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 59     59   7131 use strict;
  59         126  
  59         2379  
4 59     59   302 use warnings;
  59         1595  
  59         3391  
5 59     59   313 use bytes;
  59         113  
  59         382  
6              
7 59     59   2226 use IO::Compress::Base::Common 2.219 qw(:Status);
  59         1118  
  59         29240  
8              
9 59     59   59785 use Compress::Raw::Bzip2 2.218 ;
  59         94290  
  59         55602  
10              
11             our ($VERSION);
12             $VERSION = '2.219';
13              
14             sub mkCompObject
15             {
16 548     548 0 1030 my $BlockSize100K = shift ;
17 548         953 my $WorkFactor = shift ;
18 548         958 my $Verbosity = shift ;
19              
20 548 50       1832 $BlockSize100K = 1 if ! defined $BlockSize100K ;
21 548 50       1389 $WorkFactor = 0 if ! defined $WorkFactor ;
22 548 50       1174 $Verbosity = 0 if ! defined $Verbosity ;
23              
24 548         19957 my ($def, $status) = Compress::Raw::Bzip2->new(1, $BlockSize100K,
25             $WorkFactor, $Verbosity);
26              
27 548 50       2573 return (undef, "Could not create Deflate object: $status", $status)
28             if $status != BZ_OK ;
29              
30 548         5990 return bless {'Def' => $def,
31             'Error' => '',
32             'ErrorNo' => 0,
33             } ;
34             }
35              
36             sub compr
37             {
38 535     535 0 1043 my $self = shift ;
39              
40 535         1154 my $def = $self->{Def};
41              
42 535         198268 my $status = $def->bzdeflate($_[0], $_[1]) ;
43 535         1743 $self->{ErrorNo} = $status;
44              
45 535 50       2352 if ($status != BZ_RUN_OK)
46             {
47 0         0 $self->{Error} = "Deflate Error: $status";
48 0         0 return STATUS_ERROR;
49             }
50              
51 535         3625 return STATUS_OK;
52             }
53              
54             sub flush
55             {
56 4     4 0 6 my $self = shift ;
57              
58 4         8 my $def = $self->{Def};
59              
60 4         166 my $status = $def->bzflush($_[0]);
61 4         13 $self->{ErrorNo} = $status;
62              
63 4 50       14 if ($status != BZ_RUN_OK)
64             {
65 0         0 $self->{Error} = "Deflate Error: $status";
66 0         0 return STATUS_ERROR;
67             }
68              
69 4         24 return STATUS_OK;
70              
71             }
72              
73             sub close
74             {
75 547     547 0 1548 my $self = shift ;
76              
77 547         1040 my $def = $self->{Def};
78              
79 547         100087 my $status = $def->bzclose($_[0]);
80 547         1827 $self->{ErrorNo} = $status;
81              
82 547 50       2043 if ($status != BZ_STREAM_END)
83             {
84 0         0 $self->{Error} = "Deflate Error: $status";
85 0         0 return STATUS_ERROR;
86             }
87              
88 547         4304 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__