Struct seekable_reader::SeekableReader [−][src]
pub struct SeekableReader<R: Read> {
pub inner: R,
pub keep_size: usize,
pub read_bytes: usize,
// some fields omitted
}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: Rkeep_size: usizeread_bytes: usizeBytes read from inner
Implementations
pub fn new(inner: R, keep_size: usize) -> SeekableReader<R>ⓘNotable traits for SeekableReader<R>impl<R: Read> Read for SeekableReader<R>
pub fn new(inner: R, keep_size: usize) -> SeekableReader<R>ⓘNotable traits for SeekableReader<R>impl<R: Read> Read for SeekableReader<R>
impl<R: Read> Read for 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.
Returns the size of the buffered data. Attempts to seek further back will result an Error.
Trait Implementations
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);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.
Like read, except that it reads into a slice of buffers. Read more
can_vector)Determines if this Reader has an efficient read_vectored
implementation. Read more
read_initializer)Determines if this Reader can work with buffers of uninitialized
memory. Read more
Read all bytes until EOF in this source, placing them into buf. Read more
Read all bytes until EOF in this source, appending them to buf. Read more
Read the exact number of bytes required to fill buf. Read more
Creates a “by reference” adapter for this instance of Read. Read more
Creates an adapter which will chain this stream with another. Read more