std/compress
On this page
Index
- type
Level - type
CompressErr- method
CompressErr.display
- method
- type
Format - type
Compressor- method
Compressor.write - method
Compressor.flush - method
Compressor.finish
- method
- type
Decompressor- method
Decompressor.write - method
Decompressor.finish
- method
- fn
gzip - fn
gunzip - fn
deflate - fn
inflate - fn
zlib - fn
unzlib - fn
compressor - fn
decompressor
Types
Level
enum Level {
NoCompression
BestSpeed
Default
BestCompression
HuffmanOnly
Of(n: Int)
}A compression level: Go’s -2 (HuffmanOnly) to 9 (BestCompression);
Of(n) for any of them, a fault outside -2 to 9.
CompressErr
struct CompressErr {
msg: Str
}Go’s error texts (gzip: invalid header, flate: corrupt input before offset 5, zlib: invalid checksum, unexpected EOF), or
gzip: output exceeds max_size (N bytes) (flate, zlib likewise).
CompressErr.display
fn (e: CompressErr) display() -> StrFormat
enum Format {
Gzip
Deflate
Zlib
}The stream formats of a Compressor or Decompressor.
Compressor
struct Compressor {}A streaming compressor: bytes in, compressed bytes out, no I/O of its
own; write returns the output ready so far (it may be empty),
flush everything written so far (a sync block: a reader can decode
it all), finish the rest and the format’s trailer. The concatenation
of its outputs is what gzip, deflate, or zlib gives for all the data.
@move_only
Compressor.write
fn (var c: Compressor) write(data: Bytes) -> BytesCompressor.flush
fn (var c: Compressor) flush() -> BytesCompressor.finish
fn (var c: Compressor) finish() -> Bytes@moves
Decompressor
struct Decompressor {}A streaming decompressor: compressed bytes in, decoded bytes out as
their input arrives (how much each write returns may differ between
backends: natively each whole DEFLATE block, on the Go backend what Go’s
reader returns); finish returns the rest, or unexpected EOF when
the stream did not end. The concatenation of the outputs is what
gunzip, inflate, or unzlib gives; more than max_size bytes in all is an
error at once.
@move_only
Decompressor.write
fn (var d: Decompressor) write(data: Bytes) -> Bytes ! CompressErrDecompressor.finish
fn (var d: Decompressor) finish() -> Bytes ! CompressErr@moves
Functions
gzip
fn gzip(data: Bytes, level: Level = Level.Default) -> BytesA gzip member with no name and no time (the output depends on the data and the level only).
gunzip
fn gunzip(data: Bytes, max_size: Int = 1073741824) -> Bytes ! CompressErrEvery concatenated member; more than max_size bytes of output is an error.
deflate
fn deflate(data: Bytes, level: Level = Level.Default) -> BytesRaw DEFLATE (RFC 1951).
inflate
fn inflate(data: Bytes, max_size: Int = 1073741824) -> Bytes ! CompressErrzlib
fn zlib(data: Bytes, level: Level = Level.Default) -> Byteszlib (RFC 1950): a two byte header, DEFLATE, and the Adler-32 sum.
unzlib
fn unzlib(data: Bytes, max_size: Int = 1073741824) -> Bytes ! CompressErrcompressor
fn compressor(format: Format, level: Level = Level.Default) -> Compressordecompressor
fn decompressor(format: Format, max_size: Int = 1073741824) -> Decompressor