String/Compress.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« String/Base64.pm ↑ Summary String/Csv.pm »
1 #
2 # $Id$
3 #
4 # string::gzip Brik
5 #
6 package Metabrik::String::Compress;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw(Metabrik::System::Package);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub brik_properties {
13 return {
14 revision => '$Revision$',
15 tags => [ qw(unstable gzip gunzip unzip uncompress) ],
16 author => 'GomoR <GomoR[at]metabrik.org>',
17 license => 'http://opensource.org/licenses/BSD-3-Clause',
18 attributes => {
19 data => [ qw($data) ],
20 memory_limit => [ qw(integer) ],
21 },
22 attributes_default => {
23 memory_limit => '1_000_000_000', # XXX: to implement
24 },
25 commands => {
26 install => [ ], # Inherited
27 gunzip => [ qw($data) ],
28 gzip => [ qw($data) ],
29 },
30 require_modules => {
31 'Gzip::Faster' => [ ],
32 },
33 need_packages => {
34 ubuntu => [ qw(libz-dev) ],
35 debian => [ qw(libz-dev) ],
36 kali => [ qw(libz-dev) ],
37 },
38 };
39 }
40  
41 sub gunzip {
42 my $self = shift;
43 my ($data) = @_;
44  
45 $self->brik_help_run_undef_arg('gunzip', $data) or return;
46  
47 if (! length($data)) {
48 return $self->log->error("gunzip: empty data, nothing to decompress");
49 }
50  
51 $self->log->debug("gunzip: length[".length($data)."]");
52  
53 $self->log->debug("gunzip: starting");
54  
55 my $plain = Gzip::Faster::gunzip($data);
56 if (! defined($plain)) {
57 return $self->log->error("gunzip: error");
58 }
59  
60 $self->log->debug("gunzip: finished");
61  
62 $self->log->debug("gunzip: length[".length($plain)."]");
63  
64 return \$plain;
65 }
66  
67 sub gzip {
68 my $self = shift;
69 my ($data) = @_;
70  
71 $self->brik_help_run_undef_arg('gzip', $data) or return;
72  
73 if (! length($data)) {
74 return $self->log->error("gzip: empty data, nothing to compress");
75 }
76  
77 my $gzipped = Gzip::Faster::gzip($data);
78 if (! defined($gzipped)) {
79 return $self->log->error("gzip: error");
80 }
81  
82 return \$gzipped;
83 }
84  
85 1;
86  
87 __END__
« String/Base64.pm ↑ Summary String/Csv.pm »