pub struct Seeker<R> { /* private fields */ }Expand description
A specialized CSV stream seeker.
Implementations§
Source§impl<R: Read + Seek> Seeker<R>
impl<R: Read + Seek> Seeker<R>
Sourcepub fn has_headers(&self) -> bool
pub fn has_headers(&self) -> bool
Returns whether this seeker has been configured to interpret the first record as a header.
Sourcepub fn initial_position(&self) -> u64
pub fn initial_position(&self) -> u64
Returns the position the seekable stream was in when instantiating the seeker.
Sourcepub fn first_record_position(&self) -> u64
pub fn first_record_position(&self) -> u64
Returns the absolute byte offset of the first record (excluding header) of the seekable stream.
Sourcepub fn stream_len(&self) -> u64
pub fn stream_len(&self) -> u64
Returns the total number of bytes contained in the seekable stream.
Sourcepub fn lookahead_len(&self) -> u64
pub fn lookahead_len(&self) -> u64
Returns the number of bytes that will be read when performing a
lookahead in the seekable stream when using
Seeker::find_record_after.
Sourcepub fn range(&self) -> Range<u64>
pub fn range(&self) -> Range<u64>
Returns the first_record_position..stream_len range of the seeker.
Sourcepub fn exact_count(&self) -> Option<u64>
pub fn exact_count(&self) -> Option<u64>
Returns the exact number of records (header excluded) contained in the seekable stream, if the initial sample built when instantiating the seeker exhausted the whole stream.
Sourcepub fn approx_count(&self) -> u64
pub fn approx_count(&self) -> u64
Either returns the exact number of records (header excluded) contained in the seekable stream or an approximation based on statistics sampled from the beginning of the stream and the total stream length.
Sourcepub fn find_record_after(
&mut self,
from_pos: u64,
) -> Result<Option<(u64, ByteRecord)>>
pub fn find_record_after( &mut self, from_pos: u64, ) -> Result<Option<(u64, ByteRecord)>>
Attempt to find the position, in the seekable stream, of the beginning
of the CSV record just after the one where from_pos would end in.
Beware: if from_pos is the exact first byte of a CSV record, this
method will still return the position of next CSV record because it has
no way of knowing whether the byte just before from_pos is a newline.
This method will return an error if given from_pos is out of bounds.
This method will return None if it did not succeed in finding the
next CSV record starting position. This can typically happen when
seeking too close to the end of the stream, since this method needs to
read ahead of the stream to test its heuristics.
match seeker.find_record_after(1024) {
Ok(Some((pos, record))) => {
// Everything went fine
},
Ok(None) => {
// Lookahead failed
},
Err(err) => {
// Either `from_pos` was out-of-bounds, or some IO error occurred
}
}Sourcepub fn segments(&mut self, count: usize) -> Result<Vec<(u64, u64)>>
pub fn segments(&mut self, count: usize) -> Result<Vec<(u64, u64)>>
Split the seekable stream into a maximum of count segments.
This method might return less than count segments if the stream
seems too small to safely return that many segments.
Sourcepub fn byte_headers(&self) -> &ByteRecord
pub fn byte_headers(&self) -> &ByteRecord
Returns the headers of the seekable stream, or just the first record the seeker was configured thusly.
Sourcepub fn first_byte_record(&mut self) -> Result<Option<ByteRecord>>
pub fn first_byte_record(&mut self) -> Result<Option<ByteRecord>>
Attempt to read the first record of the seekable stream.
Sourcepub fn last_byte_record(&mut self) -> Result<Option<ByteRecord>>
pub fn last_byte_record(&mut self) -> Result<Option<ByteRecord>>
Attempt to read the last record of the seekable stream by reading it in reverse.
Sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Returns the underlying reader without unwinding its position.
Sourcepub fn into_zero_copy_reader(self) -> Result<ZeroCopyReader<R>>
pub fn into_zero_copy_reader(self) -> Result<ZeroCopyReader<R>>
Transform the seeker into a ZeroCopyReader. Underlying reader will
be correctly reset to the stream initial position beforehand.
Sourcepub fn into_splitter(self) -> Result<Splitter<R>>
pub fn into_splitter(self) -> Result<Splitter<R>>
Transform the seeker into a Splitter. Underlying reader will
be correctly reset to the stream initial position beforehand.