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: usize

Bytes read from inner

Implementations

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

🔬 This is a nightly-only experimental API. (can_vector)

Determines if this Reader has an efficient read_vectored implementation. Read more

🔬 This is a nightly-only experimental API. (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

Transforms this Read instance to an Iterator over its bytes. Read more

Creates an adapter which will chain this stream with another. Read more

Creates an adapter which will read at most limit bytes from it. Read more

Seek to an offset, in bytes, in a stream. Read more

Rewind to the beginning of a stream. Read more

🔬 This is a nightly-only experimental API. (seek_stream_len)

Returns the length of this stream (in bytes). Read more

Returns the current seek position from the start of the stream. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.