2N/Apackage Digest::file;
2N/A
2N/Ause strict;
2N/A
2N/Ause Exporter ();
2N/Ause Carp qw(croak);
2N/Ause Digest ();
2N/A
2N/Ause vars qw($VERSION @ISA @EXPORT_OK);
2N/A
2N/A$VERSION = "1.16";
2N/A@ISA = qw(Exporter);
2N/A@EXPORT_OK = qw(digest_file_ctx digest_file digest_file_hex digest_file_base64);
2N/A
2N/Asub digest_file_ctx {
2N/A my $file = shift;
2N/A croak("No digest algorithm specified") unless @_;
2N/A local *F;
2N/A open(F, "<", $file) || croak("Can't open '$file': $!");
2N/A binmode(F);
2N/A my $ctx = Digest->new(@_);
2N/A $ctx->addfile(*F);
2N/A close(F);
2N/A return $ctx;
2N/A}
2N/A
2N/Asub digest_file {
2N/A digest_file_ctx(@_)->digest;
2N/A}
2N/A
2N/Asub digest_file_hex {
2N/A digest_file_ctx(@_)->hexdigest;
2N/A}
2N/A
2N/Asub digest_file_base64 {
2N/A digest_file_ctx(@_)->b64digest;
2N/A}
2N/A
2N/A1;
2N/A
2N/A__END__
2N/A
2N/A=head1 NAME
2N/A
2N/ADigest::file - Calculate digests of files
2N/A
2N/A=head1 SYNOPSIS
2N/A
2N/A # Poor mans "md5sum" command
2N/A use Digest::file qw(digest_file_hex);
2N/A for (@ARGV) {
2N/A print digest_file_hex($_, "MD5"), " $_\n";
2N/A }
2N/A
2N/A=head1 DESCRIPTION
2N/A
2N/AThis module provide 3 convenience functions to calculate the digest
2N/Aof files. The following functions are provided:
2N/A
2N/A=over
2N/A
2N/A=item digest_file( $file, $algorithm, [$arg,...] )
2N/A
2N/AThis function will calculate and return the binary digest of the bytes
2N/Aof the given file. The function will croak if it fails to open or
2N/Aread the file.
2N/A
2N/AThe $algorithm is a string like "MD2", "MD5", "SHA-1", "SHA-512".
2N/AAdditional arguments are passed to the constructor for the
2N/Aimplementation of the given algorithm.
2N/A
2N/A=item digest_file_hex( $file, $algorithm, [$arg,...] )
2N/A
2N/ASame as digest_file(), but return the digest in hex form.
2N/A
2N/A=item digest_file_base64( $file, $algorithm, [$arg,...] )
2N/A
2N/ASame as digest_file(), but return the digest as a base64 encoded
2N/Astring.
2N/A
2N/A=back
2N/A
2N/A=head1 SEE ALSO
2N/A
2N/AL<Digest>