digitalmars.D - DMD2, std.zlib, and gzip
- Glenn Lewis (7/7) Jul 22 2009 If I'm not mistaken, I used to use std.zlib with DMD1, and it was compat...
- Vladimir Panteleev (12/20) Jul 22 2009 If you compare DMD1 and DMD2's zlib.d, you'll notice that the difference...
- grauzone (9/11) Jul 23 2009 zlib can do this for you. Then you don't need to put up so much pressure...
If I'm not mistaken, I used to use std.zlib with DMD1, and it was compatible with gzip. Now that Andrei's awesome book is available on RoughCuts, I finally figured I would take the plunge and switch up to DMD2. I tried writing a file with std.zlib.compress, and gzip could not uncompress it (both level=6 and level=9). I tried gzip'ing a file, and std.zlib.uncompress could not uncompress it (see attached D file). Note that writing with std.zlib then later reading with std.zlib works just fine... but am I dreaming that I used to also be able to use 'gzip' on the resulting files? Thanks! -- Glenn Lewis
Jul 22 2009
On Thu, 23 Jul 2009 08:40:48 +0300, Glenn Lewis <nospam nospam.org> wrote:If I'm not mistaken, I used to use std.zlib with DMD1, and it was compatible with gzip. Now that Andrei's awesome book is available on RoughCuts, I finally figured I would take the plunge and switch up to DMD2.If you compare DMD1 and DMD2's zlib.d, you'll notice that the differences are trivial, and the zlib library itself hasn't changed at all, so nothing could have changed to affect this.I tried writing a file with std.zlib.compress, and gzip could not uncompress it (both level=6 and level=9). I tried gzip'ing a file, and std.zlib.uncompress could not uncompress it (see attached D file).What you seem to be confusing is that zlib is a compression algorithm, while gzip is a compression utility and file format. You need to add a header to zlib-compressed data. I've attached a simple module I use to encode/decode gzip files. Hope this helps. -- Best regards, Vladimir mailto:thecybershadow gmail.com
Jul 22 2009
I've attached a simple module I use to encode/decode gzip files. Hope this helps.zlib can do this for you. Then you don't need to put up so much pressure on the GC, and there's no need for manual header parsing/generation. Quoting the docs for deflateInit2: "windowBits can also be greater than 15 for optional gzip encoding. Add 16 to windowBits to write a simple gzip header and trailer around the compressed data instead of a zlib wrapper." You can also enable automatic header detection for zlib/gzip decoding in inflateInit2. But I think you'll have to stop using std.zlib to use this functionality.
Jul 23 2009