Inflate
Raw DEFLATE (RFC 1951) decompressor. It is a pure-Kotlin translation of Mark Adler's puff(), the deliberately simple reference inflate that ships with zlib at contrib/puff/puff.c.
Differences from the C, all behaviour-preserving:
puff writes into a caller-supplied fixed-size buffer and returns
1("output space exhausted") when it's too small; we grow the output array on demand instead, so error code1never occurs here.puff signals "ran past the end of input" via
setjmp/longjmp; we model that non-local exit with a private OutOfInput throwable caught at the top of inflate, mapping to InflateError.DATA_DID_NOT_TERMINATE.puff's "scan only" mode (
dest == NULL) is omitted; we always materialise the output.
Bits are consumed LSB-first within each input byte; Huffman codes are read MSB-first and accumulated in reversed order so canonical codes compare as plain integers (see decode).
This object is stateless and thread-safe; all mutable inflate state lives in the private State created per call.