Boost logo

Boost Users :

Subject: Re: [Boost-users] [iostreams] gzip problem
From: Olaf Krzikalla (olaf.krzikalla_at_[hidden])
Date: 2014-02-24 09:45:19


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net