Skip to main content

HashComputer

Struct HashComputer 

Source
pub struct HashComputer { /* private fields */ }
Expand description

Hash computer with streaming I/O

Implementations§

Source§

impl HashComputer

Source

pub fn compute_hash( &self, path: &Path, algorithm: &str, ) -> Result<HashResult, HashUtilityError>

Compute hash for a single file using streaming I/O or memory mapping

Uses buffered I/O for small files and memory mapping for larger files on 64-bit targets. 32-bit targets cap mappings at 2 GiB.

§Safety

Memory mapping assumes the file will not be modified by other processes during hashing. If the file is modified concurrently, the hash result may be inconsistent. This is acceptable for typical use cases where files are not being actively modified.

Source

pub fn compute_hash_with_progress( &self, path: &Path, algorithm: &str, show_progress: bool, ) -> Result<HashResult, HashUtilityError>

Compute hash for a single file with optional progress bar

If show_progress is true and the file is larger than 1GB and stdout is a TTY, displays a progress bar that updates 10 times per second.

Source

pub fn compute_hash_fast( &self, path: &Path, algorithm: &str, ) -> Result<HashResult, HashUtilityError>

Compute hash for a file using fast mode (sampling strategy)

For files larger than 300MB, samples three 100MB regions:

  • First 100MB
  • Middle 100MB (centered at file_size/2)
  • Last 100MB

For files smaller than 300MB, uses the full file.

Source§

impl HashComputer

Source

pub fn new() -> Self

Create a new HashComputer with default buffer size (1MB)

Source

pub fn with_buffer_size(buffer_size: usize) -> Self

Create a new HashComputer with custom buffer size

Source

pub fn buffer_size(&self) -> usize

Return the buffer size

Source

pub fn compute_hash_text( &self, text: &str, algorithm: &str, ) -> Result<HashResult, HashUtilityError>

Compute hash from text string

Source

pub fn compute_multiple_hashes_text( &self, text: &str, algorithms: &[String], ) -> Result<Vec<HashResult>, HashUtilityError>

Compute multiple hashes from text string in a single pass

Source

pub fn compute_hash_stdin( &self, algorithm: &str, ) -> Result<HashResult, HashUtilityError>

Compute hash from stdin using streaming I/O

Source

pub fn compute_multiple_hashes_stdin( &self, algorithms: &[String], ) -> Result<Vec<HashResult>, HashUtilityError>

Compute multiple hashes from stdin in a single pass

Source

pub fn compute_multiple_hashes( &self, path: &Path, algorithms: &[String], ) -> Result<Vec<HashResult>, HashUtilityError>

Compute multiple hashes for a single file in a single pass

Uses buffered I/O for small files and memory mapping for larger files on 64-bit targets. 32-bit targets cap mappings at 2 GiB.

§Safety

Memory mapping assumes the file will not be modified by other processes during hashing. If the file is modified concurrently, the hash results may be inconsistent.

Source

pub fn compute_multiple_hashes_with_progress( &self, path: &Path, algorithms: &[String], show_progress: bool, ) -> Result<Vec<HashResult>, HashUtilityError>

Compute multiple hashes for a single file with optional progress bar

If show_progress is true and the file is larger than 1GB and stdout is a TTY, displays a progress bar that updates 10 times per second.

Trait Implementations§

Source§

impl Default for HashComputer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.