addfilebin#

Feed the raw byte contents of a filehandle into a Digest::SHA object.

The binary-mode backend behind addfile. Reads until end of file with no newline translation and no character interpretation — exactly what you want when hashing a file whose bytes must be preserved literally (archives, images, compiled artefacts).

Normally you use addfile with an explicit "b" mode; _addfilebin is the leading-underscore XS hook, exposed here for completeness.

Synopsis#

open my $fh, "<:raw", "archive.tar.gz" or die $!;
$sha->_addfilebin($fh);

What you get back#

The receiver, for chaining.

Examples#

open my $fh, "<:raw", "data.bin" or die $!;
my $sha = Digest::SHA->new(256);
$sha->_addfilebin($fh);
print $sha->hexdigest;
my $sha = Digest::SHA->new(512);
$sha->_addfilebin("path/to/file");   # also accepts filenames

Edge cases#

  • A bad filehandle or unreadable filename croaks with Bad filehandle: ....

  • An empty file leaves the hash state untouched.

  • Called on a non-Digest::SHA object, returns undef.

Differences from upstream#

Fully compatible with upstream Digest::SHA 6.04.

See also#

  • addfile — the public, mode-switching wrapper; prefer it in new code.

  • _addfileuniv — universal-newline counterpart.

  • add — string-oriented input for data already in memory.