summaryrefslogtreecommitdiff
path: root/lib/App
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2012-07-08 12:38:56 +0200
committerDaniel Friesel <derf@finalrewind.org>2012-07-08 12:38:56 +0200
commit7cc60cd4f505634fd1d4cdb052ceb1769be4e3a0 (patch)
tree1c30ae5ba543f009b4593404f97440cb2d28f90a /lib/App
parenta5a6a29ebbb4a96cd957004cfb1c5c7685eced7d (diff)
Set read_size to zero take read whole files
Diffstat (limited to 'lib/App')
-rw-r--r--lib/App/Hashl.pm14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/App/Hashl.pm b/lib/App/Hashl.pm
index b7d76f6..ec779a9 100644
--- a/lib/App/Hashl.pm
+++ b/lib/App/Hashl.pm
@@ -4,7 +4,7 @@ use strict;
use warnings;
use 5.010;
-use Digest::SHA qw(sha1_hex);
+use Digest::SHA;
use Storable qw(nstore retrieve);
our $VERSION = '1.00';
@@ -46,10 +46,15 @@ sub si_size {
sub hash_file {
my ( $self, $file ) = @_;
my $data;
+ my $digest = Digest::SHA->new(1);
# read() fails for empty files
if ( ( stat($file) )[7] == 0 ) {
- return sha1_hex();
+ return $digest->hexdigest;
+ }
+ if ($self->{config}->{read_size} == 0) {
+ $digest->addfile($file);
+ return $digest->hexdigest;
}
#<<< perltidy has problems indenting 'or die' with tabs
@@ -64,7 +69,8 @@ sub hash_file {
or die("Can't close ${file}: $!\n");
#>>>
- return sha1_hex($data);
+ $digest->add($data);
+ return $digest->hexdigest;
}
sub hash_in_db {
@@ -220,7 +226,7 @@ Returns a new B<App::Hashl> object. Accepted parameters are:
=item B<read_size> => I<bytes>
How many bytes of a file to consider for the hash. Defaults to 4 MiB (4 *
-2**20 bytes).
+2**20 bytes). 0 means read the whole file.
=back