deflate
nimony/lib/std/compress/deflate.nim
type InflateStatus = enum infNeedInput = (0, "infNeedInput") infOutputFull = (1, "infOutputFull") infDone = (2, "infDone") infError = (3, "infError")
func dollar`.InflateStatus(e: InflateStatus): stringfunc dollar`.Stage(e: Stage): stringtype Inflater = object br: BitReader stage: Stage final: bool storedLeft: int64 copyLeft: int64 copyDist: int64 win: string total: int64 lit: Huff dist: Huff
proc initInflater(): Inflaterproc feed(s: var Inflater; input: openArray[char])More compressed bytes. Whatever an earlier
inflateleft unread stays ahead of them.proc inflate(s: var Inflater; dest: var string; limit: int64): InflateStatusDecode what has been fed, appending to
dest, until the input runs out, the stream ends, orlimitbytes have been appended.proc isDone(s: Inflater): boolproc produced(s: Inflater): int64Bytes decoded over the whole stream so far.
proc takeRest(s: var Inflater): stringOnce
inflatehas answeredinfDone: the input that came after the stream — a container's trailer, or whatever follows that. The bits left in the last byte are padding and are dropped.func dollar`.FlushMode(e: FlushMode): stringtype Deflater = object level: int64 maxChain: int64 niceLen: int64 lazyLen: int64 buf: string pos: int64 base: int64 head: seq[uint32] prev: seq[uint32] toks: seq[uint32] litFreq: seq[int64] distFreq: seq[int64] bitbuf: uint64 bitcnt: int64 done: bool
proc initDeflater(level: int64): Deflaterleveltrades speed for size as zlib's does:0stores,1is fastest,9tries hardest.6is what everybody's default means.proc compress(s: var Deflater; input: openArray[char]; dest: var string)Compress
input, appending todestwhatever whole blocks are ready. Most of a small input stays buffered untilflushorfinish.proc flush(s: var Deflater; dest: var string)Compress everything buffered and byte-align the output, so that what
destholds decodes to everything given so far (a zlib "sync flush"). Costs a block boundary and five bytes; matches still reach back across it.proc finish(s: var Deflater; dest: var string)End the stream. Nothing may be compressed after this.
proc isFinished(s: Deflater): boolproc deflate(data: openArray[char]; level: int64): stringdataas a raw DEFLATE stream.const DefaultInflateLimit: int64How much a one-shot decode (
inflatehere,gzip.uncompress) produces unless told otherwise. DEFLATE expands up to ~1000:1, so without a cap a few kilobytes from someone else become gigabytes in memory. A caller that expects more passes its ownlimit.proc inflate(data: openArray[char]; dest: var string; limit: int64): InflateStatusDecode a whole raw DEFLATE stream from
data, appending todest.infDoneon success;infNeedInputmeansdatawas cut short;infOutputFullthat the result would exceedlimitbytes.