Function decodeZstandardFrame [src]
Decode a Zstandard frame from src into dest, returning the number of
bytes read from src and written to dest. The first four bytes of src
must be the magic number for a Zstandard frame.
Error returned:
error.UnknownContentSizeUnsupported if the frame does not declare the
uncompressed content size
error.ContentTooLarge if dest is smaller than the uncompressed data
size declared by the frame header
error.WindowSizeUnknown if the frame does not have a valid window size
error.DictionaryIdFlagUnsupported if the frame uses a dictionary
error.ContentSizeTooLarge if the frame header indicates a content size
that is larger than std.math.maxInt(usize)
error.ChecksumFailure if verify_checksum is true and the frame
contains a checksum that does not match the checksum of the decompressed
data
error.ReservedBitSet if the reserved bit of the frame header is set
error.EndOfStream if src does not contain a complete frame
an error in block.Error if there are errors decoding a block
error.BadContentSize if the content size declared by the frame does
not equal the actual size of decompressed data
Prototype
pub fn decodeZstandardFrame( dest: []u8, src: []const u8, verify_checksum: bool, ) (error{ UnknownContentSizeUnsupported, ContentTooLarge, ContentSizeTooLarge, WindowSizeUnknown, DictionaryIdFlagUnsupported, } || FrameError)!ReadWriteCount
Parameters
dest: []u8
src: []const u8
verify_checksum: bool
Source
pub fn decodeZstandardFrame(
dest: []u8,
src: []const u8,
verify_checksum: bool,
) (error{
UnknownContentSizeUnsupported,
ContentTooLarge,
ContentSizeTooLarge,
WindowSizeUnknown,
DictionaryIdFlagUnsupported,
} || FrameError)!ReadWriteCount {
assert(std.mem.readInt(u32, src[0..4], .little) == frame.Zstandard.magic_number);
var consumed_count: usize = 4;
var frame_context = context: {
var fbs = std.io.fixedBufferStream(src[consumed_count..]);
const source = fbs.reader();
const frame_header = try decodeZstandardHeader(source);
consumed_count += fbs.pos;
break :context FrameContext.init(
frame_header,
std.math.maxInt(usize),
verify_checksum,
) catch |err| switch (err) {
error.WindowTooLarge => unreachable,
inline else => |e| return e,
};
};
const counts = try decodeZStandardFrameBlocks(
dest,
src[consumed_count..],
&frame_context,
);
return ReadWriteCount{
.read_count = counts.read_count + consumed_count,
.write_count = counts.write_count,
};
}