Struct lz_fear::framed::LZ4FrameReader
source · pub struct LZ4FrameReader<R: Read> { /* private fields */ }
Expand description
Read an LZ4-compressed frame.
This reader reads the blocks inside a frame one by one.
Implementations§
source§impl<R: Read> LZ4FrameReader<R>
impl<R: Read> LZ4FrameReader<R>
sourcepub fn new(reader: R) -> Result<Self, DecompressionError>
pub fn new(reader: R) -> Result<Self, DecompressionError>
Create a new LZ4FrameReader over an underlying reader and parse the header.
A typical LZ4 file consists of exactly one frame. This reader will stop reading at the end of the frame. If you want to read any data following this frame, you should probably pass in your reader by reference, rather than by value.
sourcepub fn block_size(&self) -> usize
pub fn block_size(&self) -> usize
Returns the maximum number of bytes a block can decompress to (as specified by the file header).
In general, all blocks in a frame except for the final one will have exactly this size. (Although this is not strictly enforced and may be violated by hand-crafted inputs)
sourcepub fn frame_size(&self) -> Option<u64>
pub fn frame_size(&self) -> Option<u64>
Returns the number of bytes that this entire frame is supposed to decompress to. This value is read directly from the file header and may be incorrect for malicious inputs.
sourcepub fn dictionary_id(&self) -> Option<u32>
pub fn dictionary_id(&self) -> Option<u32>
Return an identifier for the dictionary that was used to compress this frame.
Dictionary identifiers are always application-specific. Note that the lz4 command line utility never specifies a dictionary id, even if a dictionary was used.
sourcepub fn into_read_with_dictionary(
self,
dictionary: &[u8]
) -> LZ4FrameIoReader<'_, R> ⓘ
pub fn into_read_with_dictionary( self, dictionary: &[u8] ) -> LZ4FrameIoReader<'_, R> ⓘ
Convert this LZ4FrameReader
into something that implements std::io::BufRead
.
Note that io::copy
has a small performance issue: https://github.com/rust-lang/rust/issues/49921
sourcepub fn into_read(self) -> LZ4FrameIoReader<'static, R> ⓘ
pub fn into_read(self) -> LZ4FrameIoReader<'static, R> ⓘ
Convenience wrapper in case you don’t want to specify a dictionary.
sourcepub fn decode_block(
&mut self,
output: &mut Vec<u8>,
dictionary: &[u8]
) -> Result<(), DecompressionError>
pub fn decode_block( &mut self, output: &mut Vec<u8>, dictionary: &[u8] ) -> Result<(), DecompressionError>
Decode a single block.
The output
buffer must be empty upon calling this method.