| 1 | package Gzip::Faster; | ||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | require Exporter; | |||||||||||||||||||||||||||
| 5 | 4 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 6 | 4 | our @EXPORT = qw/gzip gunzip gzip_file gunzip_file gzip_to_file/; | |||||||||||||||||||||||||||
| 7 | 4 | our @EXPORT_OK = qw/deflate inflate deflate_raw inflate_raw/; | |||||||||||||||||||||||||||
| 8 | 4 | our %EXPORT_TAGS = ('all' => [@EXPORT, @EXPORT_OK]); | |||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | our $VERSION = '0.23'; | |||||||||||||||||||||||||||
| 11 | 4 | require XSLoader; | |||||||||||||||||||||||||||
| 12 | 4 | XSLoader::load ('Gzip::Faster', $VERSION); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # Read the whole file in to memory. | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | sub get_file | ||||||||||||||||||||||||||||
| 17 | 11 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_file: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 11 | my ($file) = @_; | |||||||||||||||||||||||||||
| 19 | 11 | ▶ | open my $in, "<:raw", $file or croak "Error opening '$file': $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 11 | local $/; | |||||||||||||||||||||||||||
| 21 | 11 | my $zipped = <$in>; | |||||||||||||||||||||||||||
| 22 | 11 | ▶ | close $in or croak "Error closing '$file': $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 11 | return $zipped; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # Make a temporary user object so that gzip_file and friends can | ||||||||||||||||||||||||||||
| 27 | # fiddle with the options of it to set the file name, etc. The object | ||||||||||||||||||||||||||||
| 28 | # is discarded after the call. | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | sub gzip_options | ||||||||||||||||||||||||||||
| 31 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
gzip_options: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | 4 | my ($plain, %options) = @_; | |||||||||||||||||||||||||||
| 33 | 4 | my $gf = __PACKAGE__->new (); | |||||||||||||||||||||||||||
| 34 | 4 | my $file_name = $options{file_name}; | |||||||||||||||||||||||||||
| 35 | 4 | my $mod_time = $options{mod_time}; | |||||||||||||||||||||||||||
| 36 | 4 | ▶ | if ($file_name) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 3 | $gf->file_name ($file_name); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 4 | ▶ | if ($mod_time) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 1 | $gf->mod_time ($mod_time); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 4 | return $gf->zip ($plain); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | sub gzip_file | ||||||||||||||||||||||||||||
| 46 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
gzip_file: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 2 | my ($file, %options) = @_; | |||||||||||||||||||||||||||
| 48 | 2 | my $plain = get_file ($file); | |||||||||||||||||||||||||||
| 49 | 2 | ▶ | if (keys %options) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 1 | return gzip_options ($plain, %options); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | else { | ||||||||||||||||||||||||||||
| 53 | 1 | my $mod_time = (stat ($file))[9]; | |||||||||||||||||||||||||||
| 54 | 1 | return gzip_options ($plain, file_name => $file, mod_time => $mod_time); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | sub gunzip_file | ||||||||||||||||||||||||||||
| 59 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
gunzip_file: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 9 | my ($file, %options) = @_; | |||||||||||||||||||||||||||
| 61 | 9 | my $zipped = get_file ($file); | |||||||||||||||||||||||||||
| 62 | 9 | my $plain; | |||||||||||||||||||||||||||
| 63 | 9 | ▶ | if (keys %options) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # Make a temporary user object so that we can fiddle with the | ||||||||||||||||||||||||||||
| 66 | # options of it to get the file name, etc. The object is | ||||||||||||||||||||||||||||
| 67 | # discarded outside this scope. | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 6 | my $gf = __PACKAGE__->new (); | |||||||||||||||||||||||||||
| 70 | 6 | $plain = $gf->unzip ($zipped); | |||||||||||||||||||||||||||
| 71 | 6 | my $file_name_ref = $options{file_name}; | |||||||||||||||||||||||||||
| 72 | 6 | ▶ | if (defined ($file_name_ref) && ref $file_name_ref ne 'SCALAR') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $file_name_ref and ref $file_name_ref ne "SCALAR"
MC/DC100%2/2
defined $file_name_ref and ref $file_name_ref ne "SCALAR"
defined $file_name_ref
ref $file_name_ref ne "SCALAR"
Truth table100%3/3
A and B
A= defined $file_name_refB= ref $file_name_ref ne "SCALAR"
| |||||||||||||||||||||||||||||
| 73 | 1 | warn "Cannot write file name to non-scalar reference"; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | else { | ||||||||||||||||||||||||||||
| 76 | 5 | $$file_name_ref = $gf->file_name (); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | 6 | my $mod_time_ref = $options{mod_time}; | |||||||||||||||||||||||||||
| 79 | 6 | ▶ | if (defined ($mod_time_ref) && ref $mod_time_ref ne 'SCALAR') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $mod_time_ref and ref $mod_time_ref ne "SCALAR"
MC/DC100%2/2
defined $mod_time_ref and ref $mod_time_ref ne "SCALAR"
defined $mod_time_ref
ref $mod_time_ref ne "SCALAR"
Truth table100%3/3
A and B
A= defined $mod_time_refB= ref $mod_time_ref ne "SCALAR"
| |||||||||||||||||||||||||||||
| 80 | 1 | warn "Cannot write modification time to non-scalar reference"; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | else { | ||||||||||||||||||||||||||||
| 83 | 5 | $$mod_time_ref = $gf->mod_time (); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | else { | ||||||||||||||||||||||||||||
| 87 | 3 | $plain = gunzip ($zipped); | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | 9 | return $plain; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | sub gzip_to_file | ||||||||||||||||||||||||||||
| 93 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
gzip_to_file: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 4 | my ($plain, $file, %options) = @_; | |||||||||||||||||||||||||||
| 95 | 4 | my $zipped; | |||||||||||||||||||||||||||
| 96 | 4 | ▶ | if (keys %options) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 2 | $zipped = gzip_options ($plain, %options); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | else { | ||||||||||||||||||||||||||||
| 100 | 2 | $zipped = gzip ($plain); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 4 | ▶ | open my $in, ">:raw", $file or croak "Error opening '$file': $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 4 | print $in $zipped; | |||||||||||||||||||||||||||
| 104 | 4 | ▶ | close $in or croak "Error closing '$file': $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 4 | 1; | |||||||||||||||||||||||||||