dump#

Write the current Digest::SHA state to a file or STDOUT in text form.

With a filename argument, writes the text produced by getstate to that file, truncating it if it exists. Without an argument, prints the same text to STDOUT. The companion load method reads it back.

Synopsis#

$sha->dump("hash.state");
$sha->dump;                   # to STDOUT

What you get back#

The receiver on success (truthy), undef on I/O failure.

Examples#

my $sha = Digest::SHA->new(256);
$sha->add("partial");
$sha->dump("checkpoint.state");
# ... later, perhaps in another process ...
my $resumed = Digest::SHA->load("checkpoint.state");
$resumed->add("tail");
print $resumed->hexdigest;
# Debug-dump to the terminal:
$sha->dump;
# Check the return value for I/O errors:
defined $sha->dump("/nonexistent/path/file")
    or warn "could not write state";

Edge cases#

  • An unwritable path returns undef rather than croaking.

  • Called on something that is not a Digest::SHA object, dies with Can't locate object method or Can't call method.

Differences from upstream#

Fully compatible with upstream Digest::SHA 6.04.

See also#

  • load - counterpart that reads the file dump produces.

  • getstate - underlying text-state producer.

  • putstate - text-state ingester.