0

I found that when using Java.util.zip.GzipOutputStream, when I called flush() first then close(). The deflator always produce two bytes ('00' and '03' in hex) before writing the trailer. What does these two bytes mean? Why flush() does not flush all bytes in the compressor? I have already set the stream syncFlush to true. (In my use case I need to force flush the stream)

This is the test code I write.

        File file = new File("gtest.gz");
        OutputStream out = new FileOutputStream(file);
        GZIPOutputStream gzipOutputStream = new GZIPOutputStream(out, true);
                gzipOutputStream.write("Each gzip file generated by JAVA GzipOutputStream has byte '0003' before Trailer"
                 .getBytes());
        gzipOutputStream.flush();
        gzipOutputStream.close();

And I run hexdump -C gtest.gz get

00000000  1f 8b 08 00 00 00 00 00  00 00 72 4d 4c ce 50 48  |..........rML.PH|
00000010  af ca 2c 50 48 cb cc 49  55 48 4f cd 4b 2d 4a 2c  |..,PH..IUHO.K-J,|
00000020  49 4d 51 48 aa 54 f0 72  0c 73 54 70 07 ca f9 97  |IMQH.T.r.sTp....|
00000030  96 14 94 96 04 97 14 a5  26 e6 2a 64 24 16 03 25  |........&.*d$..%|
00000040  4b 52 15 d4 0d 0c 0c 8c  d5 15 92 52 d3 f2 8b 52  |KR.........R...R|
00000050  15 42 8a 12 81 06 14 01  00 00 00 ff ff 03 00 96  |.B..............|
00000060  ef 3b 5d 50 00 00 00                              |.;]P...|
00000067

The last 8 bytes are trailer of Gzip and the two bytes before '03' '00' will always be produced whatever content I change.

Snakienn
  • 529
  • 5
  • 12
  • Looks like [someone else](https://stackoverflow.com/questions/58571294/how-to-interpret-the-final-0x03-0x00-in-this-minimal-gzip-sample) had the same question and no-one knew :) – Federico klez Culloca Jan 09 '20 at 15:16
  • 2
    This is answered over on the sister site "Reverse Engineering": [How to interpret the final 0x03 0x00 in this minimal gzip sample?](https://reverseengineering.stackexchange.com/questions/22400/how-to-interpret-the-final-0x03-0x00-in-this-minimal-gzip-sample/22403#22403) – wally Jan 09 '20 at 15:45

0 Answers0