package core:compress/lzma
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)
- decode_properties
decompress_… (13)
- decompress_from_bytes
- decompress_from_context
- decompress_lzip_from_bytes
- decompress_lzip_from_context
- decompress_lzip_to_writer
- decompress_lzma2_append
- decompress_lzma2_from_bytes
- decompress_lzma2_from_context
- decompress_lzma2_to_writer
- decompress_raw_from_bytes
- decompress_raw_from_context
- decompress_raw_to_writer
- decompress_to_writer
- encode_properties
- level_options
Procedure Groups (8)
Types
Error ¶
Error :: compress.Error
The core:compress error types this package returns
Related Procedures With Returns
- compress_lzip_to_dynamic
- compress_lzip_to_slice
- compress_lzma2_append
- compress_lzma2_to_dynamic
- compress_lzma2_to_slice
- compress_raw_to_dynamic
- compress_raw_to_slice
- compress_to_dynamic
- compress_to_slice
- decode_properties
- decompress_from_bytes
- decompress_from_context
- decompress_lzip_from_bytes
- decompress_lzip_from_context
- decompress_lzip_to_writer
- decompress_lzma2_append
- decompress_lzma2_from_bytes
- decompress_lzma2_from_context
- decompress_lzma2_to_writer
- decompress_raw_from_bytes
- decompress_raw_from_context
- decompress_raw_to_writer
- decompress_to_writer
- lzma2_dict_size
- reader_init
- reader_init_lzip
- reader_init_lzma2
- reader_init_raw
- reader_read
- writer_finish
- writer_init
- writer_init_lzip
- writer_init_lzma2
- writer_init_raw
- writer_write
- compress (procedure groups)
- compress_lzip (procedure groups)
- compress_lzma2 (procedure groups)
- compress_raw (procedure groups)
- decompress (procedure groups)
- decompress_lzip (procedure groups)
- decompress_lzma2 (procedure groups)
- decompress_raw (procedure groups)
General_Error ¶
General_Error :: compress.General_Error
LZIP_Error ¶
LZIP_Error :: compress.LZIP_Error
LZMA2_Decoder ¶
The probability tables decompress_lzma2_append reuses across calls; set up with
lzma2_decoder_init
Related Procedures With Parameters
LZMA_Error ¶
LZMA_Error :: compress.LZMA_Error
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
- compress_lzip_to_dynamic
- compress_lzip_to_slice
- compress_to_dynamic
- compress_to_slice
- level_options
- writer_init
- writer_init_lzip
- compress (procedure groups)
- compress_lzip (procedure groups)
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
- compress_lzma2_append
- compress_lzma2_to_dynamic
- compress_lzma2_to_slice
- compress_raw_to_dynamic
- compress_raw_to_slice
- writer_init_lzma2
- writer_init_raw
- compress_lzma2 (procedure groups)
- compress_raw (procedure groups)
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
- compress_lzma2_append
- compress_lzma2_to_dynamic
- compress_lzma2_to_slice
- compress_raw_to_dynamic
- compress_raw_to_slice
- decode_properties
- writer_init_lzma2
- writer_init_raw
- compress_lzma2 (procedure groups)
- compress_raw (procedure groups)
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
LC_MAX ¶
LC_MAX :: 8
LP_MAX ¶
LP_MAX :: 4
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)
LZIP_VERSION ¶
LZIP_VERSION :: 1
PB_MAX ¶
PB_MAX :: 4
Variables
LZIP_MAGIC ¶
@(rodata) LZIP_MAGIC: [4]u8 = …
Procedures
compress_bound ¶
Returns the most bytes a .lzma file can take for an input size, or -1 if it's out of range
compress_lzip_bound ¶
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
outputif it has no allocator yet (default: context.allocator)
Returns:
- err As
compress_to_dynamic
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_sizecan 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 As
compress_to_slice
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
outputif 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 ¶
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
outputif 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_sizecan 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 ¶
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
outputif 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_Propertiesif lc, lp, pb or the match finder is out of range, otherwise ascompress_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_sizecan 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_Propertiesif lc, lp, pb or the match finder is out of range, otherwise ascompress_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
outputif it has no allocator yet (default: context.allocator)
Returns:
- err
.Output_Too_Shortif the output limit is too small,.Memory_Limit_Exceeded,.Incompatible_Optionsifoutputis nil or an option negative,.Input_Too_Large,.Canceled, an allocation error, ornil
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_sizecan 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_Optionsif an option is negative,.Canceled, an allocation error, ornil
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:
- data The bytes; only the first
PROPERTIES_SIZEare read
Returns:
- props The properties
- err
.Stream_Too_Shortifdatais short,.Invalid_Propertiesif the first byte is above 224, ornil
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
outputif it has no allocator yet (default: context.allocator)
Returns:
- err As
decompress_from_context
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
outputis 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.outputif it has no allocator yet (default: context.allocator)
Returns:
- err
.Incompatible_Optionsifz.outputis nil or an option negative,.Stream_Too_Short,.Size_Mismatchif the header's or the decoded size isn't the expected one,.Output_Too_Shortpast the output limit,.Memory_Limit_Exceeded, anLZMA_Errorfor corrupt data,.Canceled, an allocation error, ornil
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
outputif it has no allocator yet (default: context.allocator)
Returns:
- err As
decompress_lzip_from_context
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
outputis 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.outputif it has no allocator yet (default: context.allocator)
Returns:
- err
.Incompatible_Optionsifz.outputis nil or an option negative,.Stream_Too_Short,.Size_Mismatchif the decoded size isn't the expected one,.Output_Too_Shortpast the output limit,.Memory_Limit_Exceeded, anLZIP_Errorfor a bad header, marker or trailer, anLZMA_Errorfor corrupt data,.Canceled, an allocation error, ornil
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:
- err An
LZIP_Errorfor a bad header, marker or trailer, otherwise asdecompress_to_writer
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 takescontext.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_sizegives 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
inputread - err
.Incompatible_Optionsifdecoroutputis nil,.Output_Too_Shortifoutputis already past the output limit, otherwise asdecompress_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_sizegives 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
outputif 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
outputis replaced by the decompressed data - dict_size The stream's dictionary size, as
lzma2_dict_sizegives 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.outputif it has no allocator yet (default: context.allocator)
Returns:
- err
.Incompatible_Optionsifz.outputis nil or an option negative,.Stream_Too_Short,.Size_Mismatchif the decoded size isn't the expected one,.Output_Too_Shortpast the output limit,.Memory_Limit_Exceeded, anLZMA_Errorfor corrupt data,.Canceled, an allocation error, ornil
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_sizegives 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:
- err As
decompress_to_writer
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_propertiesgives 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
outputif it has no allocator yet (default: context.allocator)
Returns:
- err As
decompress_raw_from_context
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
outputis replaced by the decompressed data - props The stream's properties, as
decode_propertiesgives 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.outputif it has no allocator yet (default: context.allocator)
Returns:
- err
.Invalid_Propertiesif lc, lp or pb is out of range, otherwise asdecompress_from_context
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_propertiesgives 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:
- err
.Invalid_Propertiesif lc, lp or pb is out of range, otherwise asdecompress_to_writer
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_Optionsif an option is negative,.Stream_Too_Short,.Size_Mismatchif the header's or the decoded size isn't the expected one,.Output_Too_Shortpastoptions.max_output_size,.Memory_Limit_Exceeded, also ifoptions.bufferis too small, anLZMA_Errorfor corrupt data,.Canceled, theio.Writer's error, an allocation error, ornil
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 ¶
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 ¶
Returns the smallest LZMA2 dictionary byte whose size holds dict_size
lzma2_dict_size ¶
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_Propertiesifpropis aboveLZMA2_DICT_PROP_MAX, ornil
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:
- err As
decompress_to_writer, without theio.Writer's; on errorris destroyed
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:
- err As
decompress_lzip_to_writer, without theio.Writer's; on errorris destroyed
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_sizegives 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:
- err As
reader_init
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_propertiesgives 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_Propertiesif lc, lp or pb is out of range, otherwise asreader_init
reader_read ¶
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
.EOFonce all data has been read, a decoding error once the bytes before it have been read, ornil; an error sticks
writer_destroy ¶
writer_destroy :: proc(lw: ^Writer) {…}
writer_finish ¶
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_Mismatchif fewer bytes came than the input size given, theio.Writer's error,.Canceled, an earlier error, ornil
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_Optionsif an option is negative oroptions.buffertoo small,.Memory_Limit_Exceeded, an allocation error, ornil; on errorlwis 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:
- err As
writer_init
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_Propertiesif lc, lp, pb or the match finder is out of range, otherwise aswriter_init
writer_write ¶
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_Mismatchif it goes past the input size given,.Closedafterwriter_finish, theio.Writer's error,.Canceled, an earlier error, ornil
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 ¶
compress_lzip :: proc{ compress_lzip_to_slice, compress_lzip_to_dynamic, }
Compresses a byte slice to a single-member lzip file, into a slice or a dynamic array
compress_lzma2 ¶
compress_lzma2 :: proc{ compress_lzma2_to_slice, compress_lzma2_to_dynamic, }
Compresses a byte slice to a raw LZMA2 stream, into a slice or a dynamic array
compress_raw ¶
compress_raw :: proc{ compress_raw_to_slice, compress_raw_to_dynamic, }
Compresses a byte slice to a raw LZMA stream, into a slice or a dynamic array
decompress ¶
decompress :: proc{ decompress_from_bytes, decompress_from_context, }
Decompresses a .lzma file from a byte slice or a compress.Context
decompress_lzip ¶
decompress_lzip :: proc{ decompress_lzip_from_bytes, decompress_lzip_from_context, }
Decompresses an lzip file from a byte slice or a compress.Context
decompress_lzma2 ¶
decompress_lzma2 :: proc{ decompress_lzma2_from_bytes, decompress_lzma2_from_context, }
Decompresses a raw LZMA2 stream from a byte slice or a compress.Context
decompress_raw ¶
decompress_raw :: proc{ decompress_raw_from_bytes, decompress_raw_from_context, }
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