File Coverage

blib/lib/IO/Compress/Adapter/Bzip2.pm
Criterion Covered Total %
statement 42 61 68.8
branch 7 18 38.8
condition n/a
subroutine 9 12 75.0
pod 0 7 0.0
total 58 98 59.1


line stmt bran cond sub pod time code
1             package IO::Compress::Adapter::Bzip2 ;
2              
3 30     30   1040 use strict;
  30         56  
  30         780  
4 30     30   147 use warnings;
  30         367  
  30         905  
5 30     30   146 use bytes;
  30         52  
  30         132  
6              
7 30     30   924 use IO::Compress::Base::Common 2.204 qw(:Status);
  30         444  
  30         3155  
8              
9 30     30   7322 use Compress::Raw::Bzip2 2.204 ;
  30         20412  
  30         18744  
10              
11             our ($VERSION);
12             $VERSION = '2.204';
13              
14             sub mkCompObject
15             {
16 545     545 0 838 my $BlockSize100K = shift ;
17 545         770 my $WorkFactor = shift ;
18 545         771 my $Verbosity = shift ;
19              
20 545 50       1101 $BlockSize100K = 1 if ! defined $BlockSize100K ;
21 545 50       1018 $WorkFactor = 0 if ! defined $WorkFactor ;
22 545 50       982 $Verbosity = 0 if ! defined $Verbosity ;
23              
24 545         10375 my ($def, $status) = Compress::Raw::Bzip2->new(1, $BlockSize100K,
25             $WorkFactor, $Verbosity);
26              
27 545 50       2112 return (undef, "Could not create Deflate object: $status", $status)
28             if $status != BZ_OK ;
29              
30 545         4767 return bless {'Def' => $def,
31             'Error' => '',
32             'ErrorNo' => 0,
33             } ;
34             }
35              
36             sub compr
37             {
38 532     532 0 801 my $self = shift ;
39              
40 532         878 my $def = $self->{Def};
41              
42 532         157223 my $status = $def->bzdeflate($_[0], $_[1]) ;
43 532         1179 $self->{ErrorNo} = $status;
44              
45 532 50       1465 if ($status != BZ_RUN_OK)
46             {
47 0         0 $self->{Error} = "Deflate Error: $status";
48 0         0 return STATUS_ERROR;
49             }
50              
51 532         2853 return STATUS_OK;
52             }
53              
54             sub flush
55             {
56 4     4 0 1103 my $self = shift ;
57              
58 4         9 my $def = $self->{Def};
59              
60 4         116 my $status = $def->bzflush($_[0]);
61 4         11 $self->{ErrorNo} = $status;
62              
63 4 50       11 if ($status != BZ_RUN_OK)
64             {
65 0         0 $self->{Error} = "Deflate Error: $status";
66 0         0 return STATUS_ERROR;
67             }
68              
69 4         20 return STATUS_OK;
70              
71             }
72              
73             sub close
74             {
75 544     544 0 822 my $self = shift ;
76              
77 544         922 my $def = $self->{Def};
78              
79 544         72894 my $status = $def->bzclose($_[0]);
80 544         1324 $self->{ErrorNo} = $status;
81              
82 544 50       1468 if ($status != BZ_STREAM_END)
83             {
84 0         0 $self->{Error} = "Deflate Error: $status";
85 0         0 return STATUS_ERROR;
86             }
87              
88 544         2851 return STATUS_OK;
89              
90             }
91              
92              
93             sub reset
94             {
95 0     0 0   my $self = shift ;
96              
97 0           my $outer = $self->{Outer};
98              
99 0           my ($def, $status) = Compress::Raw::Bzip2->new();
100 0 0         $self->{ErrorNo} = ($status == BZ_OK) ? 0 : $status ;
101              
102 0 0         if ($status != BZ_OK)
103             {
104 0           $self->{Error} = "Cannot create Deflate object: $status";
105 0           return STATUS_ERROR;
106             }
107              
108 0           $self->{Def} = $def;
109              
110 0           return STATUS_OK;
111             }
112              
113             sub compressedBytes
114             {
115 0     0 0   my $self = shift ;
116 0           $self->{Def}->compressedBytes();
117             }
118              
119             sub uncompressedBytes
120             {
121 0     0 0   my $self = shift ;
122 0           $self->{Def}->uncompressedBytes();
123             }
124              
125             #sub total_out
126             #{
127             # my $self = shift ;
128             # 0;
129             #}
130             #
131              
132             #sub total_in
133             #{
134             # my $self = shift ;
135             # $self->{Def}->total_in();
136             #}
137             #
138             #sub crc32
139             #{
140             # my $self = shift ;
141             # $self->{Def}->crc32();
142             #}
143             #
144             #sub adler32
145             #{
146             # my $self = shift ;
147             # $self->{Def}->adler32();
148             #}
149              
150              
151             1;
152              
153             __END__