24 Feb
2014
24 Feb
'14
2:45 p.m.
Am 21.02.2014 16:26, schrieb Nat Goodspeed:
Could you wrap the input stream in a filter that would pass through only the chunk, pretending to its consumer that the chunk is the entire stream? Yep, the following code does the trick:
struct chunk_device : boost::iostreams::source { std::istream& stream_; std::streamsize size_; chunk_device(std::istream& is, std::streamsize sz) : stream_(is), size_(sz) {} std::streamsize read(char* s, std::streamsize n) { if (size_ == 0) { return -1; } n = std::min(n, size_); std::streamsize result = stream_.read(s, n).gcount(); size_ -= result; return result; } }; Thanks Olaf