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

source

pub fn open_file(file: &File) -> Self

Opens a file and returns a FileReader for it. The file is identified by its File object.

source

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.

source

pub fn read_to_string(&self) -> String

Reads the entire file to a string.

source

pub fn bytes(&self) -> &[u8]

Returns a slice of bytes representing the file data.

source

pub fn to_vec(&self) -> Vec<u8>

Returns a vector of bytes representing the file data.

source

pub fn file(&self) -> File

Opens the file for reading and returns the File object.

source

pub fn mmap(&self) -> &Box<Mmap>

Returns the memory-mapped file.

source

pub fn path(&self) -> &Path

Returns the path of the file.

source

pub fn to_writer(&self) -> FileWriter

Opens the file for writing and returns a FileWriter for it.

source

pub fn hash_with<H: Digest>(&self) -> Output<H>

Computes the hash of the file data using a given hash function.

source

pub fn hash(&self) -> Output<Sha3_256>

Computes the SHA3-256 hash of the file data.

source

pub fn hash_to_string(&self) -> String

Computes the hash of the file data and returns it as a hex string.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Displays the path of the file.

source§

impl Display for FileReader

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Displays the path of the file.

source§

impl IntoIterator for FileReader

source§

fn into_iter(self) -> Self::IntoIter

Converts the FileReader into an iterator over the bytes of the file data.

§

type Item = u8

The type of the elements being iterated over.
§

type IntoIter = IntoIter<<FileReader as IntoIterator>::Item>

Which kind of iterator are we turning this into?
source§

impl IntoParallelIterator for FileReader

source§

fn into_par_iter(self) -> Self::Iter

Converts the FileReader into a parallel iterator over the bytes of the file data.

§

type Item = u8

The type of item that the parallel iterator will produce.
§

type Iter = IntoIter<<FileReader as IntoParallelIterator>::Item>

The parallel iterator type that will be created.
source§

impl PartialEq for FileReader

source§

fn eq(&self, other: &Self) -> bool

Compares two FileReader instances for equality based on their hashes.

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.