addfileuniv#
Feed a filehandle’s contents into a Digest::SHA object, reading through the PerlIO text layer.
The universal-newline backend behind addfile. On platforms where Perl
performs CR/LF conversion on text streams, this mode reads the file
through that conversion so the hash is platform-agnostic. On Linux the
PerlIO text layer is a no-op, so on this platform _addfileuniv and
_addfilebin produce identical digests.
Prefer the public addfile($fh, "U") or addfile($fh, "p") wrapper in
application code.
Synopsis#
open my $fh, "<", "notes.txt" or die $!;
$sha->_addfileuniv($fh);
What you get back#
The receiver, for chaining.
Examples#
my $sha = Digest::SHA->new(256);
open my $fh, "<", "README" or die $!;
$sha->_addfileuniv($fh);
print $sha->hexdigest;
## Portable digest of a text file shared between Unix and Windows:
my $sha = Digest::SHA->new(256);
$sha->_addfileuniv("config.ini");
Edge cases#
On Linux, newline translation is inactive; the digest matches
_addfilebinon the same file.A bad filehandle or unreadable filename croaks with
Bad filehandle: ....Called on a non-
Digest::SHAobject, returnsundef.
Differences from upstream#
Fully compatible with upstream Digest::SHA 6.04.
See also#
addfile— mode-switching wrapper; prefer it in application code._addfilebin— byte-exact binary counterpart.add_bits— sub-byte input path for bit-oriented hashing.