Is it possible to get raw deflation from java.util.zip.Deflater?

zlib docs indicate that for the deflateInit2() function, you can pass a negative argument to windowBits :

windowBits can also be -8 ..- 15 for raw deflate. In this case, -windowBits determines the size of the window. deflate() then generates raw deflate data without a zlib header or trailer, and will not calculate the adler32 check value.

I used this in my C code, and in Java I can inflate bytes compressed this way by passing true for the nowrap parameter in Inflater .

However, passing true for the nowrap parameter to Deflater does not result in raw pumping. It returns another 20 bytes than what I get with my C implementation, which undoubtedly looks like a header and checksum. (Passing false for nowrap gives an even larger array of bytes.)

I looked through Deflater Docs but did not find a way to indicate the bits of the window or what I want to crash. Is this possible with this library? Or will I need to use some other implementation to get a raw deviation in Java?

+6
source share
1 answer

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

+2
source

Source: https://habr.com/ru/post/985313/


All Articles