pub struct SkippingBufReader<F: Read + Seek> { /* private fields */ }
Expand description
A buffering reader that transparently skips inaccessible parts of a file.
It functions similarly to io::BufReader
in that it fills an internal
buffer using larger, infrequent reads but is further capable of handling
intermittent permission errors by repeatedly halving the buffer size and
attempting another read. Eventually, it will fall back to skipping byte
by byte towards the next readable section.
This will occur for many regions in /dev/mem
with a brute-force search.
Skipping long inaccessible sections is very slow, so that should only be
a last resort when no memory map is available.
Implementations§
Source§impl<F: Read + Seek> SkippingBufReader<F>
impl<F: Read + Seek> SkippingBufReader<F>
pub fn new(file: F, start_offset: usize, max_offset: Option<usize>) -> Self
Sourcepub fn with_buffer_size(
buffer_size: usize,
file: F,
start_offset: usize,
max_offset: Option<usize>,
) -> Self
pub fn with_buffer_size( buffer_size: usize, file: F, start_offset: usize, max_offset: Option<usize>, ) -> Self
Create a reader with an internal buffer of the given initial size.
§Panics
This function panics if it cannot seek to the given start_offset
within file
.
Sourcepub fn position_in_file(&mut self) -> usize
pub fn position_in_file(&mut self) -> usize
Return the current read position in the file.
§Note
This is the position a subsequent call to read()
will return bytes
from (or refill the buffer if empty). It is distinct from the actual
seek position in the file, which reflects the end of the latest read
performed to fill the buffer.
§Panics
This function panics if the current seek position in the underlying reader cannot be obtained.
Trait Implementations§
Source§impl<F: Read + Seek> BufRead for SkippingBufReader<F>
impl<F: Read + Seek> BufRead for SkippingBufReader<F>
Source§fn fill_buf(&mut self) -> Result<&[u8]>
fn fill_buf(&mut self) -> Result<&[u8]>
Read
methods, if empty. Read moreSource§fn consume(&mut self, amt: usize)
fn consume(&mut self, amt: usize)
amount
of additional bytes from the internal buffer as having been read.
Subsequent calls to read
only return bytes that have not been marked as read. Read moreSource§fn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left
)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>
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>
0xA
byte) is reached, and append
them to the provided String
buffer. Read moreSource§impl<F: Read + Seek> Read for SkippingBufReader<F>
impl<F: Read + Seek> Read for SkippingBufReader<F>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
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 more