<br><br><div class="gmail_quote">On Mon, Apr 11, 2011 at 3:35 AM,  <span dir="ltr">&lt;<a href="mailto:Viatcheslav.Sysoltsev@h-d-gmbh.de">Viatcheslav.Sysoltsev@h-d-gmbh.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Ok, here&#39;s my entire script. As mentioned in the comments it works fine if<br>
size=5e5. It also runs fine if size=5e6, but then the resulting file is<br>
corrupt (i.e. cannot be gunzipped with the gzip utility). Try it out. I&#39;m<br>
using Visual Studio 2008 in a Windows XP machine.<br>
<br>
#include &lt;boost/iostreams/device/file.hpp&gt;<br>
#include &lt;boost/iostreams/filter/gzip.hpp&gt;<br>
#include &lt;boost/iostreams/filtering_stream.hpp&gt;<br>
<br>
using namespace std;<br>
namespace io = boost::iostreams;<br>
<br>
int main()<br>
{<br>
    //Set filename<br>
    string outfile = &quot;c:/outfile.bin.gz&quot;;<br>
<br>
    //Set filesize<br>
    int size = int(5e6); // &lt;- If I change this to &#39;5e5&#39; instead of &#39;5e6&#39;,<br>
everything works just fine.<br>
<br>
    //Declare memory block to be compressed to file<br>
    char* memblock = new char [size];<br>
<br>
    //Create a filtering_ostream out<br>
    io::filtering_ostream out;<br>
<br>
     //Assigns the gzip_compressor to out<br>
    out.push(io::gzip_compressor());<br>
<br>
     //Assigns out as a file sink<br>
    out.push(io::file_sink(outfile));<br>
<br>
    //Write memblock to out<br>
    out.write(memblock, size);<br>
<br>
    //Clean up<br>
    delete[] memblock;<br>
    io::close(out); //Note, also tried &#39;out.close();&#39;, &#39;io::close(out,<br>
ios_base::out);&#39; and &#39;close(out);&#39;. Same result.<br>
<br>
    return 0;<br>
}<br>
<br>
</blockquote>
<br></div></div>
Works just fine on linux gcc 4.3.2 boost 1.45. with 5e5, 5e6 and 5e7 size.<br>
As a guess, I&#39;d delete memblock after closing the out to be on a safe side, maybe it helps.<br>
<br>
-- Slava<div><div></div><div class="h5"><br>
<br>
_______________________________________________<br>
Boost-users mailing list<br>
<a href="mailto:Boost-users@lists.boost.org" target="_blank">Boost-users@lists.boost.org</a><br>
<a href="http://listarchives.boost.org/mailman/listinfo.cgi/boost-users" target="_blank">http://listarchives.boost.org/mailman/listinfo.cgi/boost-users</a><br>
</div></div></blockquote></div><br><br>If anyone is still interested, this is what I got to work after much hair-pulling. Maybe someone who understand streams (std and boost) better than I can explain why this works and my previous attempts created corrupt files when size was large (again, I&#39;m using Windows, VS 2008). Cheers, Anders<br>
<br>#include &lt;fstream&gt;<br>#include &lt;iostream&gt;<br>#include &lt;sstream&gt;<br>#include &lt;boost/iostreams/filtering_streambuf.hpp&gt;<br>#include &lt;boost/iostreams/copy.hpp&gt;<br>#include &lt;boost/iostreams/filter/gzip.hpp&gt;<br>
<br>using namespace std;<br>namespace io = boost::iostreams;<br><br>int main() <br>{<br>    //Trying with stringstream, which can act as both istream and ostream<br>    int size = 5700 * 4800 * 2; //This happens to be the actual size of the data I need to write<br>
    char* memblock = new char [size]; //Data to write<br><br>    stringstream ss(stringstream::in | stringstream::out | stringstream::binary); //Declare ss<br>    ss.write(memblock, size); //Write data to ss<br><br>    io::filtering_streambuf&lt;io::input&gt; buf; //Declare buf<br>
    buf.push(io::gzip_compressor()); //Assign compressor to buf<br>    buf.push(ss); //Push ss to buf<br>    ofstream out(&quot;c:/outfile.gz&quot;, ios_base::out | ios_base::binary); //Declare out<br>    io::copy(buf, out); //Copy buf to out<br>
<br>    //Clean up<br>    out.close();<br>    delete[] memblock;<br><br>    return 0;<br>}<br><br><br clear="all"><br>-- <br>Anders Knudby, PhD<br>e-mail: <a href="mailto:knudby@gmail.com">knudby@gmail.com</a><br>skype ID: anders.knudby<br>
<br>Man&#39;s mind, once stretched by a new idea, never regains its original dimensions.<br>~ Oliver Wendell Holmes<br>

