| 1 | package Gzip::Libdeflate; | ||||||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 2 | our $VERSION = '0.13'; | |||||||||||||
| 5 | 2 | require XSLoader; | |||||||||||||
| 6 | 2 | XSLoader::load ('Gzip::Libdeflate', $VERSION); | |||||||||||||
| 7 | |||||||||||||||
| 8 | 2 | ▶ | use File::Slurper qw!read_binary write_binary!; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 2 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | sub get_from | ||||||||||||||
| 12 | 4 | ▶ | { | ||||||||||||
|
Subroutine
get_from: called CC=4 SCAR=16.6
Pod
undocumented
| |||||||||||||||
| 13 | 4 | my (%options) = @_; | |||||||||||||
| 14 | 4 | my $from; | |||||||||||||
| 15 | 4 | ▶ | if ($options{in}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 16 | 4 | $from = read_binary ($options{in}); | |||||||||||||
| 17 | } | ||||||||||||||
| 18 | elsif ($options{from}) { | ||||||||||||||
| 19 | 0 | $from = $options{from}; | |||||||||||||
| 20 | } | ||||||||||||||
| 21 | 4 | ▶ | if (! $from) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 22 | 0 | carp "Specify one of from => scalar or in => file"; | |||||||||||||
| 23 | } | ||||||||||||||
| 24 | 4 | return $from; | |||||||||||||
| 25 | } | ||||||||||||||
| 26 | |||||||||||||||
| 27 | sub make_out | ||||||||||||||
| 28 | 4 | ▶ | { | ||||||||||||
|
Subroutine
make_out: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 29 | 4 | my ($out, %options) = @_; | |||||||||||||
| 30 | 4 | my $outfile = $options{out}; | |||||||||||||
| 31 | 4 | ▶ | if ($outfile) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 32 | 2 | write_binary ($outfile, $out); | |||||||||||||
| 33 | } | ||||||||||||||
| 34 | 4 | return $out; | |||||||||||||
| 35 | } | ||||||||||||||
| 36 | |||||||||||||||
| 37 | sub compress_file | ||||||||||||||
| 38 | 1 | ▶ | { | ||||||||||||
|
Subroutine
compress_file: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||
| 39 | 1 | my ($o, %options) = @_; | |||||||||||||
| 40 | 1 | my $from = get_from (%options); | |||||||||||||
| 41 | 1 | ▶ | if (! $from) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 42 | 0 | return undef; | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | 1 | my $out = $o->compress ($from); | |||||||||||||
| 45 | 1 | return make_out ($out, %options); | |||||||||||||
| 46 | } | ||||||||||||||
| 47 | |||||||||||||||
| 48 | sub decompress_file | ||||||||||||||
| 49 | 3 | ▶ | { | ||||||||||||
|
Subroutine
decompress_file: called CC=5 SCAR=19.0
Pod
documented
| |||||||||||||||
| 50 | 3 | my ($o, %options) = @_; | |||||||||||||
| 51 | 3 | my $from = get_from (%options); | |||||||||||||
| 52 | 3 | ▶ | if (! $from) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | 0 | return undef; | |||||||||||||
| 54 | } | ||||||||||||||
| 55 | 3 | my $type = $o->get_type (); | |||||||||||||
| 56 | 3 | ▶ | if ($type ne 'gzip') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | 0 | ▶ | if (! $options{size}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 58 | 0 | warn "A non-zero numerical size is required to decompress deflate/zlib inputs"; | |||||||||||||
| 59 | 0 | return undef; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | } | ||||||||||||||
| 62 | 3 | my $size = $options{size}; | |||||||||||||
| 63 | 3 | ▶ | if (! $size) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 64 | 3 | $size = 0; | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | 3 | my $out = $o->decompress ($from, $size); | |||||||||||||
| 67 | 3 | return make_out ($out, %options); | |||||||||||||
| 68 | } | ||||||||||||||
| 69 | |||||||||||||||
| 70 | 2 | 1; | |||||||||||||