gzip
nimony/lib/std/compress/gzip.nim
type Format = enum fmtRaw = (0, "fmtRaw") fmtZlib = (1, "fmtZlib") fmtGzip = (2, "fmtGzip") fmtDetect = (3, "fmtDetect")
func dollar`.Format(e: Format): stringtype Encoder = object fmt: Format level: int64 d: Deflater crc: Crc32 adler: Adler32 size: int64 started: bool
proc initEncoder(fmt: Format; level: int64): EncoderfmtDetectis not a format anything can be written in; it is taken to mean gzip.proc compress(e: var Encoder; input: openArray[char]; dest: var string)Compress
input, appending whatever output is ready todest.proc flush(e: var Encoder; dest: var string)Make everything compressed so far decodable from what
destholds. Seedeflate.flush.proc finish(e: var Encoder; dest: var string)End the stream and write the trailer. Idempotent.
proc compress(data: openArray[char]; fmt: Format; level: int64): stringdata, compressed, in one call.func dollar`.DecStage(e: DecStage): stringtype Decoder = object fmt: Format stage: DecStage pending: string inf: Inflater crc: Crc32 adler: Adler32 members: int64
proc initDecoder(fmt: Format): Decoderproc feed(d: var Decoder; input: openArray[char])More compressed bytes.
proc decode(d: var Decoder; dest: var string; limit: int64): InflateStatusDecode what has been fed, appending to
dest:infNeedInputwhen the input ran out,infOutputFullafterlimitbytes,infDoneonce the stream and its trailer have been read and checked.A stream that ends without
infDoneis truncated. That is the caller's call to make — only it knows the input has ended.proc isDone(d: Decoder): boolWhether a complete stream has been decoded and checked. Asked once the input has ended:
falsethen means it was cut short.proc uncompress(data: openArray[char]; fmt: Format; limit: int64): stringdata, decompressed.SyntaxErrorfor a stream that is corrupt or cut short,ContentTooLongwhen the result would passlimitbytes.The limit is what stands between a kilobyte of input and a gigabyte of output, so it has a default (
DefaultInflateLimit, 64 MiB); pass a larger one for data that is expected to be bigger.