From 7cc60cd4f505634fd1d4cdb052ceb1769be4e3a0 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 8 Jul 2012 12:38:56 +0200 Subject: Set read_size to zero take read whole files --- lib/App/Hashl.pm | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'lib/App') 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 object. Accepted parameters are: =item B => I 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 -- cgit v1.2.3