Skip to content

compress #

Description

compress is a namespace for (multiple) compression algorithms supported by V.

At the moment, the following compression algorithms are implemented:

  • compress.bzip2
  • compress.brotli
  • compress.deflate
  • compress.gzip
  • compress.lz supporting the following variations:
    • lz4
    • lz77
    • lz78
    • lzjb
    • lzma
    • lzma2
    • lzss
    • lzw
  • compress.snappy
  • compress.zlib
  • compress.zstd

Constants #

@[deprecated: 'use max_i32 (from builtin) instead']
@[deprecated_after: '2026-07-31']
const max_size = u64(1 << 31)

fn compress #

@[deprecated: 'use compress.deflate.compress instead']
@[deprecated_after: '2026-07-31']
@[manualfree]
fn compress(data []u8, flags int) ![]u8

compresses an array of bytes based on providing flags and returns the compressed bytes in a new array NB: this is a low level api, a high level implementation like zlib/gzip should be preferred

fn decompress #

@[deprecated: 'use compress.deflate.decompress instead']
@[deprecated_after: '2026-07-31']
@[manualfree]
fn decompress(data []u8, flags int) ![]u8

decompresses an array of bytes based on providing flags and returns the decompressed bytes in a new array NB: this is a low level api, a high level implementation like zlib/gzip should be preferred

fn decompress_with_callback #

@[deprecated: 'use compress.deflate.decompress_with_callback instead']
@[deprecated_after: '2026-07-31']
fn decompress_with_callback(data []u8, cb ChunkCallback, userdata voidptr, flags int) !u64

decompress_with_callback decompresses an array of bytes, based on the provided flags, and a V fn callback to receive decompressed chunks, of at most 32 kilobytes each. It returns the total decompressed length, or a decompression error. NB: this is a low level api, a high level implementation like zlib/gzip should be preferred.

type ChunkCallback #

@[deprecated: 'use compress.deflate.ChunkCallback instead']
@[deprecated_after: '2026-07-31']
type ChunkCallback = fn (chunk []u8, userdata voidptr) int