Struct s4lib::readers::blockreader::BlockReader
source · pub struct BlockReader { /* private fields */ }
Expand description
A BlockReader
reads a file in BlockSz
byte-sized Block
s. It
interfaces with the filesystem. It handles reading from specialized
storage files like
compressed files (e.g. .gz
, .xz
) and archive files (e.g .tar
).
BlockReader
handles the run-time in-memory storage the Block
s of data
it reads.
A BlockReader
uses the passed FileType
to determine how to handle
files.
This includes reading bytes from files (e.g. .log
),
compressed files (e.g. .gz
, .xz
), and archive files (e.g. .tar
).
One BlockReader
corresponds to one file. For archive files and
compressed files, one BlockReader
handles only one file within
the archive or compressed file.
A BlockReader
does not know about char
s, only bytes u8
.
XXX: not a rust “Reader”; does not implement trait Read
.
Implementations§
source§impl BlockReader
impl BlockReader
Implements the BlockReader
.
sourcepub fn new(
path: FPath,
filetype: FileType,
blocksz_: BlockSz
) -> Result<BlockReader>
pub fn new( path: FPath, filetype: FileType, blocksz_: BlockSz ) -> Result<BlockReader>
Create a new BlockReader
.
Opens the file at path
. Configures settings based on passed
filetype
.
NOTE: Dissimilar to other *Readers::new
, this new
function may
read some bytes from the file, e.g. gzip header, e.g. tar header, to
determine the file type and set other initial values.
sourcepub const fn filesz(&self) -> FileSz
pub const fn filesz(&self) -> FileSz
Return the file size in bytes.
For compressed or archived files, returns the original file size (uncompressed or unarchived) as found in the header.
An exception is .xz
files, which are entirely read during function
new
, and the file size determined from the uncompressed bytes.
See Issue #12.
For plain files, returns the file size reported by the filesystem.
Users of this struct should always use this instead of accessing
self.filesz
or self.filesz_actual
directly.
sourcepub const fn filetype(&self) -> FileType
pub const fn filetype(&self) -> FileType
Return a copy of self.filetype
. The FileType
enum determines
various behaviors around opening and reading from the file.
sourcepub fn mtime(&self) -> SystemTime
pub fn mtime(&self) -> SystemTime
Get the best available “Modified Datetime” file attribute available.
For compressed or archived files, use the copied header-embedded “MTIME”. If the embedded “MTIME” is not available then return the encompassing file’s “MTIME”.
For example, if archived file syslog
within archive logs.tar
does
not have a valid “MTIME”, then return the file system attribute
“modified time” for logs.tar
.
sourcepub const fn block_offset_at_file_offset(
fileoffset: FileOffset,
blocksz: BlockSz
) -> BlockOffset
pub const fn block_offset_at_file_offset( fileoffset: FileOffset, blocksz: BlockSz ) -> BlockOffset
Return nearest preceding BlockOffset
for given FileOffset
.
sourcepub const fn file_offset_at_block_offset(
blockoffset: BlockOffset,
blocksz: BlockSz
) -> FileOffset
pub const fn file_offset_at_block_offset( blockoffset: BlockOffset, blocksz: BlockSz ) -> FileOffset
sourcepub const fn file_offset_at_block_offset_self(
&self,
blockoffset: BlockOffset
) -> FileOffset
pub const fn file_offset_at_block_offset_self( &self, blockoffset: BlockOffset ) -> FileOffset
Return FileOffset
(byte offset) at given BlockOffset
.
sourcepub const fn file_offset_at_block_offset_index(
blockoffset: BlockOffset,
blocksz: BlockSz,
blockindex: BlockIndex
) -> FileOffset
pub const fn file_offset_at_block_offset_index( blockoffset: BlockOffset, blocksz: BlockSz, blockindex: BlockIndex ) -> FileOffset
Return FileOffset
(byte offset) at BlockOffset
+ BlockIndex
.
sourcepub const fn fileoffset_last(&self) -> FileOffset
pub const fn fileoffset_last(&self) -> FileOffset
Get the last byte FileOffset
(index) of the file (inclusive).
sourcepub const fn block_index_at_file_offset(
fileoffset: FileOffset,
blocksz: BlockSz
) -> BlockIndex
pub const fn block_index_at_file_offset( fileoffset: FileOffset, blocksz: BlockSz ) -> BlockIndex
Return BlockIndex
(byte offset into a Block
) for the Block
that
corresponds to the passed FileOffset
.
sourcepub const fn block_index_at_file_offset_self(
&self,
fileoffset: FileOffset
) -> BlockIndex
pub const fn block_index_at_file_offset_self( &self, fileoffset: FileOffset ) -> BlockIndex
Return BlockIndex
(byte offset into a Block
) for the Block
that
corresponds to the passed FileOffset
.
sourcepub const fn count_blocks(filesz: FileSz, blocksz: BlockSz) -> Count
pub const fn count_blocks(filesz: FileSz, blocksz: BlockSz) -> Count
Return Count
of Block
s in a file.
Equivalent to the last BlockOffset
+ 1.
Not a count of Block
s that have been read; the calculated
count of Block
s based on the FileSz
.
sourcepub fn blocksz_at_blockoffset(&self, blockoffset: &BlockOffset) -> BlockSz
pub fn blocksz_at_blockoffset(&self, blockoffset: &BlockOffset) -> BlockSz
Specific BlockSz
(size in bytes) of block at BlockOffset
.
This should be self.blocksz
for all Block
s except the last, which
should be >0
and <=self.blocksz
sourcepub fn last_blockindex_at_blockoffset(
&self,
blockoffset: &BlockOffset
) -> BlockIndex
pub fn last_blockindex_at_blockoffset( &self, blockoffset: &BlockOffset ) -> BlockIndex
Return last valid BlockIndex
for block at the BlockOffset
.
sourcepub const fn blockoffset_last(&self) -> BlockOffset
pub const fn blockoffset_last(&self) -> BlockOffset
The last valid BlockOffset
for the file (inclusive).
In other words, expected largest BlockOffset
value for the file.
Independent of Block
s that have been processed.
sourcepub fn count_blocks_processed(&self) -> Count
pub fn count_blocks_processed(&self) -> Count
Count
of blocks read by this BlockReader
.
Not always the same as blocks currently stored (those may be drop
ped
during streaming stage).
sourcepub fn count_bytes(&self) -> Count
pub fn count_bytes(&self) -> Count
Count
of bytes stored by this BlockReader
.
sourcepub fn LRU_cache_enable(&mut self)
pub fn LRU_cache_enable(&mut self)
Enable internal LRU cache used by read_block
.
sourcepub fn LRU_cache_disable(&mut self)
pub fn LRU_cache_disable(&mut self)
Disable internal LRU cache used by read_block
.
sourcepub const fn is_streamed_file(&self) -> bool
pub const fn is_streamed_file(&self) -> bool
Is the current file a “streaming” file? i.e. must the file be read in a linear manner starting from the first byte? Compressed files must be read in this manner.
If true
then it is presumed calls to read_block_File
will
always be in sequential (linear) manner; i.e. only increasing values of
the passed blockoffset
.
If false
then no presumptions are made about the value of
blockoffset
passed to read_block_File
.
sourcepub fn drop_block(&mut self, blockoffset: BlockOffset) -> bool
pub fn drop_block(&mut self, blockoffset: BlockOffset) -> bool
Proactively drop
the Block
at BlockOffset
.
For “streaming stage”.
The caller must know what they are doing!
sourcepub fn read_block(&mut self, blockoffset: BlockOffset) -> ResultS3ReadBlock
pub fn read_block(&mut self, blockoffset: BlockOffset) -> ResultS3ReadBlock
Read a Block
of data of max size self.blocksz
from the file.
A successful read returns Found(BlockP)
.
When at or past the end of the file and no data was read, returns
Done
.
All other File
and std::io
errors are propagated to the caller
in Err
.
sourcepub fn read_data_to_buffer(
&mut self,
fileoffset_beg: FileOffset,
fileoffset_end: FileOffset,
oneblock: bool,
buffer: &mut [u8]
) -> ResultReadDataToBuffer
pub fn read_data_to_buffer( &mut self, fileoffset_beg: FileOffset, fileoffset_end: FileOffset, oneblock: bool, buffer: &mut [u8] ) -> ResultReadDataToBuffer
Read data from the file into the passed buffer
. Calls private
function read_data
.
When successful, Found
contains number of bytes read into the passed
buffer
.
Data is read inclusive of fileoffset_beg
and exclusive of
fileoffset_end
.
Argument oneblock
is passed to read_data
.
pub fn summary(&self) -> SummaryBlockReader
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BlockReader
impl !RefUnwindSafe for BlockReader
impl Send for BlockReader
impl Sync for BlockReader
impl Unpin for BlockReader
impl !UnwindSafe for BlockReader
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more