Deflate
Pure-Kotlin RFC 1951 DEFLATE deflater: the inverse of Inflate.
LZ77 (greedy, 32 KiB window, hash-chained with bounded chain length) tokenizes the input; every 64 Ki tokens form a block, and each block is emitted as the cheapest of the three RFC encodings: stored (BTYPE=00), fixed Huffman (BTYPE=01) or dynamic Huffman (BTYPE=10) with code-length tables built from the block's actual token frequencies (T-11). Dynamic blocks bring the pure encoder's output close to zlib's; on JVM/Android the PlatformFlate fast path bypasses this entirely, so this is the ratio story for Apple/JS/Wasm/native writers.
Output is bare DEFLATE; Zlib.encode wraps it for PDF's FlateDecode. The result decodes byte-for-byte through KitePDF's own Inflate, zlib and MuPDF.
Bit-packing matches Inflate's reader: data elements (block headers and the length/distance extra bits) are packed least-significant-bit-first, while Huffman codes are packed most-significant-bit-first.