package core:compress

Overview

package compress is a collection of utilities to aid with other compression packages

Types

Context_Memory_Input ¶

Context_Memory_Input :: struct #packed {
	input_data:    []u8,
	output:        ^bytes.Buffer,
	bytes_written: i64,
	code_buffer:   u64,
	num_bits:      u64,
	// 		If we know the data size, we can optimize the reads and writes.
	size_packed:   i64,
	size_unpacked: i64,
}
 

General I/O context for ZLIB, LZW, etc.

Context_Stream_Input ¶

Context_Stream_Input :: struct #packed {
	input_data:            []u8,
	input:                 io.Stream,
	output:                ^bytes.Buffer,
	bytes_written:         i64,
	code_buffer:           u64,
	num_bits:              u64,
	// 		If we know the data size, we can optimize the reads and writes.
	size_packed:           i64,
	size_unpacked:         i64,
	// 		Flags:
	// 			`input_fully_in_memory`
	// 				true  = This tells us we read input from `input_data` exclusively. [] = EOF.
	// 				false = Try to refill `input_data` from the `input` stream.
	input_fully_in_memory: b8,
	padding:               [1]u8,
}

Deflate_Error ¶

Deflate_Error :: enum int {
	None                     = 0, 
	Huffman_Bad_Sizes, 
	Huffman_Bad_Code_Lengths, 
	Inflate_Error, 
	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, 
	Payload_Length_Invalid, 
	Payload_CRC_Invalid, 
	// 		GZIP's payload can be a maximum of max(u32le), or 4 GiB.
	// 		If you tell it you expect it to contain more, that's obviously an error.
	Payload_Size_Exceeds_Max_Payload, 
	// 		For buffered instead of streamed output, the payload size can't exceed
	// 		the max set by the `COMPRESS_OUTPUT_ALLOCATE_MAX` switch in compress/common.odin.
	// 
	// 		You can tweak this setting using `-define:COMPRESS_OUTPUT_ALLOCATE_MAX=size_in_bytes`
	Output_Exceeds_COMPRESS_OUTPUT_ALLOCATE_MAX, 
}

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, 
	// 		Memory errors
	Allocation_Failed, 
	Resize_Failed, 
}

ZIP_Error ¶

ZIP_Error :: enum int {
	None                                     = 0, 
	Invalid_ZIP_File_Signature, 
	Unexpected_Signature, 
	Insert_Next_Disk, 
	Expected_End_of_Central_Directory_Record, 
}

ZLIB_Error ¶

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

Constants

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_OUTPUT_ALLOCATE_MIN ¶

COMPRESS_OUTPUT_ALLOCATE_MIN :: int(#config(COMPRESS_OUTPUT_ALLOCATE_MIN, 1 << 20))
 

When a decompression routine doesn't stream its output, but writes to a buffer,

we pre-allocate an output buffer to speed up decompression. The default is 1 MiB.

Variables

This section is empty.

Procedures

consume_bits_lsb_from_memory ¶

consume_bits_lsb_from_memory :: proc "odin" (z: ^Context_Memory_Input, width: u8) {…}

consume_bits_lsb_from_stream ¶

consume_bits_lsb_from_stream :: proc "odin" (z: ^Context_Stream_Input, width: u8) {…}

discard_to_next_byte_lsb_from_memory ¶

discard_to_next_byte_lsb_from_memory :: proc "odin" (z: ^Context_Memory_Input) {…}

discard_to_next_byte_lsb_from_stream ¶

discard_to_next_byte_lsb_from_stream :: proc "odin" (z: ^Context_Stream_Input) {…}

input_size_from_memory ¶

input_size_from_memory :: proc "odin" (z: ^Context_Memory_Input) -> (res: i64, err: Error) {…}

input_size_from_stream ¶

input_size_from_stream :: proc "odin" (z: ^Context_Stream_Input) -> (res: i64, err: Error) {…}

peek_back_byte ¶

peek_back_byte :: proc "odin" (z: ^$, offset: i64) -> (res: u8, err: io.Error) {…}

peek_bits_lsb_from_memory ¶

peek_bits_lsb_from_memory :: proc "odin" (z: ^Context_Memory_Input, width: u8) -> u32 {…}

peek_bits_lsb_from_stream ¶

peek_bits_lsb_from_stream :: proc "odin" (z: ^Context_Stream_Input, width: u8) -> u32 {…}

peek_bits_no_refill_lsb_from_memory ¶

peek_bits_no_refill_lsb_from_memory :: proc "odin" (z: ^Context_Memory_Input, width: u8) -> u32 {…}

peek_bits_no_refill_lsb_from_stream ¶

peek_bits_no_refill_lsb_from_stream :: proc "odin" (z: ^Context_Stream_Input, width: u8) -> u32 {…}

peek_data_at_offset_from_memory ¶

peek_data_at_offset_from_memory :: proc "odin" (z: ^Context_Memory_Input, $T: typeid, #any_int offset: int) -> (res: typeid, err: io.Error) {…}

peek_data_at_offset_from_stream ¶

peek_data_at_offset_from_stream :: proc "odin" (z: ^Context_Stream_Input, $T: typeid, #any_int offset: int) -> (res: typeid, err: io.Error) {…}

peek_data_from_memory ¶

peek_data_from_memory :: proc "odin" (z: ^Context_Memory_Input, $T: typeid) -> (res: typeid, err: io.Error) {…}

peek_data_from_stream ¶

peek_data_from_stream :: proc "odin" (z: ^Context_Stream_Input, $T: typeid) -> (res: typeid, err: io.Error) {…}

read_bits_lsb_from_memory ¶

read_bits_lsb_from_memory :: proc "odin" (z: ^Context_Memory_Input, width: u8) -> u32 {…}

read_bits_lsb_from_stream ¶

read_bits_lsb_from_stream :: proc "odin" (z: ^Context_Stream_Input, width: u8) -> u32 {…}

read_bits_no_refill_lsb_from_memory ¶

read_bits_no_refill_lsb_from_memory :: proc "odin" (z: ^Context_Memory_Input, width: u8) -> u32 {…}

read_bits_no_refill_lsb_from_stream ¶

read_bits_no_refill_lsb_from_stream :: proc "odin" (z: ^Context_Stream_Input, width: u8) -> u32 {…}

read_data ¶

read_data :: proc "odin" (z: ^$, $T: typeid) -> (res: typeid, err: io.Error) {…}

read_slice_from_memory ¶

read_slice_from_memory :: proc "odin" (z: ^Context_Memory_Input, size: int) -> (res: []u8, err: io.Error) {…}

read_slice_from_stream ¶

read_slice_from_stream :: proc "odin" (z: ^Context_Stream_Input, size: int) -> (res: []u8, err: io.Error) {…}

read_u8_from_memory ¶

read_u8_from_memory :: proc "odin" (z: ^Context_Memory_Input) -> (res: u8, err: io.Error) {…}

read_u8_from_stream ¶

read_u8_from_stream :: proc "odin" (z: ^Context_Stream_Input) -> (res: u8, err: io.Error) {…}

read_u8_prefer_code_buffer_lsb ¶

read_u8_prefer_code_buffer_lsb :: proc "odin" (z: ^$) -> (res: u8, err: io.Error) {…}

refill_lsb_from_memory ¶

refill_lsb_from_memory :: proc "odin" (z: ^Context_Memory_Input, width: i8 = i8(48)) {…}

refill_lsb_from_stream ¶

refill_lsb_from_stream :: proc "odin" (z: ^Context_Stream_Input, width: i8 = i8(24)) {…}

Procedure Groups

Source Files

Generation Information

Generated with odin version dev-2022-10 (vendor "odin") Windows_amd64 @ 2022-10-05 21:11:47.304919700 +0000 UTC