pub struct FrameDecoder<R: Read> { /* private fields */ }
Expand description
A reader for decompressing the LZ4 frame format
This Decoder wraps any other reader that implements io::Read
.
Bytes read will be decompressed according to the LZ4 frame format.
§Example 1
Deserializing json values out of a compressed file.
let compressed_input = std::fs::File::open("datafile").unwrap();
let mut decompressed_input = lz4_flex::frame::FrameDecoder::new(compressed_input);
let json: serde_json::Value = serde_json::from_reader(decompressed_input).unwrap();
§Example
Deserializing multiple json values out of a compressed file
let compressed_input = std::fs::File::open("datafile").unwrap();
let mut decompressed_input = lz4_flex::frame::FrameDecoder::new(compressed_input);
loop {
match serde_json::from_reader::<_, serde_json::Value>(&mut decompressed_input) {
Ok(json) => { println!("json {:?}", json); }
Err(e) if e.is_eof() => break,
Err(e) => panic!("{}", e),
}
}
Implementations§
Source§impl<R: Read> FrameDecoder<R>
impl<R: Read> FrameDecoder<R>
Sourcepub fn new(rdr: R) -> FrameDecoder<R> ⓘ
pub fn new(rdr: R) -> FrameDecoder<R> ⓘ
Creates a new Decoder for the specified reader.
Sourcepub fn get_mut(&mut self) -> &mut R
pub fn get_mut(&mut self) -> &mut R
Gets a mutable reference to the underlying reader in this decoder.
Note that mutation of the stream may result in surprising results if this decoder is continued to be used.
Sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Consumes the FrameDecoder and returns the underlying reader.
Trait Implementations§
Source§impl<R: Read> BufRead for FrameDecoder<R>
impl<R: Read> BufRead for FrameDecoder<R>
Source§fn fill_buf(&mut self) -> Result<&[u8]>
fn fill_buf(&mut self) -> Result<&[u8]>
Returns the contents of the internal buffer, filling it with more data
from the inner reader if it is empty. Read more
Source§fn consume(&mut self, amt: usize)
fn consume(&mut self, amt: usize)
Tells this buffer that
amt
bytes have been consumed from the buffer,
so they should no longer be returned in calls to read
. Read moreSource§fn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
🔬This is a nightly-only experimental API. (
buf_read_has_data_left
)Checks if the underlying
Read
has any data left to be read. Read more1.83.0 · Source§fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
Skips all bytes until the delimiter
byte
or EOF is reached. Read more1.0.0 · Source§fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
Reads all bytes until a newline (the
0xA
byte) is reached, and append
them to the provided String
buffer. Read moreSource§impl<R: Read> Read for FrameDecoder<R>
impl<R: Read> Read for FrameDecoder<R>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Pull some bytes from this source into the specified buffer, returning
how many bytes were read. Read more
Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
Reads all bytes until EOF in this source, appending them to
buf
. Read moreSource§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
Reads all bytes until EOF in this source, placing them into
buf
. Read more1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
Like
read
, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector
)1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
Reads the exact number of bytes required to fill
buf
. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf
)Pull some bytes from this source into the specified buffer. Read more
Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf
)Reads the exact number of bytes required to fill
cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Creates a “by reference” adaptor for this instance of
Read
. Read moreAuto Trait Implementations§
impl<R> Freeze for FrameDecoder<R>where
R: Freeze,
impl<R> RefUnwindSafe for FrameDecoder<R>where
R: RefUnwindSafe,
impl<R> Send for FrameDecoder<R>where
R: Send,
impl<R> Sync for FrameDecoder<R>where
R: Sync,
impl<R> Unpin for FrameDecoder<R>where
R: Unpin,
impl<R> UnwindSafe for FrameDecoder<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more