Zlib

object Zlib

zlib (RFC 1950) wrapper around Inflate/Deflate.

PDF's FlateDecode filter stores zlib-wrapped DEFLATE data, not bare DEFLATE. The wrapper is: 2-byte CMF/FLG header, DEFLATE payload, 4-byte big-endian Adler-32 trailer. We verify both header validity and the Adler checksum.

Functions

Link copied to clipboard
fun adler32(data: ByteArray): Int

RFC 1950 §9: Adler-32, mod 65521 over the decoded data.

Link copied to clipboard
fun decode(input: ByteArray, verifyChecksum: Boolean = true): ByteArray
Link copied to clipboard

zlib-wrap a DEFLATE compression of data (PDF FlateDecode form). Header is the conventional 0x78 0x9C (32 KiB window, default level, no preset dictionary; passes the mod-31 check), and the Adler-32 of the original data is appended big-endian. Round-trips through decode.