Boost logo

Boost Users :

Subject: Re: [Boost-users] Writing large binary files with boost gzip
From: Viatcheslav.Sysoltsev_at_[hidden]
Date: 2011-04-11 03:35:32


> Ok, here's my entire script. As mentioned in the comments it works fine
> if
> size=5e5. It also runs fine if size=5e6, but then the resulting file is
> corrupt (i.e. cannot be gunzipped with the gzip utility). Try it out. I'm
> using Visual Studio 2008 in a Windows XP machine.
>
> #include <boost/iostreams/device/file.hpp>
> #include <boost/iostreams/filter/gzip.hpp>
> #include <boost/iostreams/filtering_stream.hpp>
>
> using namespace std;
> namespace io = boost::iostreams;
>
> int main()
> {
> //Set filename
> string outfile = "c:/outfile.bin.gz";
>
> //Set filesize
> int size = int(5e6); // <- If I change this to '5e5' instead of
> '5e6',
> everything works just fine.
>
> //Declare memory block to be compressed to file
> char* memblock = new char [size];
>
> //Create a filtering_ostream out
> io::filtering_ostream out;
>
> //Assigns the gzip_compressor to out
> out.push(io::gzip_compressor());
>
> //Assigns out as a file sink
> out.push(io::file_sink(outfile));
>
> //Write memblock to out
> out.write(memblock, size);
>
> //Clean up
> delete[] memblock;
> io::close(out); //Note, also tried 'out.close();', 'io::close(out,
> ios_base::out);' and 'close(out);'. Same result.
>
> return 0;
> }
>

Works just fine on linux gcc 4.3.2 boost 1.45. with 5e5, 5e6 and 5e7 size.
As a guess, I'd delete memblock after closing the out to be on a safe
side, maybe it helps.

-- Slava


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