Xo is experimental. The source is now public on GitHub, or try Xo in your browser.
Menu · compress

Docs

std/compress

On this page

Index

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.

Source: std/compress.xo: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).

Source: std/compress.xo:21

CompressErr.display

fn (e: CompressErr) display() -> Str

Source: std/compress.xo:25

Format

enum Format {
  Gzip
  Deflate
  Zlib
}

The stream formats of a Compressor or Decompressor.

Source: std/compress.xo:41

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

Source: std/compress.xo:53

Compressor.write

fn (var c: Compressor) write(data: Bytes) -> Bytes

Source: std/compress.xo:56

Compressor.flush

fn (var c: Compressor) flush() -> Bytes

Source: std/compress.xo:57

Compressor.finish

fn (var c: Compressor) finish() -> Bytes

@moves

Source: std/compress.xo:59

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

Source: std/compress.xo:69

Decompressor.write

fn (var d: Decompressor) write(data: Bytes) -> Bytes ! CompressErr

Source: std/compress.xo:72

Decompressor.finish

fn (var d: Decompressor) finish() -> Bytes ! CompressErr

@moves

Source: std/compress.xo:74

Functions

gzip

fn gzip(data: Bytes, level: Level = Level.Default) -> Bytes

A gzip member with no name and no time (the output depends on the data and the level only).

Source: std/compress.xo:29

gunzip

fn gunzip(data: Bytes, max_size: Int = 1073741824) -> Bytes ! CompressErr

Every concatenated member; more than max_size bytes of output is an error.

Source: std/compress.xo:32

deflate

fn deflate(data: Bytes, level: Level = Level.Default) -> Bytes

Raw DEFLATE (RFC 1951).

Source: std/compress.xo:34

inflate

fn inflate(data: Bytes, max_size: Int = 1073741824) -> Bytes ! CompressErr

Source: std/compress.xo:35

zlib

fn zlib(data: Bytes, level: Level = Level.Default) -> Bytes

zlib (RFC 1950): a two byte header, DEFLATE, and the Adler-32 sum.

Source: std/compress.xo:37

unzlib

fn unzlib(data: Bytes, max_size: Int = 1073741824) -> Bytes ! CompressErr

Source: std/compress.xo:38

compressor

fn compressor(format: Format, level: Level = Level.Default) -> Compressor

Source: std/compress.xo:55

decompressor

fn decompressor(format: Format, max_size: Int = 1073741824) -> Decompressor

Source: std/compress.xo:71

↑ index