Binmode + Bump version and update Changes
[slob.git] / lib / Slob.pm
index 3e9697fff3c7c2faea0550ea579f1f4bc6848a33..0603b8bcca023f84fc9e889743fbcf0446183ca1 100644 (file)
@@ -3,7 +3,7 @@ package Slob;
 use 5.014000;
 use strict;
 use warnings;
-our $VERSION = '0.001';
+our $VERSION = '0.002002';
 
 use constant MAGIC => "!-1SLOB\x1F";
 
@@ -14,6 +14,9 @@ use Compress::Raw::Bzip2;
 use Compress::Raw::Lzma;
 use Compress::Raw::Zlib;
 
+# MD5 only used for debugging output in tests
+use Digest::MD5 qw/md5_hex/;
+
 our %UNCOMPRESS = (
        '' => sub { $_[0] },
        'lzma2' => sub {
@@ -62,7 +65,8 @@ sub new {
        if (ref $path eq 'IO') {
                $fh = $path
        } else {
-               open $fh, '<', $path or croak "Cannot open \"$path\": $!"
+               open $fh, '<', $path or croak "Cannot open \"$path\": $!";
+               binmode $fh;
        }
        my $self = bless {path => $path, fh => $fh}, $class;
        $self->{header} = $self->read_header;
@@ -156,8 +160,14 @@ sub ftell {
 }
 
 sub uncompress {
-       my ($self, $data) = @_;
-       $UNCOMPRESS{$self->{header}{compression}}->($data)
+       my ($self, $data) = @_;
+       my $compression = $self->{header}{compression};
+       if ($ENV{HARNESS_ACTIVE} && $compression eq 'lzma2') {
+               my $prefix = unpack 'H*', substr $data, 0, 10;
+               my $md5sum = md5_hex $data;
+               Test::More::diag "Uncompressing data starting '$prefix', md5sum $md5sum";
+       }
+       $UNCOMPRESS{$compression}->($data)
 }
 
 sub read_header {
@@ -363,7 +373,7 @@ Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright (C) 2017 by Marius Gavrilescu
+Copyright (C) 2017-2018 by Marius Gavrilescu
 
 This library is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself, either Perl version 5.26.1 or,
This page took 0.009757 seconds and 4 git commands to generate.