struct Simple [src]

Fields

buffer: []u8Note that store blocks are limited to 65535 bytes.
wp: usize
block_writer: BlockWriter
hasher: Container.Hasher
strategy: Strategy

Members

Source

pub const Simple = struct { /// Note that store blocks are limited to 65535 bytes. buffer: []u8, wp: usize, block_writer: BlockWriter, hasher: Container.Hasher, strategy: Strategy, pub const Strategy = enum { huffman, store }; pub fn init(output: *Writer, buffer: []u8, container: Container, strategy: Strategy) !Simple { const header = container.header(); try output.writeAll(header); return .{ .buffer = buffer, .wp = 0, .block_writer = .init(output), .hasher = .init(container), .strategy = strategy, }; } pub fn flush(self: *Simple) !void { try self.flushBuffer(false); try self.block_writer.storedBlock("", false); try self.block_writer.flush(); } pub fn finish(self: *Simple) !void { try self.flushBuffer(true); try self.block_writer.flush(); try self.hasher.container().writeFooter(&self.hasher, self.block_writer.output); } fn flushBuffer(self: *Simple, final: bool) !void { const buf = self.buffer[0..self.wp]; switch (self.strategy) { .huffman => try self.block_writer.huffmanBlock(buf, final), .store => try self.block_writer.storedBlock(buf, final), } self.wp = 0; } }