How do I use std.zlib to write a struct of data to a binary file with compression?

TJB broughtj at gmail.com
Tue Sep 25 14:50:27 PDT 2012


On Tuesday, 25 September 2012 at 18:08:44 UTC, Justin Whear wrote:

> I wrote up a quick example program and pasted it here:
>   http://dpaste.dzfl.pl/f1699d07
>
> Hope that helps you out.

OK, I think I am working this out.  Let's say I want to write the 
data to a gzipped file that will be inter-operable with gzip at 
the command line. I think
I do something like the following:

   auto mem = new MemoryStream();
   mem.writeExact(foo.ptr, foo.length * A.sizeof);

   auto gzdat = new Compress(9, HeaderFormat.gzip);
   gzdat.compress(mem.data);

But then, what do I do with gzdat?  Do I try to write it to a 
file like this:

   auto fout = new std.stream.File("data.bin.gz", FileMode.OutNew);
   fout.writeExact(gzdat.ptr, gzdat.sizeof);

Something is wrong though.  Hmm ...

TJB


More information about the Digitalmars-d-learn mailing list