componenta/file-hasher

File hashing contract and default implementation

Maintainers

Package info

github.com/componenta/file-hasher

pkg:composer/componenta/file-hasher

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-17 00:51 UTC

This package is auto-updated.

Last update: 2026-06-17 15:43:58 UTC


README

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.