Thread overview
How to uncompress gzip archive compressed by deflate method.
Nov 12, 2010
Zarathustra
Nov 12, 2010
div0
Nov 13, 2010
Zarathustra
Nov 13, 2010
Zarathustra
November 12, 2010
Maybe it is a stupid question but I need yours help.
As in the topic. I have a Gzip archive in the buffer and I need to extract
these archive into another buffer.

I tried: void[] _uncompressed = uncompress(_compressed);

but it throws 'std.zlib.ZlibException: data error.'

Is it possible to do with Phobos2 ? The archive is not corrupted because It works fine after saving on the disk.

Thanks in advance.
November 12, 2010
On 12/11/2010 23:33, Zarathustra wrote:
> Maybe it is a stupid question but I need yours help.
> As in the topic. I have a Gzip archive in the buffer and I need to extract
> these archive into another buffer.
>
> I tried: void[] _uncompressed = uncompress(_compressed);
>
> but it throws 'std.zlib.ZlibException: data error.'
>
> Is it possible to do with Phobos2 ? The archive is not corrupted because It
> works fine after saving on the disk.
>
> Thanks in advance.

A Gzipp'd file will start with a Gzip header and the uncompress function (probably) expects to be given a pointer the first byte of the compressed data, i.e. not a pointer to the header.

You probably just need to add an offset == to the size of the gzip header to the start of your data.

There's a full interface to zlib available in phobo\etc\c\zlib.d. so have a look through there.

-- 
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk
November 13, 2010
Thanks for a tip, but it's still does not work.
My test gzip file have 10 (minimum gzip header) header bytes and 8 trailing bytes,
so I tried:
auto _uncompressed = uncompress(_compressed[0x0A.._compressed.length - 0x08]);

But the exception still occurs. Maybe the compressed data need to be aligned in
some boundary or something.
Please for help.
November 13, 2010
Ok, I found the solution:

_uncompressed = uncompress(_compressed,
*cast(uint*)&_compressed[_compressed.length-4], 30);