package core:compress

⌘K
Ctrl+K
or
/

    Overview

    A collection of utilities to aid with other compression packages.

    Packages 10

    bzip2An implementation of the BZIP2 compression method
    deflateDeflate compression and decompression implementation, following RFC 1950 (zlib), RFC 1951 (DEFLATE),
    filtersReversible filters that make executables and some other data compress better
    gzipA small GZIP unpacker.
    lz4This package implements Yann Collet's LZ4 Block and Frame compression and decompression.
    lzmaAn implementation of the LZMA and LZMA2 compression methods
    pkzip-legacyDecoders for PKZIP's legacy compression methods: Shrink (1), Reduce (2-5) and Implode (6).
    ppmdAn implementation of the PPMd compression methods
    shocoShoco short string compression and decompression.
    zlibDeflate decompression of raw and ZLIB-type streams.

    Types

    BCJ2_Error ¶

    BCJ2_Error :: enum int {
    	None          = 0, 
    	Corrupt_Data, 
    	Size_Mismatch, 
    }

    BZip2_Error ¶

    BZip2_Error :: enum int {
    	None                     = 0, 
    	Invalid_Magic, 
    	Invalid_Block_Magic, 
    	Invalid_Original_Pointer, 
    	No_Symbols_In_Use, 
    	Invalid_Group_Count, 
    	Invalid_Selector_Count, 
    	Invalid_Selector, 
    	Invalid_Code_Length, 
    	Invalid_Huffman_Code, 
    	Selectors_Exhausted, 
    	Run_Too_Long, 
    	Block_Too_Large, 
    	Block_Checksum_Failed, 
    	Stream_Checksum_Failed, 
    	Input_Too_Large, 
    }

    Context ¶

    Context :: struct #align (64) {
    	input:             io.Stream,
    	// 32-bit: 8, 64-bit: 16
    	output:            ^[dynamic]u8,
    	// 32-bit: 4, 64-bit: 8
    	bytes_written:     i64,
    	// 32-bit: 8, 64-bit: 8
    	code_buffer:       u64,
    	// 32-bit: 8, 64-bit: 8
    	num_bits:          u64,
    	// Some algorithms, like legacy PKZIP methods Implode & Reduce,
    	// need to know the unpacked size to not write a spurious tail,
    	size_unpacked:     i64,
    	// 32-bit: 8, 64-bit: 8
    	buffer:            []u8,
    	window:            []u8,
    	backing:           []u8,
    	backing_allocator: runtime.Allocator,
    	owns_backing:      b8,
    	_reserved:         [7]u8,
    }
     

    A generic I/O context for ZLIB, LZW, etc.

    When input.procedure equals this package's _memory_reader_proc, it signals that input.data is a ^[]byte containing the whole input, which we can access directly as a fast path.

    Streams are now read in blocks into window, backed by backing to forestall unnecessary slowdowns by reading a stream byte-by-byte.

    Related Procedures With Parameters

    Related Procedures With Returns

    Deflate_Error ¶

    Deflate_Error :: enum int {
    	None                     = 0, 
    	Huffman_Bad_Sizes, 
    	Huffman_Bad_Code_Lengths, 
    	Bad_Distance, 
    	Bad_Huffman_Code, 
    	Len_Nlen_Mismatch, 
    	BType_3, 
    }

    GZIP_Error ¶

    GZIP_Error :: enum int {
    	None                   = 0, 
    	Invalid_GZIP_Signature, 
    	Reserved_Flag_Set, 
    	Invalid_Extra_Data, 
    	Original_Name_Too_Long, 
    	Comment_Too_Long, 
    	Header_CRC_Invalid, 
    	Payload_Length_Invalid, 
    	Payload_CRC_Invalid, 
    }

    General_Error ¶

    General_Error :: enum int {
    	None                                        = 0, 
    	File_Not_Found, 
    	Cannot_Open_File, 
    	File_Too_Short, 
    	Stream_Too_Short, 
    	Output_Too_Short, 
    	Unknown_Compression_Method, 
    	Checksum_Failed, 
    	Incompatible_Options, 
    	Unimplemented, 
    	Allocation_Failed, 
    	Output_Exceeds_COMPRESS_OUTPUT_ALLOCATE_MAX, 
    }

    LZ4_Error ¶

    LZ4_Error :: enum int {
    	None                    = 0, 
    	Invalid_Magic, 
    	Unsupported_Version, 
    	Reserved_Bit_Set, 
    	Invalid_Block_Max_Size, 
    	Header_Checksum_Failed, 
    	Block_Checksum_Failed, 
    	Content_Checksum_Failed, 
    	Content_Size_Mismatch, 
    	Block_Too_Large, 
    	Dictionary_Required, 
    	Invalid_Offset, 
    	Offset_Out_Of_Range, 
    	Literal_Overrun, 
    	Input_Too_Large, 
    }

    LZMA_Error ¶

    LZMA_Error :: enum int {
    	None                  = 0, 
    	Invalid_Properties, 
    	Invalid_Header, 
    	Corrupt_Range_Coder, 
    	Invalid_Distance, 
    	Unexpected_End_Marker, 
    	Size_Mismatch, 
    	Invalid_Chunk, 
    	Input_Too_Large, 
    }

    Memory_Reader ¶

    Memory_Reader :: io.Stream
     

    A fake io.Stream for when the full input is in memory as a ^[]bytein itsdata` pointer.

    Related Procedures With Parameters

    PKZIP_Legacy_Error ¶

    PKZIP_Legacy_Error :: enum int {
    	None                   = 0, 
    	Invalid_First_Code, 
    	Invalid_Control_Code, 
    	Code_Size_Too_Large, 
    	Invalid_Code, 
    	Invalid_Follower_Set, 
    	Invalid_Follower_Index, 
    	Invalid_Tree, 
    }

    PPMd_Error ¶

    PPMd_Error :: enum int {
    	None                  = 0, 
    	Invalid_Properties, 
    	Corrupt_Data, 
    	Unexpected_End_Marker, 
    	Memory_Limit_Exceeded, 
    }

    ZLIB_Error ¶

    ZLIB_Error :: enum int {
    	None                    = 0, 
    	Unsupported_Window_Size, 
    	FDICT_Unsupported, 
    	Code_Buffer_Malformed, 
    }

    Constants

    BZIP2_EXPANSION_MAX ¶

    BZIP2_EXPANSION_MAX :: 2_331_000

    COMPRESS_GROWTH_MIN ¶

    COMPRESS_GROWTH_MIN :: 4 * 1024

    COMPRESS_GROWTH_STEP ¶

    COMPRESS_GROWTH_STEP :: 16 * 1024 * 1024

    COMPRESS_INITIAL_RESERVATION ¶

    COMPRESS_INITIAL_RESERVATION :: int(#config(COMPRESS_INITIAL_RESERVATION, 16 * 1024 * 1024))

    COMPRESS_INITIAL_RESERVATION_RATIO ¶

    COMPRESS_INITIAL_RESERVATION_RATIO :: int(#config(COMPRESS_INITIAL_RESERVATION_RATIO, 4))

    COMPRESS_OUTPUT_ALLOCATE_MAX ¶

    COMPRESS_OUTPUT_ALLOCATE_MAX :: int(#config(COMPRESS_OUTPUT_ALLOCATE_MAX, 1 << 32))
     

    For 64-bit platforms, we set the default max buffer size to 4 GiB, which is GZIP and PKZIP's max payload size.

    COMPRESS_RESERVE_DEFAULT ¶

    COMPRESS_RESERVE_DEFAULT :: 64 * 1024

    CONTEXT_WINDOW_SIZE ¶

    CONTEXT_WINDOW_SIZE :: 64 * 1024

    DEFLATE64_EXPANSION_MAX ¶

    DEFLATE64_EXPANSION_MAX :: 29128

    Variables

    This section is empty.

    Procedures

    destroy_context ¶

    destroy_context :: proc(z: ^Context) {…}

    init_context_from_slice ¶

    init_context_from_slice :: proc(
    	data:          ^[]u8, 
    	output:        ^[dynamic]u8 = nil, 
    	size_unpacked: i64 = i64(-1), 
    ) -> (ctx: Context) {…}
     

    Initialize I/O Context from byte slice

    init_context_from_stream ¶

    init_context_from_stream :: proc(
    	stream:        io.Stream, 
    	output:        ^[dynamic]u8 = nil, 
    	size_unpacked: i64 = i64(-1), 
    	buffer:        []u8 = nil, 
    	allocator := context.allocator, 
    ) -> (ctx: Context) {…}
     

    Initialize I/O Context from io.Stream

    input_size ¶

    input_size :: proc(z: ^Context) -> (res: int) {…}

    is_memory_context ¶

    is_memory_context :: proc(z: ^Context) -> (memory_context: bool) {…}
     

    Tests whether the Context was initialized with the full input in memory

    output_grow_capacity ¶

    output_grow_capacity :: proc "contextless" (capacity, need, limit: int) -> (new_capacity: int) {…}

    output_reservation ¶

    output_reservation :: proc "contextless" (declared, bound, input_size: int) -> (size: int) {…}

    peek_data_at_cursor ¶

    @(optimization_mode="favor_size")
    peek_data_at_cursor :: proc(z: ^Context, $T: typeid) -> (res: T, err: io.Error) {…}

    peek_data_at_offset ¶

    @(optimization_mode="favor_size")
    peek_data_at_offset :: proc(
    	z:      ^Context, 
    	$T:      typeid, 
    	#any_int offset: i64, 
    ) -> (res: T, err: io.Error) {…}

    peek_input_at ¶

    @(optimization_mode="favor_size")
    peek_input_at :: proc(z: ^Context, buf: []u8, offset: i64) -> (err: io.Error) {…}

    read_data ¶

    @(optimization_mode="favor_size")
    read_data :: proc(z: ^Context, $T: typeid) -> (res: T, err: io.Error) {…}

    read_ptr ¶

    @(optimization_mode="favor_size")
    read_ptr :: proc(z: ^Context, ptr: ^$T) -> (err: io.Error) {…}

    read_remaining ¶

    @(optimization_mode="favor_size")
    read_remaining :: proc(
    	z:         ^Context, 
    	allocator := context.allocator, 
    ) -> (data: [dynamic]u8, err: io.Error) {…}

    read_slice ¶

    @(optimization_mode="favor_size")
    read_slice :: proc(z: ^Context, buf: []u8) -> (err: io.Error) {…}

    read_u8 ¶

    @(optimization_mode="favor_size")
    read_u8 :: proc(z: ^Context) -> (res: u8, err: io.Error) {…}

    refill_window ¶

    @(optimization_mode="favor_size")
    refill_window :: proc(z: ^Context, need: int) -> (err: io.Error) {…}

    rewind ¶

    rewind :: proc(z: ^Context, n: int) -> (ok: bool) {…}

    size ¶

    @(optimization_mode="favor_size")
    size :: proc(z: ^Context) -> (res: i64, err: io.Error) {…}
     

    Returns the size of the Context's input or io.Errors.

    skip ¶

    @(optimization_mode="favor_size")
    skip :: proc(z: ^Context, offset: i64) -> (err: io.Error) {…}

    Procedure Groups

    Source Files

    Generation Information

    Generated with odin version dev-2026-11 (vendor "odin") Windows_amd64 @ 2026-11-10 03:07:04.374188700 +0000 UTC