Note that there are some explanatory texts on larger screens.

plurals
  1. POBoost Iostreams zlib_error with Custom Source
    primarykey
    data
    text
    <p>I am trying to use a <code>zlib_decompressor</code> to decompress data through an <code>istreambuf_iterator</code>. I couldn't find an in built way to use an input iterator as input to a stream (please point out a way if one exists already) so I wrote this source: </p> <pre><code>template &lt;class cha_type, class iterator_type&gt; class IteratorSource { public: typedef cha_type char_type; typedef boost::iostreams::source_tag category; iterator_type&amp; i; iterator_type eof; IteratorSource(iterator_type&amp; it, iterator_type end) : i(it), eof(end) { } std::streamsize read(char* s, std::streamsize n) { for(int j = 0; j &lt; n; j++) { if(i == eof) { std::cout &lt;&lt; "Reached eof after " &lt;&lt; j &lt;&lt; " bytes\n"; return -1; } char next = *i++; std::cout &lt;&lt; "Reading " &lt;&lt; next &lt;&lt; "\n"; *s++ = next; } return n; } }; </code></pre> <p>And used it like this:</p> <pre><code>int main() { std::vector&lt;char&gt; data_back = {'\x78', '\x9c', '\x73', '\x04', '\x00', '\x00', '\x42', '\x00', '\x42'}; auto start = data_back.begin(); IteratorSource&lt;char, decltype(data_back)::iterator&gt; data(start, data_back.end()); boost::iostreams::filtering_istreambuf def; def.push(boost::iostreams::zlib_decompressor()); def.push(data); boost::iostreams::copy(def, std::cout); return 0; } </code></pre> <p>To give this output:</p> <pre><code>Reading x Reading � Reading s Reading Reading Reading Reading B Reading Reading B Reached eof after 9 bytes terminate called after throwing an instance of 'boost::exception_detail::clone_impl&lt;boost::exception_detail::error_info_injector&lt;boost::iostreams::zlib_error&gt; &gt;' what(): zlib error Aborted (core dumped) </code></pre> <p>I am not sure why this is producing an error because loading from a file works fine.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload