GzipReader
struct GzipReaderA gzip file decoded a window at a time: every member of it, or just the first.
The streaming form of gunzip, over Inflater: run decodes until the
window (output()) holds want bytes, the input runs short or the file
ends; compact drops what the caller has used. The input may still be
arriving, and input already consumed may be discarded, exactly as for
Inflater. Headers, CRC-32s and ISIZEs are checked as gunzip checks
them, with the same messages; the CRC is folded in as output is
produced, so it covers bytes long since compacted away.
var gz = GzipReader()
var have = 0 # how much of `data` has arrived
while True:
var st = gz.run(Span(data)[:have], have == len(data), len(gz) + (1 << 20))
parse(gz.output())
_ = gz.compact(len(gz))
if st == InflateStatus.FINISHED:
break
if st == InflateStatus.NEED_INPUT:
have = ... # wait for more
Implements Movable, Sized
- Fields
inflater: Inflater: Holds the window and the DEFLATE state of the member being decoded.state: Intmulti_member: Boolmember: Intmember_at: Int: Absolute input offset of the current member's header (for messages).crc32: _Crc32crc: UInt32crc_at: Int:output()[crc_at:]is not incrcyet.member_out: Intpadding_at: Int
__init__
def __init__(out self, capacity: Int = Int(1048576), multi_member: Bool = True) capacity is the window's starting size. With multi_member false, decoding stops after the first member, and whatever follows it is left alone (input_used() says where it ended).
output
def output(self) -> Span[UInt8, origin_of(self.inflater.out.buf)] Everything decoded and not yet compacted away.
__len__
def __len__(self) -> Int compact
def compact(mut self, keep_from: Int) -> Int Inflater.compact: drop output()[0:keep_from] as far as back-references allow; return how many bytes went.
total_out
def total_out(self) -> Int members
def members(self) -> Int Members decoded and verified so far.
finished
def finished(self) -> Bool finish
def finish(deinit self) -> List[UInt8] The window as a list, consuming the reader.
input_used
def input_used(self) -> Int How many bytes of data the reader is done with; once finished, the offset just past the last trailer it read (or padding).
discard_input
def discard_input(mut self) -> Int Inflater.discard_input: forget the input before input_used() and return how many bytes that is.
total_in
def total_in(self) -> Int run
def run(mut self, data: Span[UInt8], complete: Bool, want: Int = Int.MAX) -> InflateStatus Decode from data until the window holds want bytes: OUTPUT, NEED_INPUT or FINISHED, as Inflater.run. Raises what gunzip raises, once complete says no more input is coming (and on corruption before that).