File::Raw · File::Raw::Hash 0.07
File::Raw::Hash
Digests computed while the file is read or written.
A passthrough: the bytes flow on unchanged, and the digest lands where into points. SHA-256, SHA-512, SHA-1, MD5, BLAKE3, CRC32 and xxh64, several in one pass, bundled C with no library to install.
Registers hash
use File::Raw ();
use File::Raw::Hash;
# The bytes pass through; the digest lands where `into` points.
my $bytes = File::Raw::slurp('release.tar.gz',
plugin => 'hash', algo => 'sha256', into => \my $sha256);
# Several digests in one pass over the file.
my %sums;
File::Raw::slurp('release.tar.gz',
plugin => 'hash', algos => [qw(sha256 md5 crc32)], into => \%sums);
print "$sha256\n$sums{md5}\n";
What you get
-
A passthrough
The data is unchanged, and the digest lands in the scalar or hash
intopoints at. Reading a file and checking it is one pass, not two. -
SHA instructions, when the CPU has them
From 0.07, SHA-256 and SHA-1 run on the CPU's SHA instructions where it has them (ARMv8, Apple silicon included), chosen when the module loads, so one build runs everywhere.
implementation()says which code is in use, andFRH_PORTABLE=1keeps the portable C. -
Seven algorithms
sha256, sha512, sha1, md5, blake3, crc32 and xxh64, in bundled C: no OpenSSL, no library to install.
-
Several at once
algos => [qw(sha256 md5 crc32)]computes them all in the same pass. -
Streams and writes
With
each_linethe digest arrives when the loop ends, the file never whole in memory. Withspewit is the digest of what was written.
The numbers
Against the fastest alternative that was installed, and shown whichever way it went.
- 3.7x sha256 of a 64 MB file, against Digest::SHA File::Raw::Hash 0.07 at 25.6/s, Digest::SHA 6.04 at 6.9/s
- 1.0x md5 of a 64 MB file, against Digest::MD5 File::Raw::Hash 0.07 at 10.5/s, Digest::MD5 2.59 at 10.5/s
Measured on Apple M5, darwin with perl 5.42.0, 2026-10-19: each entry timed for 3 CPU seconds by the Benchmark module, 3 times, the median kept, after checking that both sides produced the same result. Every number.
For C
frh_abi.h gives other XS modules the digests, HMAC and the lockstep runner, resolved once through File::Raw::Hash::_abi_ptr. No Perl types cross it: handles are opaque and digests land in the caller's buffers.
Works with
Chains from its documentation: the plugins run left to right on a read, right to left on a write.
plugin => ['hash', 'gzip', 'json']with File::Raw::Gzip and File::Raw::JSON
The reference
- File::Raw::Hash Cryptographic and integrity digests as a File::Raw plugin