Function prepare [src]

Prepare the decoder to decode a compressed block. Loads the literals stream and Huffman tree from literals and reads the FSE tables from in.

Prototype

pub fn prepare( self: *Decode, in: *Reader, remaining: *Limit, literals: LiteralsSection, sequences_header: SequencesSection.Header, ) PrepareError!void

Parameters

self: *Decodein: *Readerremaining: *Limitliterals: LiteralsSectionsequences_header: SequencesSection.Header

Possible Errors

EndOfStream

input stream ends before all FSE tables are read

InputBufferUndersize
MalformedAccuracyLog

an FSE table has an invalid accuracy

MalformedFseTable

failed decoding an FSE table

MissingStartBit

the (reversed) literal bitstream's first byte does not have any bits set

ReadFailed
RepeatModeFirst

on the first call if one of the sequence FSE tables is set to repeat mode

TreelessLiteralsFirst

literals is a treeless literals section and the decode state does not have a Huffman tree from a previous block

Source

pub fn prepare( self: *Decode, in: *Reader, remaining: *Limit, literals: LiteralsSection, sequences_header: SequencesSection.Header, ) PrepareError!void { self.literal_written_count = 0; self.literal_header = literals.header; self.literal_streams = literals.streams; if (literals.huffman_tree) |tree| { self.huffman_tree = tree; } else if (literals.header.block_type == .treeless and self.huffman_tree == null) { return error.TreelessLiteralsFirst; } switch (literals.header.block_type) { .raw, .rle => {}, .compressed, .treeless => { self.literal_stream_index = 0; switch (literals.streams) { .one => |slice| try self.initLiteralStream(slice), .four => |streams| try self.initLiteralStream(streams[0]), } }, } if (sequences_header.sequence_count > 0) { try self.updateFseTable(in, remaining, .literal, sequences_header.literal_lengths); try self.updateFseTable(in, remaining, .offset, sequences_header.offsets); try self.updateFseTable(in, remaining, .match, sequences_header.match_lengths); self.fse_tables_undefined = false; } }