Struct file_rw::FileReader
source · pub struct FileReader { /* private fields */ }Expand description
The FileReader struct represents a file reader that provides high-performance file reading capabilities. It uses memory mapping for efficient access to file data.
Implementations§
source§impl FileReader
impl FileReader
sourcepub fn open_file(file: &File) -> Self
pub fn open_file(file: &File) -> Self
Opens a file and returns a FileReader for it. The file is identified by its File object.
sourcepub fn open(path: impl AsRef<Path> + Send + Sync) -> Self
pub fn open(path: impl AsRef<Path> + Send + Sync) -> Self
Opens a file and returns a FileReader for it. The file is identified by its path.
sourcepub fn read_to_string(&self) -> String
pub fn read_to_string(&self) -> String
Reads the entire file to a string.
sourcepub fn to_writer(&self) -> FileWriter
pub fn to_writer(&self) -> FileWriter
Opens the file for writing and returns a FileWriter for it.
sourcepub fn hash_with<H: Digest>(&self) -> Output<H>
pub fn hash_with<H: Digest>(&self) -> Output<H>
Computes the hash of the file data using a given hash function.
sourcepub fn hash_to_string(&self) -> String
pub fn hash_to_string(&self) -> String
Computes the hash of the file data and returns it as a hex string.
sourcepub fn find_bytes(&self, bytes: &impl AsRef<[u8]>) -> Option<usize>
pub fn find_bytes(&self, bytes: &impl AsRef<[u8]>) -> Option<usize>
Finds the first occurrence of a byte sequence in the file data.
It takes a byte sequence bytes and returns the index of the first occurrence.
If the byte sequence is not found, it returns None.
sourcepub fn rfind_bytes(&self, bytes: &impl AsRef<[u8]>) -> Option<usize>
pub fn rfind_bytes(&self, bytes: &impl AsRef<[u8]>) -> Option<usize>
Finds the last occurrence of a byte sequence in the file data.
It takes a byte sequence bytes and returns the index of the last occurrence.
If the byte sequence is not found, it returns None.
sourcepub fn find_bytes_all(&self, bytes: &impl AsRef<[u8]>) -> Vec<usize>
pub fn find_bytes_all(&self, bytes: &impl AsRef<[u8]>) -> Vec<usize>
Finds all occurrences of a byte sequence in the file data.
It takes a byte sequence bytes and returns a vector of indices where the byte sequence is found.
sourcepub fn find_bytes_nth(
&self,
bytes: &impl AsRef<[u8]>,
n: usize
) -> Option<usize>
pub fn find_bytes_nth( &self, bytes: &impl AsRef<[u8]>, n: usize ) -> Option<usize>
Finds the nth occurrence of a byte sequence in the file data.
It takes a byte sequence bytes and an index n, and returns the index of the nth occurrence.
If the byte sequence is not found, it returns None.
sourcepub fn compare_files(
file_path1: impl AsRef<Path> + Send + Sync,
file_path2: impl AsRef<Path> + Send + Sync
) -> bool
pub fn compare_files( file_path1: impl AsRef<Path> + Send + Sync, file_path2: impl AsRef<Path> + Send + Sync ) -> bool
Compares two files by their hashes.
It takes two file paths file_path1 and file_path2, and returns true if the files are identical (based on their hashes), false otherwise.
sourcepub fn compare_to(&self, file_path: impl AsRef<Path> + Send + Sync) -> bool
pub fn compare_to(&self, file_path: impl AsRef<Path> + Send + Sync) -> bool
Compares the FileReader’s file to another file by their hashes.
It takes a file path file_path, and returns true if the files are identical (based on their hashes), false otherwise.
sourcepub fn compare_to_file(&self, file: &File) -> bool
pub fn compare_to_file(&self, file: &File) -> bool
Compares the FileReader’s file to another file by their hashes.
It takes a File object file, and returns true if the files are identical (based on their hashes), false otherwise.
sourcepub fn compare_hash<T: Digest>(&self, hash: &Output<T>) -> bool
pub fn compare_hash<T: Digest>(&self, hash: &Output<T>) -> bool
Compares the hash of the FileReader’s file to a given hash.
It takes a hash hash, and returns true if the hash of the file is identical to the given hash, false otherwise.
Trait Implementations§
source§impl Debug for FileReader
impl Debug for FileReader
source§impl Display for FileReader
impl Display for FileReader
source§impl IntoIterator for FileReader
impl IntoIterator for FileReader
source§impl IntoParallelIterator for FileReader
impl IntoParallelIterator for FileReader
source§fn into_par_iter(self) -> Self::Iter
fn into_par_iter(self) -> Self::Iter
Converts the FileReader into a parallel iterator over the bytes of the file data.