compress.brotli #
Description
compress.brotli compresses and decompresses binary data using Brotli.
The module loads the system libbrotlienc and libbrotlidec shared libraries at runtime. Set V_BROTLI_ENC_LIB or V_BROTLI_DEC_LIB to point to custom library locations when they are not in the platform loader path.
Examples
import compress.brotli
fn main() {
uncompressed := 'Hello world!'
compressed := brotli.compress(uncompressed.bytes(), mode: .text)!
decompressed := brotli.decompress(compressed)!
assert decompressed == uncompressed.bytes()
}
Library loading uses V's dl module and requires no bundled native loader header. MemorySanitizer builds link directly to the sanitizer runtime helper to mark bytes written by the external Brotli libraries as initialized, including when the runtime is linked statically.
fn compress #
fn compress(data []u8, params CompressParams) ![]u8
compress compresses data as a Brotli stream and returns the compressed bytes.
fn decompress #
fn decompress(data []u8, _ DecompressParams) ![]u8
decompress decompresses a Brotli stream and returns the decompressed bytes.
fn is_available #
fn is_available() bool
is_available reports whether both Brotli encoder and decoder libraries can be loaded.
fn Mode.from #
fn Mode.from[W](input W) !Mode
from returns the Mode value of an integer or of a field name, or an error if there is none.
enum Mode #
enum Mode {
generic = 0
text = 1
font = 2
}
Mode tunes the Brotli encoder for generic, text, or font data.
struct CompressParams #
struct CompressParams {
pub:
quality int = 11
lgwin int = 22
mode Mode = .generic
}
CompressParams controls Brotli compression.
struct DecompressParams #
struct DecompressParams {}
DecompressParams controls Brotli decompression.