componenta/hasher

Stream-aware content hashing contract and default implementation

Maintainers

Package info

github.com/componenta/hasher

pkg:composer/componenta/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:59 UTC


README

Stream-aware content hashing contract and default implementation.

Use this package when services need to hash either an in-memory string or a PSR-7 stream through one small abstraction.

Installation

composer require componenta/hasher

Usage

use Componenta\Stdlib\Hasher;

$hasher = new Hasher('sha256');

$hash = $hasher->hash('content');
$sha1 = $hasher->withAlgorithm('sha1');

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

$hasher->algorithm; // sha256

withAlgorithm() returns a new immutable instance.

Contract

use Psr\Http\Message\StreamInterface;

interface HasherInterface
{
    public function hash(string|StreamInterface $input): string;
}

When a stream is passed, the default implementation rewinds the stream before hashing and rewinds it again after hashing. This lets callers pass the same stream to storage after computing its digest.

Related Packages

Package Why it matters here
componenta/file-hasher Hashes files by filename.
componenta/password Hashes passwords with PHP's dedicated password API.