digitalmars.D - Trouble with std.zlib
- Andrew Wiley (14/15) Jul 19 2011 I'm using std.zlib in an application, and I'm having trouble decompressi...
- Jesse Phillips (4/9) Jul 19 2011 The zlib format is different from the gzip format.
- Andrew Wiley (6/19) Jul 19 2011 I know, but if you look at the docs for the inflate functions, zlib is
- Jesse Phillips (3/7) Jul 19 2011 Not sure what documentation you are talking of. But it doesn't sound lik...
- Andrew Wiley (7/19) Jul 19 2011 Ah, I stand corrected:
- Andrew Wiley (5/28) Jul 19 2011 Looks like this is the solution:
I'm using std.zlib in an application, and I'm having trouble decompressing a file. The file is gzipped, and I can easily see the contents with `cat file | gzip -d` but this code doesn't work: auto arr = read("file.gz"); ubyte[] realarr = cast(ubyte[])uncompress(arr); output: std.zlib.ZlibException std/zlib.d(59): data errorFrom the header file, it seems like zlib should be detecting a gzip headerand *just working*, but, well, it isn't. I have to store data in a compressed format, and eventually the code I'm writing will be used in-memory instead of on files, so I'm going to have to uncompress it somehow. Has anyone encountered this before? Thanks, Andrew
Jul 19 2011
Andrew Wiley Wrote:I'm using std.zlib in an application, and I'm having trouble decompressing a file. The file is gzipped, and I can easily see the contents with `cat file | gzip -d` but this code doesn't work: auto arr = read("file.gz"); ubyte[] realarr = cast(ubyte[])uncompress(arr);The zlib format is different from the gzip format. http://www.zlib.net/zlib_faq.html#faq18 One is made for file storage and the other internal data transfer. D does not provide a wrapper to the gzip functions at this time but they are available in std.c.zlib (with the C interface).
Jul 19 2011
On Tue, Jul 19, 2011 at 7:11 AM, Jesse Phillips <jessekphillips+D gmail.com>wrote:Andrew Wiley Wrote:I know, but if you look at the docs for the inflate functions, zlib is supposed to be autodetecting the gzip header and uncompressing the payload correctly, if I understand the documentation (which I probably don't at this point).I'm using std.zlib in an application, and I'm having troubledecompressing afile. The file is gzipped, and I can easily see the contents with `catfile| gzip -d` but this code doesn't work: auto arr = read("file.gz"); ubyte[] realarr = cast(ubyte[])uncompress(arr);The zlib format is different from the gzip format. http://www.zlib.net/zlib_faq.html#faq18 One is made for file storage and the other internal data transfer. D does not provide a wrapper to the gzip functions at this time but they are available in std.c.zlib (with the C interface).
Jul 19 2011
Andrew Wiley Wrote:I know, but if you look at the docs for the inflate functions, zlib is supposed to be autodetecting the gzip header and uncompressing the payload correctly, if I understand the documentation (which I probably don't at this point).Not sure what documentation you are talking of. But it doesn't sound like it does auto detection, an answer to one of the question: "You can request that deflate write the gzip format instead of the zlib format using deflateInit2(). You can also request that inflate decode the gzip format using inflateInit2(). Read zlib.h for more details."
Jul 19 2011
On Tue, Jul 19, 2011 at 9:57 AM, Jesse Phillips <jessekphillips+D gmail.com>wrote:Andrew Wiley Wrote:Ah, I stand corrected: "inflate() can decompress and check either zlib-wrapped or gzip-wrapped deflate data. The header type is detected automatically, if requested when initializing with inflateInit2()."I know, but if you look at the docs for the inflate functions, zlib is supposed to be autodetecting the gzip header and uncompressing thepayloadcorrectly, if I understand the documentation (which I probably don't atthispoint).Not sure what documentation you are talking of. But it doesn't sound like it does auto detection, an answer to one of the question: "You can request that deflate write the gzip format instead of the zlib format using deflateInit2(). You can also request that inflate decode the gzip format using inflateInit2(). Read zlib.h for more details."
Jul 19 2011
On Tue, Jul 19, 2011 at 10:14 AM, Andrew Wiley <wiley.andrew.j gmail.com>wrote:On Tue, Jul 19, 2011 at 9:57 AM, Jesse Phillips < jessekphillips+D gmail.com> wrote:Looks like this is the solution: ubyte[] realarr = cast(ubyte[])uncompress(arr, 0, 47); The 47 makes zlib autodetect the header (because the 32 bit is set; if you wanted to force gzip, you'd set the 16 bit).Andrew Wiley Wrote:Ah, I stand corrected: "inflate() can decompress and check either zlib-wrapped or gzip-wrapped deflate data. The header type is detected automatically, if requested when initializing with inflateInit2()."I know, but if you look at the docs for the inflate functions, zlib is supposed to be autodetecting the gzip header and uncompressing thepayloadcorrectly, if I understand the documentation (which I probably don't atthispoint).Not sure what documentation you are talking of. But it doesn't sound like it does auto detection, an answer to one of the question: "You can request that deflate write the gzip format instead of the zlib format using deflateInit2(). You can also request that inflate decode the gzip format using inflateInit2(). Read zlib.h for more details."
Jul 19 2011