Search code examples
gzipcompressiondeflate

Gzip deflate noncompressed data format


After reading RFC 1951 and manually wrote a simple gzip file that contains non-compressed data. The uncompressed data file only has one character 'a' with no additional spaces or line breaks. The content of the gzip file is
1f 8b 08 00 00 00 00 00 00 03 01 80 00 7f ff 86 43 be b7 e8 01 00 00 00.

When I was trying to unzip it under Linux system, it gave me an error "gzip: xxx.gz: unexpected end of file".

I think I followed the deflate format of non-compressed data block mentioned in 3.2.4. After 10 bytes gzip header,

  1. 01: BFINAL=1 and BTYPE=00
  2. 8000: LEN=1
  3. 7fff: NLEN
  4. 86: a

Followed by CRC and Size.

Can anyone point out anything wrong or missing in the gzip file? Thanks a lot.


Solution

  • 8000 is length 128, not 1. 0100 would be length 1. (Interestingly, you managed to correctly represent the total uncompressed length at the end as 01 00 00 00.)

    Also an a is hex 61, not 86.

    So the correct stream would be:

    1f 8b 08 00 00 00 00 00 00 03 01 01 00 fe ff 61 43 be b7 e8 01 00 00 00