Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get a raw deflate out of java.util.zip.Deflater?

Tags:

java

zlib

The zlib docs specify that one can pass a negative windowBits argument to the deflateInit2() function:

windowBits can also be –8..–15 for raw deflate. In this case, -windowBits determines the window size. deflate() will then generate raw deflate data with no zlib header or trailer, and will not compute an adler32 check value.

I've used this in my C code, and in Java am able to inflate bytes thus compressed by passing true for the nowrap parameter to the Inflater constructor.

However, passing true for the nowrap parameter to the Deflater does not yield a raw deflate. It returns 20 more bytes than I get with my C implementation, which sure sounds like a header and checksum. (Passing false for nowrap yields an even longer byte array.)

I've scanned through the Deflater docs but have not found a way to specify window bits or that I want a raw deflate. Is it possible with this library? Or would I need to use some other implementation to get a raw deflate in Java?

like image 963
theory Avatar asked Apr 16 '15 23:04

theory


1 Answers

Deflater produces zlib-wrapped data (RFC 1950). Deflater(level, true) produces raw deflate data (RFC 1951).

like image 122
Mark Adler Avatar answered Oct 05 '22 02:10

Mark Adler