pub struct SeekableReader<R: Read> {
pub inner: R,
pub keep_size: usize,
pub read_bytes: usize,
/* private fields */
}Expand description
A reader adapter that allows to seek a little bit
The SeekableReader will wrap around a Read instance and can be read normally.
The core feature is to provide Seek, even if the underlying Reader does not.
It achieves this by holding a cache of the read data, which can be read again.
Fields§
§inner: R§keep_size: usize§read_bytes: usizeBytes read from inner
Implementations§
Source§impl<R: Read> SeekableReader<R>
impl<R: Read> SeekableReader<R>
Sourcepub fn new(inner: R, keep_size: usize) -> SeekableReader<R> ⓘ
pub fn new(inner: R, keep_size: usize) -> SeekableReader<R> ⓘ
Create a new instance of a SeekableReader.
It wraps around inner and allows seeking backwards by
keeping at least keep_size bytes of already read data,
if this amount of data is already read.
At most, 2 * keep_size bytes are kept.
Sourcepub fn buffered_size(&self) -> usize
pub fn buffered_size(&self) -> usize
Returns the size of the buffered data. Attempts to seek further back will result an Error.
pub fn get_stream_position(&self) -> usize
Trait Implementations§
Source§impl<R: Read> Read for SeekableReader<R>
A SeekableReader can be read just normally:
impl<R: Read> Read for SeekableReader<R>
A SeekableReader can be read just normally:
use std::io::Read;
use seekable_reader::SeekableReader;
let source = vec![1, 2, 3, 4, 5];
let reader = SeekableReader::new(source.as_slice(), 1);
let bytes: Vec<_> = reader.bytes().map(|b| b.unwrap()).collect();
assert_eq!(&source, &bytes);Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Read something from this source and write it into buffer, returning how many bytes were read.
read will never read more than buf.len() from the underlying reader. But it may have read less
than it returns, in case the user seeked backwards before, causing the cache to be used.
1.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>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read moreSource§impl<R: Read> Seek for SeekableReader<R>
impl<R: Read> Seek for SeekableReader<R>
Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len)