Skip to content

componenta/file-hasher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Componenta File Hasher

File hashing contract and default implementation.

Use this package when a service needs to hash a file by filename and receive file-specific exceptions for invalid paths.

Installation

composer require componenta/file-hasher

Usage

use Componenta\Stdlib\FileHasher;

$hasher = new FileHasher('sha256');

$hash = $hasher->hashFile(__DIR__ . '/document.pdf');
$sha1 = $hasher->withAlgorithm('sha1');

FileHasher exposes the selected algorithm as read-only public state:

$hasher->algorithm; // sha256

withAlgorithm() returns a new immutable instance.

Contract

interface FileHasherInterface
{
    public function hashFile(string $filename): string;
}

Exceptions

All package exceptions are named with a File* prefix and implement FileHasherExceptionInterface.

Exception When it is thrown
FileNotFoundException The path does not exist.
FileNotReadableException The path exists but is not a readable regular file.
FileHashFailedException PHP failed to compute the file hash.

Related Packages

Package Why it matters here
componenta/hasher Hashes strings and PSR-7 streams.
componenta/password Hashes passwords with PHP's dedicated password API.

About

File hashing contract and default implementation

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages