core/compress/zlib
compress_zlib
Types
8Compression_Level
Compression_Level :: enum u8 {
Fastest = 0,
Fast = 1,
Default = 2,
Maximum = 3,
}SourceCompression_Method
Compression_Method :: enum u8 {
DEFLATE = 8,
Reserved = 15,
}Sourcezlib.inflate decompresses a ZLIB stream passed in as a []u8 or io.Stream.
Returns: Error.
Do we do Adler32 as we write bytes to output?
It used to be faster to do it inline, now it's faster to do it at the end of `inflate`.
We'll see what's faster after more optimization, and might end up removing
`Context.rolling_hash` if not inlining it is still faster.Deflate_Error
Deflate_Error :: Deflate_ErrorSourceError
Error :: ErrorSourceGeneral_Error
General_Error :: General_ErrorSourceHuffman_Table
Huffman_Table :: struct {
fast: [1 << ZFAST_BITS]u16,
firstcode: [17]u16,
maxcode: [17]int,
firstsymbol: [17]u16,
size: [288]u8,
value: [288]u16,
}SourceZLIB-style Huffman encoding.
JPEG packs from left, ZLIB from right. We can't share code.Options
Options :: struct {
window_size: u16,
level: u8,
}SourceZLIB_Error
ZLIB_Error :: ZLIB_ErrorSourceConstants
9DEFLATE_MAX_CHUNK_SIZE
DEFLATE_MAX_CHUNK_SIZE :: 65535SourceDEFLATE_MAX_DISTANCE
DEFLATE_MAX_DISTANCE :: 32768SourceDEFLATE_MAX_LENGTH
DEFLATE_MAX_LENGTH :: 258SourceDEFLATE_MAX_LITERAL_SIZE
DEFLATE_MAX_LITERAL_SIZE :: 65535SourceHUFFMAN_FAST_BITS
HUFFMAN_FAST_BITS :: 9SourceHUFFMAN_FAST_MASK
HUFFMAN_FAST_MASK :: ((1 << HUFFMAN_FAST_BITS) - 1)SourceHUFFMAN_MAX_BITS
HUFFMAN_MAX_BITS :: 16SourceZFAST_BITS
ZFAST_BITS :: 9SourceAccelerate all cases in default tables.
ZFAST_MASK
ZFAST_MASK :: ((1 << ZFAST_BITS) - 1)SourceVariables
7Z_DIST_BASE
Z_DIST_BASE :: [32]u16 = [32]u16{
1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,
257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0,
}SourceZ_DIST_EXTRA
Z_DIST_EXTRA :: [32]u8 = [32]u8{
0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0,
}SourceZ_FIXED_DIST
Z_FIXED_DIST :: [32]u8 = [32]u8{
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
}SourceZ_FIXED_LENGTH
Z_FIXED_LENGTH :: [288]u8 = [288]u8{
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,SourceZ_LENGTH_BASE
Z_LENGTH_BASE :: [31]u16 = [31]u16{
3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,
67,83,99,115,131,163,195,227,258,0,0,
}SourceZ_LENGTH_DEZIGZAG
Z_LENGTH_DEZIGZAG :: []u8 = []u8{
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15,
}SourceZ_LENGTH_EXTRA
Z_LENGTH_EXTRA :: [31]u8 = [31]u8{
0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,
}SourceProcedures
14allocate_huffman_table
allocate_huffman_table :: proc(allocator: mem.Allocator = context.allocator) -> (z: ^Huffman_Table, err: Error)Sourcebuild_huffman
build_huffman :: proc(z: ^Huffman_Table, code_lengths: []u8) -> (err: Error)Sourcedecode_huffman
decode_huffman :: proc(z: ^C, t: ^Huffman_Table) -> (r: u16, err: Error)Sourcedecode_huffman_slowpath
decode_huffman_slowpath :: proc(z: ^C, t: ^Huffman_Table) -> (r: u16, err: Error)Sourcegrow_buffer
grow_buffer :: proc(buf: ^[dynamic]u8) -> (err: compress.Error)Sourceinflate_from_byte_array
inflate_from_byte_array :: proc(input: []u8, buf: ^bytes.Buffer, raw: untyped boolean = false, expected_output_size: untyped integer = -1) -> (err: Error)Sourceinflate_from_byte_array_raw
inflate_from_byte_array_raw :: proc(input: []u8, buf: ^bytes.Buffer, raw: untyped boolean = false, expected_output_size: untyped integer = -1) -> (err: Error)Sourceinflate_from_context
inflate_from_context :: proc(using, raw: untyped boolean = false, expected_output_size: untyped integer = -1, allocator: mem.Allocator = context.allocator) -> (err: Error)Sourceinflate_raw
inflate_raw :: proc(z: ^C, expected_output_size: untyped integer = -1, allocator: mem.Allocator = context.allocator) -> (err: Error)SourceTODO: Check alignment of reserve/resize.
parse_huffman_block
parse_huffman_block :: proc(z: ^C, z_repeat: ^Huffman_Table, z_offset: ^Huffman_Table) -> (err: Error)Sourcerepl_byte
repl_byte :: proc(z: ^C, count: u16, c: u8) -> (err: io.Error)Sourcerepl_bytes
repl_bytes :: proc(z: ^C, count: u16, distance: u16) -> (err: io.Error)Sourcewrite_byte
write_byte :: proc(z: ^C, c: u8) -> (err: io.Error)SourceTODO: Make these return compress.Error.
z_bit_reverse
z_bit_reverse :: proc(n: u16, bits: u8) -> (r: u16)SourceImplementation starts here