package core:compress/xz

⌘K
Ctrl+K
or
/

    Overview

    An implementation of the .xz file format

    Reads and writes .xz files, also stored in zip as method 95: LZMA2 behind up to three filters (Delta and the branch converters from core:compress/filters), with an optional CRC32, CRC64 or SHA-256 check. Concatenated streams and stream padding decode as one, and checks of other types are skipped unverified. read_index, find_block and decompress_block seek through a file's index and decode single blocks.

    Types

    Block_Info ¶

    Block_Info :: struct {
    	stream:              int,
    	compressed_offset:   i64,
    	uncompressed_offset: i64,
    	unpadded_size:       i64,
    	uncompressed_size:   i64,
    }

    Check ¶

    Check :: enum u8 {
    	None   = 0x00, 
    	CRC32  = 0x01, 
    	CRC64  = 0x04, 
    	SHA256 = 0x0A, 
    }

    Decode_Flag ¶

    Decode_Flag :: enum u8 {
    	Ignore_Check, 
    }

    Filter ¶

    Filter :: struct {
    	id:             Filter_ID,
    	start_offset:   u32,
    	delta_distance: int,
    }

    Filter_ID ¶

    Filter_ID :: enum u64 {
    	Delta     = 0x03, 
    	X86       = 0x04, 
    	PowerPC   = 0x05, 
    	IA64      = 0x06, 
    	ARM       = 0x07, 
    	ARM_Thumb = 0x08, 
    	SPARC     = 0x09, 
    	ARM64     = 0x0A, 
    	RISCV     = 0x0B, 
    	LZMA2     = 0x21, 
    }

    Index ¶

    Index :: struct {
    	streams:           [dynamic]Stream_Info,
    	blocks:            [dynamic]Block_Info,
    	compressed_size:   i64,
    	uncompressed_size: i64,
    }

    Related Procedures With Parameters

    Related Procedures With Returns

    Level ¶

    Level :: compress_lzma.Level

    Related Procedures With Parameters

    Options ¶

    Options :: struct {
    	lzma2:        compress_lzma.Options,
    	check:        runtime.Maybe($T=Check),
    	block_size:   int,
    	filters:      [3]Filter,
    	filter_count: int,
    }

    Related Procedures With Parameters

    Reader ¶

    Reader :: struct {
    	z:                ^compress.Context,
    	flags:            bit_set[Decode_Flag; u8],
    	options:          compress.Options,
    	allocator:        runtime.Allocator,
    	size:             int,
    	total_in:         i64,
    	consumed:         i64,
    	produced:         i64,
    	done:             bool,
    	err:              compress.Error,
    	check_id:         u8,
    	stream_flags:     [2]u8,
    	records:          u64,
    	unpadded_sum:     u64,
    	uncompressed_sum: u64,
    	index_hash:       sha2.Context_256,
    	in_block:         bool,
    	lzma:             compress_lzma.Reader,
    	chain:            [3]compress_filters.Reader,
    	chain_count:      int,
    	header_size:      int,
    	compressed:       u64,
    	uncompressed:     u64,
    	has_compressed:   bool,
    	has_uncompressed: bool,
    	block_out:        u64,
    	crc32:            u32,
    	crc64:            u64,
    	sha256:           sha2.Context_256,
    	bounded:          bool,
    	block_view:       bool,
    	block_z:          compress.Context,
    	block_data:       []u8,
    	block_left:       u64,
    	block_eof:        bool,
    	block_backing:    []u8,
    }

    Related Procedures With Parameters

    Stream_Info ¶

    Stream_Info :: struct {
    	check_id:            u8,
    	compressed_offset:   i64,
    	compressed_size:     i64,
    	uncompressed_offset: i64,
    	uncompressed_size:   i64,
    	padding:             i64,
    	first_block:         int,
    	block_count:         int,
    }

    Writer ¶

    Writer :: struct {
    	w:           io.Stream,
    	opts:        Options,
    	options:     compress.Options,
    	allocator:   runtime.Allocator,
    	check:       Check,
    	props:       compress_lzma.Properties,
    	lzma:        compress_lzma.Writer,
    	chain:       [3]compress_filters.Writer,
    	chain_count: int,
    	open:        bool,
    	in_block:    bool,
    	block_in:    u64,
    	block_start: i64,
    	header_size: int,
    	records:     [dynamic][2]u64,
    	total_in:    i64,
    	total_out:   i64,
    	next_report: i64,
    	crc32:       u32,
    	crc64:       u64,
    	sha256:      sha2.Context_256,
    	err:         compress.Error,
    	finished:    bool,
    }

    Related Procedures With Parameters

    Constants

    BLOCK_SIZE_MIN ¶

    BLOCK_SIZE_MIN :: 1 << 20

    INDEX_RECORD_MAX ¶

    INDEX_RECORD_MAX :: 2 * VLI_BYTES_MAX

    INDEX_SIZE_MAX ¶

    INDEX_SIZE_MAX :: u64(1) << 34

    UNPADDED_SIZE_MAX ¶

    UNPADDED_SIZE_MAX: u64 : VLI_MAX &~ 3

    VLI_MAX ¶

    VLI_MAX :: u64(max(i64))

    Variables

    CHECK_SIZES ¶

    @(rodata)
    CHECK_SIZES: [16]int = …
    @(rodata)
    FOOTER_MAGIC: [2]u8 = …

    HEADER_MAGIC ¶

    @(rodata)
    HEADER_MAGIC: [6]u8 = …

    Procedures

    compress_bound ¶

    compress_bound :: proc(
    	length:     int, 
    	level:      compress_lzma.Level = Level.Default, 
    	xz_options: Options = Options{}, 
    ) -> int {…}

    compress_to_dynamic ¶

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

    compress_to_slice ¶

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

    decompress_block_from_bytes ¶

    decompress_block_from_bytes :: proc(
    	output:    ^[dynamic]u8, 
    	input:     []u8, 
    	index:     ^Index, 
    	block:     int, 
    	flags:     bit_set[Decode_Flag; u8] = Decode_Flags{}, 
    	options:   compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}

    decompress_block_from_stream ¶

    decompress_block_from_stream :: proc(
    	output:    ^[dynamic]u8, 
    	input:     io.Stream, 
    	index:     ^Index, 
    	block:     int, 
    	flags:     bit_set[Decode_Flag; u8] = Decode_Flags{}, 
    	options:   compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}

    decompress_from_bytes ¶

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

    decompress_from_context ¶

    decompress_from_context :: proc(
    	z:                    ^compress.Context, 
    	flags:                bit_set[Decode_Flag; u8] = Decode_Flags{}, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}

    decompress_to_writer ¶

    decompress_to_writer :: proc(
    	w:                    io.Stream, 
    	z:                    ^compress.Context, 
    	flags:                bit_set[Decode_Flag; u8] = Decode_Flags{}, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}

    find_block ¶

    find_block :: proc(index: ^Index, uncompressed_offset: i64) -> (block: int, ok: bool) {…}

    index_destroy ¶

    index_destroy :: proc(index: ^Index) {…}

    level_options ¶

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

    read_index_from_bytes ¶

    read_index_from_bytes :: proc(
    	input:     []u8, 
    	allocator := context.allocator, 
    ) -> (index: Index, err: compress.Error) {…}

    read_index_from_stream ¶

    read_index_from_stream :: proc(
    	input:     io.Stream, 
    	allocator := context.allocator, 
    ) -> (index: Index, err: compress.Error) {…}

    reader_destroy ¶

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

    reader_init ¶

    reader_init :: proc(
    	r:                    ^Reader, 
    	z:                    ^compress.Context, 
    	flags:                bit_set[Decode_Flag; u8] = Decode_Flags{}, 
    	expected_output_size: int = -1, 
    	options:              compress.Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: compress.Error) {…}

    reader_read ¶

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

    reader_to_stream ¶

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

    writer_destroy ¶

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

    writer_finish ¶

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

    writer_init ¶

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

    writer_to_stream ¶

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

    writer_write ¶

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

    Procedure Groups

    Source Files

    Generation Information

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