load#

Construct a Digest::SHA object from a text state file written by dump.

Reads the file, parses its contents as a text state string, and returns a new object with the algorithm and internal state recorded in the file. Typically called as a class method, but works as an instance method too (the receiver is ignored; a fresh object is always returned).

Σύνοψη#

my $sha = Digest::SHA->load("hash.state");

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

A Digest::SHA object on success, undef if the file could not be read or the contents could not be parsed.

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

my $sha = Digest::SHA->new(256);
$sha->add("one");
$sha->dump("hash.state");

my $resumed = Digest::SHA->load("hash.state");
$resumed->add("two");
print $resumed->hexdigest;

## same as Digest::SHA->new(256)->add("one")->add("two")->hexdigest
## Missing file returns undef rather than croaking:

my $sha = Digest::SHA->load("/does/not/exist");
print defined $sha ? "ok" : "undef"; # undef
## Works as an instance method too (but still returns a fresh object):

my $dummy = Digest::SHA->new(1);
my $sha = $dummy->load("hash.state");

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

  • I/O failure or a parse error returns undef.

  • The returned object’s algorithm comes from the file, not from any receiver - the receiver is essentially a namespace hook.

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

Fully compatible with upstream Digest::SHA 6.04.

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

  • dump - writes the file load reads.

  • putstate - parses the text state directly from a string.

  • _putstate - binary-state counterpart.