This project is read-only.

Looking for File Headers 1F 8B 08 08 (Similar to GZipStream)

May 7, 2009 at 7:10 PM
Edited May 7, 2009 at 8:29 PM
Hi Cheeso,

I tried searching the discussions before posting this and didn't find anything.

What I'm basically looking for is compressing one file; similar to the System.IO.Compression.GZipStream. I would use the System.IO.Compress.GZipStream, but it is too unpredictable and unreliable.
I used the Ionic.Zlib.ZlibStream to compress a file, but when I looked at the header, it didn't match that of the GZipStream.

I am assuming that this functionality exists in DotNetZip and was wondering if you would kindly point me to the correct classes.

The use application for me is a result from sending files to a hardware device that support gZip (decompress only). The firmware on the device I am sending files to expect the headers of 1F 8B 08 08.

Thank you
kind regards,

May 7, 2009 at 8:02 PM
Edited May 7, 2009 at 8:05 PM
Whoa!  Ionic.Zlib.GZipStream is unreliable and unpredictable?
If so, I should fix it.
have you logged work items?  Do I have details?

If you want a GZIP stream, then the thing you are asking for is the Ionic.Zlib.GZipStream. The ZlibStream compresses in a different way.  Likewise the DeflateStream.  The compression formats are described in RFC 1950 [ZLIB], 1951 [DEFLATE], and 1952 [GZIP]

Without consulting those RFCs, I don't know, off the top of my head, what the required file header is for GZIP.  If the bytestream you listed is required by the GZIP spec then those bytes are the ones the library will emit, when using GZipStream.  If the required bytes are not being emitted, then I need to fix the library. 

May 7, 2009 at 8:15 PM
Just had a quick look at the spec.  The 0x1f 0x8b is a standard GZIP header.  The next byte indicates the compression method - 0x08 implies DEFLATE, which is what Ionic.Zlib.GZipStream will produce.  The next byte is the flag byte and indicates whether the file metadata contains various optional parts.  0x08 in that byte indicates the filename must be present in the GZIP metadata.  To make this happen you can set the FileName property on the GZipStream. 

I just looked at the doc on Ionic.Zip.GZipStream and it is less than clear that the FileName property is optional. And it is also not stated that setting the filename will turn on bit 3 in the flag byte.  But as I recall, I designed it so that if you set the filename then bit 3 of the flag byte automatically gets set.  In the absence of other optional stuff (comments, Extra data, etc), the flag byte will be 0x08, which is what you said you want.

To sum it up, if you are using GZipStream to write a blob to be consumed for this device, and the device expects 0x1F 0x8B 0x08 ox08 as header bytes, then I suggest you set the FileName property on the GZipStream instance before calling Write() for the first time on the instance.
May 7, 2009 at 8:25 PM
Hi Cheeso,

I think I must have mistyped what I was trying to convey. The Microsoft System.IO.Compression.GZipStream is unreliable. If I compress a simple bitmap with only 128 colors, (Original size 1.1MB), using Microsoft's GZipStream compresses it down to 856kb, whereas using the Ionic.Zlib.ZlibStream compresses the same bitmap down to 552kb. WinZip compresses the same bitmap down to 552kb.

In my humble opinion, the DonNetZip library rocks! I havn't had any problems with it whatsoever. Excellent effort; thank you for the contribution.

I will try what you have suggested and post my findings.

Again, thank you.

May 7, 2009 at 8:39 PM
Edited May 7, 2009 at 8:39 PM
How embarrasing for me... I feel silly now.

I just realized taht I am using DNZ instead of 1.8, which is why I couldn't locate GZipStream. I think its clear that I'm due for a vacation.  :)

May 7, 2009 at 8:44 PM
Ah, I misunderstood.
And yes, as you realized, the GZipStream class is new in DotNetZip for v1.8.
It should do what you want !