compress.snappy #
Constants
fn compress #
fn compress(input []u8) []u8
compress compresses input and returns the compressed bytes.
fn crc32c #
fn crc32c(data []u8) u32
crc32c returns the CRC-32C checksum of data.
fn decode_stream #
fn decode_stream(input []u8) ![]u8
decode_stream decodes a Snappy framing stream and returns the concatenated uncompressed data, or an error if the stream is malformed.
fn decompress #
fn decompress(input []u8) ![]u8
decompress decompresses a Snappy-compressed slice and returns the original bytes, or an error if the data is malformed.
fn encode_stream #
fn encode_stream(input []u8) []u8
encode_stream wraps input in the Snappy framing format and returns the complete byte stream. Input is split into ≤64 KiB blocks automatically.
struct StreamDecoder #
struct StreamDecoder {
mut:
buf []u8 // unparsed compressed bytes
offset int // read position within buf (avoids repeated cloning)
identified bool // have we seen the stream identifier chunk?
err ?IError
output []u8 // decoded bytes ready for the caller
closed bool
}
StreamDecoder holds state for incremental framing-format decoding. Call write() with successive chunks of compressed input, and call read() to read the decoded bytes. The writer must call close() when it finishes writing the bytes.
fn (StreamDecoder) write #
fn (mut dec StreamDecoder) write(buf []u8) !int
write appends buf to the decoder's input buffer and processes as many complete chunks as possible. Returns an error if the stream is malformed.
fn (StreamDecoder) read #
fn (mut dec StreamDecoder) read(mut buf []u8) !int
read removes and returns decoded bytes. When the output buffer is empty it surfaces any error recorded during write()/close(). Only then does it return io.Eof{} for a cleanly terminated stream.
fn (StreamDecoder) close #
fn (mut dec StreamDecoder) close() !
close marks the stream finished and validates its terminal state. Returns an error if the stream was truncated or the identifier was never received. The error is also stored internally so read() will surface it after draining output.
struct StreamEncoder #
struct StreamEncoder {
mut:
buf []u8 // pending uncompressed bytes
out []u8 = stream_header // accumulated encoded output, initialized with stream identifier
closed bool
}
StreamEncoder holds state for incremental framing-format encoding. Call write() one or more times, then close() to flush the final chunk. Take the encoded bytes using read().
fn (StreamEncoder) write #
fn (mut enc StreamEncoder) write(buf []u8) !int
write appends buf to the encoder, flushing complete 64 KiB chunks.
fn (StreamEncoder) read #
fn (mut enc StreamEncoder) read(mut buf []u8) !int
fn (StreamEncoder) close #
fn (mut enc StreamEncoder) close()
close flushes any remaining buffered bytes and returns the complete stream. The encoder must not be used after this call.
fn (StreamEncoder) peek #
fn (enc StreamEncoder) peek() []u8
peek returns the encoded bytes produced so far without flushing.