1File(3)               User Contributed Perl Documentation              File(3)
2
3
4

NAME

6       Digest::MD5::File - Perl extension for getting MD5 sums for files and
7       urls.
8

SYNOPSIS

10           use Digest::MD5::File qw(dir_md5_hex file_md5_hex url_md5_hex);
11
12           my $md5 = Digest::MD5->new;
13           $md5->addpath('/path/to/file');
14           my $digest = $md5->hexdigest;
15
16           my $digest = file_md5($file);
17           my $digest = file_md5_hex($file);
18           my $digest = file_md5_base64($file);
19
20           my $md5 = Digest::MD5->new;
21           $md5->addurl('http://www.tmbg.com/tour.html');
22           my $digest = $md5->hexdigest;
23
24           my $digest = url_md5($url);
25           my $digest = url_md5_hex($url);
26           my $digest = url_md5_base64($url);
27
28           my $md5 = Digest::MD5->new;
29           $md5->adddir('/directory');
30           my $digest = $md5->hexdigest;
31
32           my $dir_hashref = dir_md5($dir);
33           my $dir_hashref = dir_md5_hex($dir);
34           my $dir_hashref = dir_md5_base64($dir);
35

DESCRIPTION

37         Get MD5 sums for files of a given path or content of a given url.
38

EXPORT

40       None by default.  You can export any file_* dir_*, or url_* function
41       and anything Digest::MD5 can export.
42
43          use Digest::MD5::File qw(md5 md5_hex md5_base64); # 3 Digest::MD5 functions
44          print md5_hex('abc123'), "\n";
45          print md5_base64('abc123'), "\n";
46

OBJECT METHODS

48   addpath()
49           my $md5 = Digest::MD5->new;
50           $md5->addpath('/path/to/file.txt')
51               or die "file.txt is not where you said: $!";
52
53       or you can add multiple files by specifying an array ref of files:
54
55           $md5->addpath(\@files);
56
57   adddir()
58       addpath()s each file in a directory recursively. Follows the same rules
59       as the dir_* functions.
60
61           my $md5 = Digest::MD5->new;
62           $md5->adddir('/home/tmbg/')
63               or die "See warning above to see why I bailed: $!";
64
65   addurl()
66           my $md5 = Digest::MD5->new;
67           $md5->addurl('http://www.tmbg.com/tour.html')
68               or die "They Must Be not on tour";
69

file_* functions

71       Get the digest in variouse formats of $file.  If file does not exist or
72       is a directory it croaks (See NOFATALS for more info)
73
74           my $digest = file_md5($file) or warn "$file failed: $!";
75           my $digest = file_md5_hex($file) or warn "$file failed: $!";
76           my $digest = file_md5_base64($file) or warn "$file failed: $!";
77

dir_* functions

79       Returns a hashref whose keys are files relative to the given path and
80       the values are the MD5 sum of the file or and empty string if a
81       directory.  It recurses through the entire depth of the directory.
82       Symlinks to files are just addpath()d and symlinks to directories are
83       followed.
84
85           my $dir_hashref = dir_md5($dir) or warn "$dir failed: $!";
86           my $dir_hashref = dir_md5_hex($dir) or warn "$dir failed: $!";
87           my $dir_hashref = dir_md5_base64($dir) or warn "$dir failed: $!";
88

url_* functions

90       Get the digest in various formats of the content at $url (Including, if
91       $url points to directory, the directory listing content).  Returns
92       undef if url fails (IE if LWP::UserAgent's $res->is_success is false)
93
94           my $digest = url_md5($url) or warn "$url failed";
95           my $digest = url_md5_hex($url) or warn "$url failed";
96           my $digest = url_md5_base64($url) or warn "$url failed";
97

SPECIAL SETTINGS

99   BINMODE
100       By default files are opened in binmode. If you do not want to do this
101       you can unset it a variety of ways:
102
103           use Digest::MD5::File qw(-nobin);
104
105       or
106
107           $Digest::MD5::File::BINMODE = 0;
108
109       or at the function/method level by specifying its value as the second
110       argument:
111
112           $md5->addpath($file,0);
113
114           my $digest = file_md5_hex($file,0);
115
116   UTF8
117       In some cases you may want to have your data utf8 encoded, you can do
118       this the following ways:
119
120           use Digest::MD5::File qw(-utf8);
121
122       or
123
124           $Digest::MD5::File::UTF8 = 1;
125
126       or at the function/method level by specifying its value as the third
127       argument for files and second for urls:
128
129           $md5->addpath($file,$binmode,1);
130
131           my $digest = file_md5_hex($file,$binmode,1);
132
133           $md5->addurl($url,1);
134
135           url_md5_hex($url,1);
136
137       It use's Encode's encode_utf8() function to do the encoding. So if you
138       do not have Encode (pre 5.7.3) this won't work :)
139
140   NOFATALS
141       Instead of croaking it will return undef if you set NOFATALS to true.
142
143       You can do this two ways:
144
145           $Digest::MD5::File::NOFATALS = 1;
146
147       or the -nofatals flag:
148
149           use Digest::MD5::File qw(-nofatals);
150
151           my $digest = file_md5_hex($file) or die "$file failed";
152
153       $! is not set so its not really helpful if you die().
154

SEE ALSO

156       Digest::MD5, Encode, LWP::UserAgent
157

AUTHOR

159       Daniel Muey, <http://drmuey.com/cpan_contact.pl>
160
162       Copyright 2005 by Daniel Muey
163
164       This library is free software; you can redistribute it and/or modify it
165       under the same terms as Perl itself.
166
167
168
169perl v5.32.0                      2020-07-28                           File(3)
Impressum