package core:compress/lzma

⌘K
Ctrl+K
or
/

    Overview

    An implementation of the LZMA and LZMA2 compression methods

    Reads and writes .lzma and .lz (lzip) files, raw LZMA streams as stored in 7z and zip (method 14), and raw LZMA2 streams as used by xz and 7z. It is a port of Igor Pavlov's public domain LZMA SDK, and the encoder's output is byte-identical to the SDK's.

    Index

    Variables (1)
    Procedures (48)

    Types

    LZMA2_Decoder ¶

    LZMA2_Decoder :: struct {
    	probs:     []u16,
    	allocator: runtime.Allocator,
    }
     

    The probability tables decompress_lzma2_append reuses across calls; set up with lzma2_decoder_init

    Related Procedures With Parameters

    Level ¶

    Level :: enum i32 {
    	Level_0 = 0, 
    	Level_1 = 1, 
    	Level_2 = 2, 
    	Level_3 = 3, 
    	Level_4 = 4, 
    	Level_5 = 5, 
    	Level_6 = 6, 
    	Level_7 = 7, 
    	Level_8 = 8, 
    	Level_9 = 9, 
    	Fastest = Level_0, 
    	Default = Level_6, 
    	Best    = Level_9, 
    }
     

    A preset as in xz, from 0 (fastest) to 9 (best)

    Related Procedures With Parameters

    Lzip_Trailer ¶

    Lzip_Trailer :: struct #packed {
    	crc32:       u32le,
    	// Of the member's uncompressed data
    	data_size:   u64le,
    	// Uncompressed size
    	member_size: u64le,
    }
     

    The trailer that ends each lzip member

    Match_Finder_Kind ¶

    Match_Finder_Kind :: enum u8 {
    	HC4, 
    	HC5, 
    	BT2, 
    	BT3, 
    	BT4, 
    	BT5, 
    }
     

    The encoder's match finder: hash chains or binary trees, hashing 2 to 5 bytes

    Options ¶

    Options :: struct {
    	lc:           u8,
    	// Literal context bits; lc + lp is at most 4 for LZMA2
    	lp:           u8,
    	// Literal position bits
    	pb:           u8,
    	// Position bits
    	dict_size:    u32,
    	// Cut to the input size, but not below `DICT_SIZE_MIN`
    	fast:         bool,
    	// The SDK's fast parser instead of its optimal one
    	nice_len:     u32,
    	// A match this long ends the search; clamped to 5..=273
    	depth:        u32,
    	// Match finder search depth; 0 picks one from `nice_len`
    	match_finder: Match_Finder_Kind,
    	end_marker:   bool,
    }
     

    The encoder's settings; level_options gives a level's

    Related Procedures With Parameters

    Properties ¶

    Properties :: struct {
    	lc:        u8,
    	// Literal context bits, up to `LC_MAX`
    	lp:        u8,
    	// Literal position bits, up to `LP_MAX`
    	pb:        u8,
    	// Position bits, up to `PB_MAX`
    	dict_size: u32,
    }
     

    An LZMA stream's parameters, as its 5 properties bytes store them

    Related Procedures With Parameters

    Related Procedures With Returns

    Related Constants

    Reader ¶

    Reader :: struct {
    	z:           ^compress.Context,
    	decoder:     Decoder,
    	lzma2:       LZMA2_State,
    	window:      [dynamic]u8,
    	out:         Output,
    	flushed:     int,
    	keep:        int,
    	size:        int,
    	kind:        Stream_Kind,
    	done:        bool,
    	owns_window: bool,
    	options:     compress.Options,
    	allocator:   runtime.Allocator,
    	total_in:    i64,
    	lzip:        Lzip_Member,
    	err:         compress.Error,
    }
     

    A streaming decoder of .lzma, raw LZMA, LZMA2 or lzip; set up by a reader_init proc

    Related Procedures With Parameters

    Writer ¶

    Writer :: struct {
    	w:          io.Stream,
    	state:      ^Writer_State,
    	chunker:    LZMA2_Chunker,
    	block:      []u8,
    	threshold:  u32,
    	kind:       Stream_Kind,
    	input_size: i64,
    	total_in:   i64,
    	flushed:    i64,
    	options:    compress.Options,
    	allocator:  runtime.Allocator,
    	err:        compress.Error,
    	crc32:      u32,
    	owns_block: bool,
    	finished:   bool,
    }
     

    A streaming encoder to an io.Writer; set up by a writer_init proc

    Related Procedures With Parameters

    Constants

    CHUNK_SIZE ¶

    CHUNK_SIZE :: 256 * 1024
     

    The output a Reader decodes per step on top of its dictionary when compress.Options.chunk_size is 0; at least a quarter of the dictionary is used

    DEFAULT_PROPERTIES ¶

    DEFAULT_PROPERTIES :: Properties{lc = 3, lp = 0, pb = 2, dict_size = 8 << 20}
     

    lc 3, lp 0, pb 2 and an 8 MiB dictionary

    DICT_SIZE_MIN ¶

    DICT_SIZE_MIN :: 1 << 12
     

    Smaller dictionaries are raised to this

    HEADER_SIZE ¶

    HEADER_SIZE :: PROPERTIES_SIZE + 8
     

    A .lzma header: properties and uncompressed size

    LZIP_DICT_SIZE_MAX ¶

    LZIP_DICT_SIZE_MAX :: 1 << 29
     

    512 MiB

    LZIP_HEADER_SIZE ¶

    LZIP_HEADER_SIZE :: 6
     

    The lzip format's sizes, version, largest dictionary and fixed literal and position bits

    LZIP_LC_LP ¶

    LZIP_LC_LP :: int(LZIP_PROPERTIES.lc) + int(LZIP_PROPERTIES.lp)

    LZIP_PROPERTIES ¶

    LZIP_PROPERTIES :: Properties{lc = 3, lp = 0, pb = 2}

    LZIP_TRAILER_SIZE ¶

    LZIP_TRAILER_SIZE :: size_of(Lzip_Trailer)

    LZMA2_DICT_PROP_MAX ¶

    LZMA2_DICT_PROP_MAX :: 40
     

    The largest LZMA2 dictionary byte, for 4 GiB - 1

    LZMA2_LCLP_MAX ¶

    LZMA2_LCLP_MAX :: 4
     

    LZMA2's limit on lc + lp

    PROPERTIES_SIZE ¶

    PROPERTIES_SIZE :: 5
     

    Sizes and limits of the LZMA and LZMA2 formats

    UNKNOWN_SIZE ¶

    UNKNOWN_SIZE: u64 : max(u64)
     

    A .lzma header's uncompressed size when not known

    Variables

    LZIP_MAGIC ¶

    @(rodata)
    LZIP_MAGIC: [4]u8 = …

    Procedures

    compress_bound ¶

    compress_bound :: proc(length: int) -> int {…}
     

    Returns the most bytes a .lzma file can take for an input size, or -1 if it's out of range

    compress_lzip_bound ¶

    compress_lzip_bound :: proc(length: int) -> int {…}
     

    Returns the most bytes a single-member lzip file can take for an input size, or -1 if it's out of range

    compress_lzip_to_dynamic ¶

    compress_lzip_to_dynamic :: proc(
    	output:    ^[dynamic]u8, 
    	input:     []u8, 
    	level:     Level = Level.Default, 
    	options:   compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Compresses a byte slice to a single-member lzip file into a dynamic array

    Allocates Using Provided Allocator

    Inputs:

    • output Replaced by the compressed data; emptied on error
    • input The data to compress
    • level (default: .Default)
    • options Caps the output size and working memory, and reports progress (default: {})
    • allocator For the encoder's state, and for output if it has no allocator yet (default: context.allocator)

    Returns:

    compress_lzip_to_slice ¶

    compress_lzip_to_slice :: proc(
    	output, input: []u8, 
    	level:         Level = Level.Default, 
    	options:       compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (written: int, err: compress.Error) {…}
     

    Compresses a byte slice to a single-member lzip file into a slice

    An output of at least compress_lzip_bound(len(input)) bytes always fits.

    Allocates Using Provided Allocator

    Inputs:

    • output The buffer to compress into; options.max_output_size can shorten it
    • input The data to compress
    • level (default: .Default)
    • options Caps the output size and working memory, and reports progress (default: {})
    • allocator For the encoder's state, freed before returning (default: context.allocator)

    Returns:

    compress_lzma2_append ¶

    compress_lzma2_append :: proc(
    	output:       ^[dynamic]u8, 
    	input:        []u8, 
    	lzma_options: Options, 
    	options:      compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (props: Properties, err: compress.Error) {…}
     

    Compresses a byte slice to a raw LZMA2 stream appended to a dynamic array

    Its bytes count towards options.max_output_size along with what output already holds.

    Allocates Using Provided Allocator

    Inputs:

    • output Gets the compressed data appended; left as it was on error
    • input The data to compress
    • lzma_options The encoder's settings, with lc + lp at most 4; see level_options
    • options Caps the output size and working memory, and reports progress (default: {})
    • allocator For the encoder's state, and for output if it has no allocator yet (default: context.allocator)

    Returns:

    • props The stream's settings; lzma2_dict_prop(props.dict_size) is its dictionary byte
    • err As compress_raw_to_dynamic

    compress_lzma2_bound ¶

    compress_lzma2_bound :: proc(length: int) -> int {…}
     

    Returns the most bytes a raw LZMA2 stream can take for an input size, or -1 if it's out of range

    compress_lzma2_to_dynamic ¶

    compress_lzma2_to_dynamic :: proc(
    	output:       ^[dynamic]u8, 
    	input:        []u8, 
    	lzma_options: Options, 
    	options:      compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (props: Properties, err: compress.Error) {…}
     

    Compresses a byte slice to a raw LZMA2 stream into a dynamic array, as xz and 7z store it

    Allocates Using Provided Allocator

    Inputs:

    • output Replaced by the compressed data; emptied on error
    • input The data to compress
    • lzma_options The encoder's settings, with lc + lp at most 4; see level_options
    • options Caps the output size and working memory, and reports progress (default: {})
    • allocator For the encoder's state, and for output if it has no allocator yet (default: context.allocator)

    Returns:

    • props The stream's settings; lzma2_dict_prop(props.dict_size) is its dictionary byte
    • err As compress_raw_to_dynamic

    compress_lzma2_to_slice ¶

    compress_lzma2_to_slice :: proc(
    	output, input: []u8, 
    	lzma_options:  Options, 
    	options:       compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (written: int, props: Properties, err: compress.Error) {…}
     

    Compresses a byte slice to a raw LZMA2 stream into a slice, as xz and 7z store it

    An output of at least compress_lzma2_bound(len(input)) bytes always fits.

    Allocates Using Provided Allocator

    Inputs:

    • output The buffer to compress into; options.max_output_size can shorten it
    • input The data to compress
    • lzma_options The encoder's settings, with lc + lp at most 4; see level_options
    • options Caps the output size and working memory, and reports progress (default: {})
    • allocator For the encoder's state, freed before returning (default: context.allocator)

    Returns:

    • written The compressed size
    • props The stream's settings; lzma2_dict_prop(props.dict_size) is its dictionary byte
    • err As compress_raw_to_slice

    compress_raw_bound ¶

    compress_raw_bound :: proc(length: int) -> int {…}
     

    Returns the most bytes a raw LZMA stream can take for an input size, or -1 if it's out of range

    compress_raw_to_dynamic ¶

    compress_raw_to_dynamic :: proc(
    	output:       ^[dynamic]u8, 
    	input:        []u8, 
    	lzma_options: Options, 
    	options:      compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (props: Properties, err: compress.Error) {…}
     

    Compresses a byte slice to a raw LZMA stream into a dynamic array, as 7z and zip store it

    Allocates Using Provided Allocator

    Inputs:

    • output Replaced by the compressed data; emptied on error
    • input The data to compress
    • lzma_options The encoder's settings; see level_options
    • options Caps the output size and working memory, and reports progress (default: {})
    • allocator For the encoder's state, and for output if it has no allocator yet (default: context.allocator)

    Returns:

    • props The properties to store with the stream; the dictionary size is rounded up to an LZMA2 one
    • err .Invalid_Properties if lc, lp, pb or the match finder is out of range, otherwise as compress_to_dynamic

    compress_raw_to_slice ¶

    compress_raw_to_slice :: proc(
    	output, input: []u8, 
    	lzma_options:  Options, 
    	options:       compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (written: int, props: Properties, err: compress.Error) {…}
     

    Compresses a byte slice to a raw LZMA stream into a slice, as 7z and zip store it

    An output of at least compress_raw_bound(len(input)) bytes always fits.

    Allocates Using Provided Allocator

    Inputs:

    • output The buffer to compress into; options.max_output_size can shorten it
    • input The data to compress
    • lzma_options The encoder's settings; see level_options
    • options Caps the output size and working memory, and reports progress (default: {})
    • allocator For the encoder's state, freed before returning (default: context.allocator)

    Returns:

    • written The compressed size
    • props The properties to store with the stream; the dictionary size is rounded up to an LZMA2 one
    • err .Invalid_Properties if lc, lp, pb or the match finder is out of range, otherwise as compress_to_slice

    compress_to_dynamic ¶

    compress_to_dynamic :: proc(
    	output:    ^[dynamic]u8, 
    	input:     []u8, 
    	level:     Level = Level.Default, 
    	options:   compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Compresses a byte slice to a .lzma file into a dynamic array

    The header records the input size, so the stream has no end marker.

    Allocates Using Provided Allocator

    Inputs:

    • output Replaced by the compressed data; emptied on error
    • input The data to compress
    • level (default: .Default)
    • options Caps the output size and working memory, and reports progress (default: {})
    • allocator For the encoder's state, and for output if it has no allocator yet (default: context.allocator)

    Returns:

    • err .Output_Too_Short if the output limit is too small, .Memory_Limit_Exceeded, .Incompatible_Options if output is nil or an option negative, .Input_Too_Large, .Canceled, an allocation error, or nil

    compress_to_slice ¶

    compress_to_slice :: proc(
    	output, input: []u8, 
    	level:         Level = Level.Default, 
    	options:       compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (written: int, err: compress.Error) {…}
     

    Compresses a byte slice to a .lzma file into a slice

    The header records the input size, so the stream has no end marker. An output of at least compress_bound(len(input)) bytes always fits.

    Allocates Using Provided Allocator

    Inputs:

    • output The buffer to compress into; options.max_output_size can shorten it
    • input The data to compress
    • level (default: .Default)
    • options Caps the output size and working memory, and reports progress (default: {})
    • allocator For the encoder's state, freed before returning (default: context.allocator)

    Returns:

    • written The compressed size
    • err .Output_Too_Short, .Memory_Limit_Exceeded, .Incompatible_Options if an option is negative, .Canceled, an allocation error, or nil

    decode_properties ¶

    decode_properties :: proc "contextless" (data: []u8) -> (props: Properties, err: compress.Error) {…}
     

    Decodes an LZMA stream's 5 properties bytes, as .lzma, 7z and zip store them

    Inputs:

    Returns:

    • props The properties
    • err .Stream_Too_Short if data is short, .Invalid_Properties if the first byte is above 224, or nil

    decompress_from_bytes ¶

    decompress_from_bytes :: proc(
    	output:               ^[dynamic]u8, 
    	input:                []u8, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Decompresses a .lzma file from a byte slice into a dynamic array

    Allocates Using Provided Allocator

    Inputs:

    • output Replaced by the decompressed data
    • input The compressed data
    • expected_output_size The exact output size, or -1 if unknown (default: -1)
    • options Caps the output size and working memory, and reports progress (default: {})
    • allocator For the decoder's state, and for output if it has no allocator yet (default: context.allocator)

    Returns:

    decompress_from_context ¶

    decompress_from_context :: proc(
    	z:                    ^compress.Context, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Decompresses a .lzma file from a compress.Context into its output array

    Allocates Using Provided Allocator

    Inputs:

    • z The context; its output is replaced by the decompressed data
    • expected_output_size The exact output size, or -1 if unknown (default: -1)
    • options Caps the output size and working memory, and reports progress (default: {})
    • allocator For the decoder's state, and for z.output if it has no allocator yet (default: context.allocator)

    Returns:

    • err .Incompatible_Options if z.output is nil or an option negative, .Stream_Too_Short, .Size_Mismatch if the header's or the decoded size isn't the expected one, .Output_Too_Short past the output limit, .Memory_Limit_Exceeded, an LZMA_Error for corrupt data, .Canceled, an allocation error, or nil

    decompress_lzip_from_bytes ¶

    decompress_lzip_from_bytes :: proc(
    	output:               ^[dynamic]u8, 
    	input:                []u8, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Decompresses an lzip file from a byte slice into a dynamic array

    Allocates Using Provided Allocator

    Inputs:

    • output Replaced by the decompressed data
    • input The compressed data
    • expected_output_size The exact output size, or -1 if unknown (default: -1)
    • options Caps the output size and working memory, and reports progress (default: {})
    • allocator For the decoder's state, and for output if it has no allocator yet (default: context.allocator)

    Returns:

    decompress_lzip_from_context ¶

    decompress_lzip_from_context :: proc(
    	z:                    ^compress.Context, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Decompresses an lzip file from a compress.Context into its output array

    The members' data is joined. Data after the last member is ignored, unless it looks like a damaged or truncated member header.

    Allocates Using Provided Allocator

    Inputs:

    • z The context; its output is replaced by the decompressed data
    • expected_output_size The exact output size, or -1 if unknown (default: -1)
    • options Caps the output size and working memory, and reports progress (default: {})
    • allocator For the decoder's state, and for z.output if it has no allocator yet (default: context.allocator)

    Returns:

    • err .Incompatible_Options if z.output is nil or an option negative, .Stream_Too_Short, .Size_Mismatch if the decoded size isn't the expected one, .Output_Too_Short past the output limit, .Memory_Limit_Exceeded, an LZIP_Error for a bad header, marker or trailer, an LZMA_Error for corrupt data, .Canceled, an allocation error, or nil

    decompress_lzip_to_writer ¶

    decompress_lzip_to_writer :: proc(
    	w:                    io.Stream, 
    	z:                    ^compress.Context, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Decompresses an lzip file from a compress.Context to an io.Writer

    The members' data is joined, and trailing data is handled as by decompress_lzip_from_context. Memory use is as for decompress_to_writer, with the largest member's dictionary.

    Allocates Using Provided Allocator

    Inputs:

    • w Where the decompressed data goes; it's never closed
    • z The input
    • expected_output_size The exact output size, or -1 if unknown (default: -1)
    • options Caps the output size and working memory, sets the chunk size, and reports progress (default: {})
    • allocator For the decoder's state, freed before returning (default: context.allocator)

    Returns:

    decompress_lzma2_append ¶

    decompress_lzma2_append :: proc(
    	dec:                  ^LZMA2_Decoder, 
    	output:               ^[dynamic]u8, 
    	input:                []u8, 
    	dict_size:            u32, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    ) -> (consumed: int, err: compress.Error) {…}
     

    Decompresses a raw LZMA2 stream from the start of a byte slice, appending it to a dynamic array

    The output counts towards options.max_output_size along with what output already holds.

    Allocates Using Provided Allocator

    Inputs:

    • dec The decoder, set up with lzma2_decoder_init; its tables are reused across calls. A zero decoder takes context.allocator
    • output Gets the decompressed data appended; on error it keeps what was decoded
    • input The compressed data; bytes after the stream's end are left alone
    • dict_size The stream's dictionary size, as lzma2_dict_size gives it
    • expected_output_size The exact size this call adds, or -1 if unknown (default: -1)
    • options Caps the output size and working memory, and reports progress (default: {})

    Returns:

    • consumed The bytes of input read
    • err .Incompatible_Options if dec or output is nil, .Output_Too_Short if output is already past the output limit, otherwise as decompress_lzma2_from_context

    decompress_lzma2_from_bytes ¶

    decompress_lzma2_from_bytes :: proc(
    	output:               ^[dynamic]u8, 
    	input:                []u8, 
    	dict_size:            u32, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Decompresses a raw LZMA2 stream from a byte slice into a dynamic array

    Allocates Using Provided Allocator

    Inputs:

    • output Replaced by the decompressed data
    • input The compressed data
    • dict_size The stream's dictionary size, as lzma2_dict_size gives it
    • expected_output_size The exact output size, or -1 if unknown (default: -1)
    • options Caps the output size and working memory, and reports progress (default: {})
    • allocator For the decoder's state, and for output if it has no allocator yet (default: context.allocator)

    Returns:

    decompress_lzma2_from_context ¶

    decompress_lzma2_from_context :: proc(
    	z:                    ^compress.Context, 
    	dict_size:            u32, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Decompresses a raw LZMA2 stream from a compress.Context into its output array

    Allocates Using Provided Allocator

    Inputs:

    • z The context; its output is replaced by the decompressed data
    • dict_size The stream's dictionary size, as lzma2_dict_size gives it
    • expected_output_size The exact output size, or -1 if unknown (default: -1)
    • options Caps the output size and working memory, and reports progress (default: {})
    • allocator For the decoder's state, and for z.output if it has no allocator yet (default: context.allocator)

    Returns:

    • err .Incompatible_Options if z.output is nil or an option negative, .Stream_Too_Short, .Size_Mismatch if the decoded size isn't the expected one, .Output_Too_Short past the output limit, .Memory_Limit_Exceeded, an LZMA_Error for corrupt data, .Canceled, an allocation error, or nil

    decompress_lzma2_to_writer ¶

    decompress_lzma2_to_writer :: proc(
    	w:                    io.Stream, 
    	z:                    ^compress.Context, 
    	dict_size:            u32, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Decompresses a raw LZMA2 stream from a compress.Context to an io.Writer

    Memory use is as for decompress_to_writer.

    Allocates Using Provided Allocator

    Inputs:

    • w Where the decompressed data goes; it's never closed
    • z The input
    • dict_size The stream's dictionary size, as lzma2_dict_size gives it
    • expected_output_size The exact output size, or -1 if unknown (default: -1)
    • options Caps the output size and working memory, sets the chunk size, and reports progress (default: {})
    • allocator For the decoder's state, freed before returning (default: context.allocator)

    Returns:

    decompress_raw_from_bytes ¶

    decompress_raw_from_bytes :: proc(
    	output:               ^[dynamic]u8, 
    	input:                []u8, 
    	props:                Properties, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Decompresses a raw LZMA stream from a byte slice into a dynamic array

    Without an expected size the stream must end with an end marker.

    Allocates Using Provided Allocator

    Inputs:

    • output Replaced by the decompressed data
    • input The compressed data
    • props The stream's properties, as decode_properties gives them
    • expected_output_size The exact output size, or -1 if unknown (default: -1)
    • options Caps the output size and working memory, and reports progress (default: {})
    • allocator For the decoder's state, and for output if it has no allocator yet (default: context.allocator)

    Returns:

    decompress_raw_from_context ¶

    decompress_raw_from_context :: proc(
    	z:                    ^compress.Context, 
    	props:                Properties, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Decompresses a raw LZMA stream from a compress.Context into its output array

    Without an expected size the stream must end with an end marker.

    Allocates Using Provided Allocator

    Inputs:

    • z The context; its output is replaced by the decompressed data
    • props The stream's properties, as decode_properties gives them
    • expected_output_size The exact output size, or -1 if unknown (default: -1)
    • options Caps the output size and working memory, and reports progress (default: {})
    • allocator For the decoder's state, and for z.output if it has no allocator yet (default: context.allocator)

    Returns:

    decompress_raw_to_writer ¶

    decompress_raw_to_writer :: proc(
    	w:                    io.Stream, 
    	z:                    ^compress.Context, 
    	props:                Properties, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Decompresses a raw LZMA stream from a compress.Context to an io.Writer

    Without an expected size the stream must end with an end marker. Memory use is as for decompress_to_writer.

    Allocates Using Provided Allocator

    Inputs:

    • w Where the decompressed data goes; it's never closed
    • z The input
    • props The stream's properties, as decode_properties gives them
    • expected_output_size The exact output size, or -1 if unknown (default: -1)
    • options Caps the output size and working memory, sets the chunk size, and reports progress (default: {})
    • allocator For the decoder's state, freed before returning (default: context.allocator)

    Returns:

    decompress_to_writer ¶

    decompress_to_writer :: proc(
    	w:                    io.Stream, 
    	z:                    ^compress.Context, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Decompresses a .lzma file from a compress.Context to an io.Writer

    The decoder keeps the dictionary plus a chunk in memory, within options.max_memory; options.buffer replaces it.

    Allocates Using Provided Allocator

    Inputs:

    • w Where the decompressed data goes; it's never closed
    • z The input
    • expected_output_size The exact output size, or -1 if unknown (default: -1)
    • options Caps the output size and working memory, sets the chunk size, and reports progress (default: {})
    • allocator For the decoder's state, freed before returning (default: context.allocator)

    Returns:

    • err .Incompatible_Options if an option is negative, .Stream_Too_Short, .Size_Mismatch if the header's or the decoded size isn't the expected one, .Output_Too_Short past options.max_output_size, .Memory_Limit_Exceeded, also if options.buffer is too small, an LZMA_Error for corrupt data, .Canceled, the io.Writer's error, an allocation error, or nil

    encode_properties ¶

    encode_properties :: proc "contextless" (props: Properties) -> (data: [5]u8) {…}
     

    Encodes properties as an LZMA stream's 5 properties bytes; they must be within the _MAX limits

    level_options ¶

    level_options :: proc(level: Level = Level.Default) -> (options: Options) {…}
     

    Returns the encoder settings for a level after xz's presets, clamping it to 0 through 9 and leaving out the end marker

    lzma2_decoder_destroy ¶

    lzma2_decoder_destroy :: proc(dec: ^LZMA2_Decoder) {…}
     

    Frees an LZMA2_Decoder's tables and clears it

    lzma2_decoder_init ¶

    lzma2_decoder_init :: proc(dec: ^LZMA2_Decoder, allocator := context.allocator) {…}
     

    Sets up an LZMA2_Decoder; the first decompress_lzma2_append call allocates its tables with allocator

    lzma2_dict_prop ¶

    lzma2_dict_prop :: proc "contextless" (dict_size: u32) -> (prop: u8) {…}
     

    Returns the smallest LZMA2 dictionary byte whose size holds dict_size

    lzma2_dict_size ¶

    lzma2_dict_size :: proc "contextless" (prop: u8) -> (dict_size: u32, err: compress.Error) {…}
     

    Decodes an LZMA2 dictionary byte, as 7z and xz store it

    Inputs:

    • prop An even one means 1 << (prop / 2 + 12) bytes, an odd one 1.5 times the one below it, and 40 means 4 GiB - 1

    Returns:

    • dict_size The dictionary size
    • err .Invalid_Properties if prop is above LZMA2_DICT_PROP_MAX, or nil

    reader_destroy ¶

    reader_destroy :: proc(r: ^Reader) {…}
     

    Frees a Reader's decoder and window, unless the window is options.buffer; its compress.Context is left alone

    reader_init ¶

    reader_init :: proc(
    	r:                    ^Reader, 
    	z:                    ^compress.Context, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Sets up a Reader that decompresses a .lzma file from a compress.Context

    It reads the header now. Memory use is as for decompress_to_writer.

    Allocates Using Provided Allocator

    Inputs:

    • r The reader; it's cleared first
    • z The input; it must stay valid while the reader is used
    • expected_output_size The exact output size, or -1 if unknown (default: -1)
    • options Caps the output size and working memory, sets the chunk size, and reports progress (default: {})
    • allocator (default: context.allocator)

    Returns:

    reader_init_lzip ¶

    reader_init_lzip :: proc(
    	r:                    ^Reader, 
    	z:                    ^compress.Context, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Sets up a Reader that decompresses an lzip file from a compress.Context

    It reads the first member's header now. Members and memory use are as for decompress_lzip_to_writer.

    Allocates Using Provided Allocator

    Inputs:

    • r The reader; it's cleared first
    • z The input; it must stay valid while the reader is used
    • expected_output_size The exact output size, or -1 if unknown (default: -1)
    • options Caps the output size and working memory, sets the chunk size, and reports progress (default: {})
    • allocator (default: context.allocator)

    Returns:

    reader_init_lzma2 ¶

    reader_init_lzma2 :: proc(
    	r:                    ^Reader, 
    	z:                    ^compress.Context, 
    	dict_size:            u32, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Sets up a Reader that decompresses a raw LZMA2 stream from a compress.Context

    Memory use is as for decompress_to_writer.

    Allocates Using Provided Allocator

    Inputs:

    • r The reader; it's cleared first
    • z The input; it must stay valid while the reader is used
    • dict_size The stream's dictionary size, as lzma2_dict_size gives it
    • expected_output_size The exact output size, or -1 if unknown (default: -1)
    • options Caps the output size and working memory, sets the chunk size, and reports progress (default: {})
    • allocator (default: context.allocator)

    Returns:

    reader_init_raw ¶

    reader_init_raw :: proc(
    	r:                    ^Reader, 
    	z:                    ^compress.Context, 
    	props:                Properties, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Sets up a Reader that decompresses a raw LZMA stream from a compress.Context

    Without an expected size the stream must end with an end marker. Memory use is as for decompress_to_writer.

    Allocates Using Provided Allocator

    Inputs:

    • r The reader; it's cleared first
    • z The input; it must stay valid while the reader is used
    • props The stream's properties, as decode_properties gives them
    • expected_output_size The exact output size, or -1 if unknown (default: -1)
    • options Caps the output size and working memory, sets the chunk size, and reports progress (default: {})
    • allocator (default: context.allocator)

    Returns:

    • err .Invalid_Properties if lc, lp or pb is out of range, otherwise as reader_init

    reader_read ¶

    reader_read :: proc(r: ^Reader, p: []u8) -> (n: int, err: compress.Error) {…}
     

    Reads decompressed data from a Reader, decoding more as needed

    Inputs:

    • r The reader
    • p The buffer to fill

    Returns:

    • n The bytes read
    • err .EOF once all data has been read, a decoding error once the bytes before it have been read, or nil; an error sticks

    reader_to_stream ¶

    reader_to_stream :: proc(r: ^Reader) -> (s: io.Stream) {…}
     

    Wraps a Reader as an io.Stream that reads and destroys it; errors that aren't io.Errors read as .Unknown

    writer_destroy ¶

    writer_destroy :: proc(lw: ^Writer) {…}
     

    Frees a Writer's encoder and window, unless the window is options.buffer, without finishing it; the io.Writer is left open

    writer_finish ¶

    writer_finish :: proc(lw: ^Writer) -> (err: compress.Error) {…}
     

    Compresses what a Writer still holds and ends the stream; an lzip member gets its trailer

    Calling it again does nothing. It doesn't free the writer.

    Inputs:

    • lw The writer

    Returns:

    • err .Size_Mismatch if fewer bytes came than the input size given, the io.Writer's error, .Canceled, an earlier error, or nil

    writer_init ¶

    writer_init :: proc(
    	lw:         ^Writer, 
    	w:          io.Stream, 
    	level:      Level = Level.Default, 
    	input_size: i64 = -1, 
    	options:    compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Sets up a Writer that compresses to a .lzma file on an io.Writer

    The header goes out with the first block. Without an input size it records the size as unknown and the stream ends with an end marker. The dictionary shrinks, down to DICT_SIZE_MIN, until the encoder fits options.max_memory, or its window fits options.buffer.

    Allocates Using Provided Allocator

    Inputs:

    • lw The writer; it's cleared first
    • w Where the compressed stream goes; it's never closed
    • level (default: .Default)
    • input_size The exact bytes that will be written, or -1 if unknown (default: -1)
    • options Caps the working memory and reports progress (default: {})
    • allocator (default: context.allocator)

    Returns:

    • err .Incompatible_Options if an option is negative or options.buffer too small, .Memory_Limit_Exceeded, an allocation error, or nil; on error lw is destroyed

    writer_init_lzip ¶

    writer_init_lzip :: proc(
    	lw:         ^Writer, 
    	w:          io.Stream, 
    	level:      Level = Level.Default, 
    	input_size: i64 = -1, 
    	options:    compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}
     

    Sets up a Writer that compresses to a single-member lzip file on an io.Writer

    The dictionary shrinks as for writer_init; writer_finish writes the trailer.

    Allocates Using Provided Allocator

    Inputs:

    • lw The writer; it's cleared first
    • w Where the compressed stream goes; it's never closed
    • level (default: .Default)
    • input_size The exact bytes that will be written, or -1 if unknown (default: -1)
    • options Caps the working memory and reports progress (default: {})
    • allocator (default: context.allocator)

    Returns:

    writer_init_lzma2 ¶

    writer_init_lzma2 :: proc(
    	lw:           ^Writer, 
    	w:            io.Stream, 
    	lzma_options: Options, 
    	input_size:   i64 = -1, 
    	options:      compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (props: Properties, err: compress.Error) {…}
     

    Sets up a Writer that compresses to a raw LZMA2 stream on an io.Writer

    The dictionary shrinks as for writer_init.

    Allocates Using Provided Allocator

    Inputs:

    • lw The writer; it's cleared first
    • w Where the compressed stream goes; it's never closed
    • lzma_options The encoder's settings, with lc + lp at most 4; see level_options
    • input_size The exact bytes that will be written, or -1 if unknown (default: -1)
    • options Caps the working memory and reports progress (default: {})
    • allocator (default: context.allocator)

    Returns:

    • props The stream's settings; lzma2_dict_prop(props.dict_size) is its dictionary byte
    • err As writer_init_raw

    writer_init_raw ¶

    writer_init_raw :: proc(
    	lw:           ^Writer, 
    	w:            io.Stream, 
    	lzma_options: Options, 
    	input_size:   i64 = -1, 
    	options:      compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (props: Properties, err: compress.Error) {…}
     

    Sets up a Writer that compresses to a raw LZMA stream on an io.Writer

    The dictionary shrinks as for writer_init.

    Allocates Using Provided Allocator

    Inputs:

    • lw The writer; it's cleared first
    • w Where the compressed stream goes; it's never closed
    • lzma_options The encoder's settings; see level_options
    • input_size The exact bytes that will be written, or -1 if unknown (default: -1)
    • options Caps the working memory and reports progress (default: {})
    • allocator (default: context.allocator)

    Returns:

    • props The properties to store with the stream; the dictionary size is rounded up to an LZMA2 one
    • err .Invalid_Properties if lc, lp, pb or the match finder is out of range, otherwise as writer_init

    writer_to_stream ¶

    writer_to_stream :: proc(lw: ^Writer) -> (s: io.Stream) {…}
     

    Wraps a Writer as an io.Stream: closing it finishes the writer, destroying it destroys it; errors that aren't io.Errors read as .Unknown

    writer_write ¶

    writer_write :: proc(lw: ^Writer, p: []u8) -> (n: int, err: compress.Error) {…}
     

    Compresses data into a Writer, writing compressed blocks out as they fill

    Inputs:

    • lw The writer
    • p The data to compress

    Returns:

    • n The bytes taken
    • err .Size_Mismatch if it goes past the input size given, .Closed after writer_finish, the io.Writer's error, .Canceled, an earlier error, or nil

    Procedure Groups

    compress ¶

    compress :: proc{
    	compress_to_slice,
    	compress_to_dynamic,
    }
    
     

    Compresses a byte slice to a .lzma file, into a slice or a dynamic array

    compress_lzip ¶

     

    Compresses a byte slice to a single-member lzip file, into a slice or a dynamic array

    compress_lzma2 ¶

     

    Compresses a byte slice to a raw LZMA2 stream, into a slice or a dynamic array

    compress_raw ¶

     

    Compresses a byte slice to a raw LZMA stream, into a slice or a dynamic array

    decompress ¶

     

    Decompresses a .lzma file from a byte slice or a compress.Context

    decompress_lzip ¶

     

    Decompresses an lzip file from a byte slice or a compress.Context

    decompress_lzma2 ¶

     

    Decompresses a raw LZMA2 stream from a byte slice or a compress.Context

    decompress_raw ¶

     

    Decompresses a raw LZMA stream from a byte slice or a compress.Context

    Source Files

    Generation Information

    Generated with odin version dev-2026-11 (vendor "odin") Windows_amd64 @ 2026-11-30 21:05:49.814964300 +0000 UTC