package core:compress
Overview
A collection of utilities to aid with other compression packages.
Packages 10
| bzip2 | An implementation of the BZIP2 compression method | |
| deflate | Deflate compression and decompression implementation, following RFC 1950 (zlib), RFC 1951 (DEFLATE), | |
| filters | Reversible filters that make executables and some other data compress better | |
| gzip | A small GZIP unpacker. | |
| lz4 | This package implements Yann Collet's LZ4 Block and Frame compression and decompression. | |
| lzma | An implementation of the LZMA and LZMA2 compression methods | |
| pkzip-legacy | Decoders for PKZIP's legacy compression methods: Shrink (1), Reduce (2-5) and Implode (6). | |
| ppmd | An implementation of the PPMd compression methods | |
| shoco | Shoco short string compression and decompression. | |
| zlib | Deflate decompression of raw and ZLIB-type streams. |
Index
Constants (16)
Variables (0)
This section is empty.
Procedures (19)
Procedure Groups (2)
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
- init_context_from_slice
- init_context_from_stream
- init_context (procedure groups)
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, }
Error ¶
Error :: union { General_Error, Deflate_Error, ZLIB_Error, GZIP_Error, LZ4_Error, BZip2_Error, PKZIP_Legacy_Error, LZMA_Error, PPMd_Error, BCJ2_Error, io.Error, runtime.Allocator_Error, }
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
- init_context_from_stream
- init_context (procedure groups)
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_HISTORY ¶
CONTEXT_HISTORY :: 16
CONTEXT_WINDOW_SIZE ¶
CONTEXT_WINDOW_SIZE :: 64 * 1024
DEFLATE64_EXPANSION_MAX ¶
DEFLATE64_EXPANSION_MAX :: 29128
DEFLATE_EXPANSION_MAX ¶
DEFLATE_EXPANSION_MAX :: 1032
IMPLODE_EXPANSION_MAX ¶
IMPLODE_EXPANSION_MAX :: 256
LZ4_EXPANSION_MAX ¶
LZ4_EXPANSION_MAX :: 255
LZMA_EXPANSION_MAX ¶
LZMA_EXPANSION_MAX :: 7168
REDUCE_EXPANSION_MAX ¶
REDUCE_EXPANSION_MAX :: 512
SHRINK_EXPANSION_MAX ¶
SHRINK_EXPANSION_MAX :: 8192
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 ¶
is_memory_context ¶
Tests whether the Context was initialized with the full input in memory
read_remaining ¶
@(optimization_mode="favor_size") read_remaining :: proc( z: ^Context, allocator := context.allocator, ) -> (data: [dynamic]u8, err: io.Error) {…}
Procedure Groups
init_context ¶
init_context :: proc{ init_context_from_slice, init_context_from_stream, }
peek_data ¶
peek_data :: proc{ peek_data_at_cursor, peek_data_at_offset, }
Source Files
Generation Information
Generated with odin version dev-2026-11 (vendor "odin") Windows_amd64 @ 2026-11-10 03:07:04.374188700 +0000 UTC