source: for-distributions/trunk/bin/windows/perl/lib/Digest/file.pm@ 14489

Last change on this file since 14489 was 14489, checked in by oranfry, 17 years ago

upgrading to perl 5.8

File size: 1.7 KB
Line 
1package Digest::file;
2
3use strict;
4
5use Exporter ();
6use Carp qw(croak);
7use Digest ();
8
9use vars qw($VERSION @ISA @EXPORT_OK);
10
11$VERSION = "1.00";
12@ISA = qw(Exporter);
13@EXPORT_OK = qw(digest_file_ctx digest_file digest_file_hex digest_file_base64);
14
15sub digest_file_ctx {
16 my $file = shift;
17 croak("No digest algorithm specified") unless @_;
18 local *F;
19 open(F, $file) || croak("Can't open '$file': $!");
20 binmode(F);
21 my $ctx = Digest->new(@_);
22 $ctx->addfile(*F);
23 close(F);
24 return $ctx;
25}
26
27sub digest_file {
28 digest_file_ctx(@_)->digest;
29}
30
31sub digest_file_hex {
32 digest_file_ctx(@_)->hexdigest;
33}
34
35sub digest_file_base64 {
36 digest_file_ctx(@_)->b64digest;
37}
38
391;
40
41__END__
42
43=head1 NAME
44
45Digest::file - Calculate digests of files
46
47=head1 SYNOPSIS
48
49 # Poor mans "md5sum" command
50 use Digest::file qw(digest_file_hex);
51 for (@ARGV) {
52 print digest_file_hex($_, "MD5"), " $_\n";
53 }
54
55=head1 DESCRIPTION
56
57This module provide 3 convenience functions to calculate the digest
58of files. The following functions are provided:
59
60=over
61
62=item digest_file( $file, $algorithm, [$arg,...] )
63
64This function will calculate and return the binary digest of the bytes
65of the given file. The function will croak if it fails to open or
66read the file.
67
68The $algorithm is a string like "MD2", "MD5", "SHA-1", "SHA-512".
69Additional arguments are passed to the constructor for the
70implementation of the given algorithm.
71
72=item digest_file_hex( $file, $algorithm, [$arg,...] )
73
74Same as digest_file(), but return the digest in hex form.
75
76=item digest_file_base64( $file, $algorithm, [$arg,...] )
77
78Same as digest_file(), but return the digest as a base64 encoded
79string.
80
81=back
82
83=head1 SEE ALSO
84
85L<Digest>
Note: See TracBrowser for help on using the repository browser.