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.

תקציר#

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

מה מוחזר#

The receiver, for chaining.

דוגמאות#

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

מקרי קצה#

  • 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.

הבדלים מן ה-upstream#

Fully compatible with upstream Digest::SHA 6.04.

ראו גם#

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

  • _addfileuniv - universal-newline counterpart.

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