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.

Σύνοψη#

open my $fh, "<", "notes.txt" or die $!;
$sha->_addfileuniv($fh);

Τι επιστρέφεται#

The receiver, for chaining.

Παραδείγματα#

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");

Οριακές περιπτώσεις#

  • On Linux, newline translation is inactive; the digest matches _addfilebin on the same file.

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

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

Διαφορές από το upstream#

Fully compatible with upstream Digest::SHA 6.04.

Δείτε επίσης#

  • addfile - mode-switching wrapper; prefer it in application code.

  • _addfilebin - byte-exact binary counterpart.

  • add_bits - sub-byte input path for bit-oriented hashing.