xref: /openbsd-src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Adapter/Bzip2.pm (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1package IO::Compress::Adapter::Bzip2 ;
2
3use strict;
4use warnings;
5use bytes;
6
7use IO::Compress::Base::Common  2.024 qw(:Status);
8
9#use Compress::Bzip2 ;
10use Compress::Raw::Bzip2  2.024 ;
11
12our ($VERSION);
13$VERSION = '2.024';
14
15sub mkCompObject
16{
17    my $BlockSize100K = shift ;
18    my $WorkFactor = shift ;
19    my $Verbosity  = shift ;
20
21    my ($def, $status) = new Compress::Raw::Bzip2(1, $BlockSize100K,
22                                                 $WorkFactor, $Verbosity);
23    #my ($def, $status) = bzdeflateInit();
24                        #-BlockSize100K => $params->value('BlockSize100K'),
25                        #-WorkFactor    => $params->value('WorkFactor');
26
27    return (undef, "Could not create Deflate object: $status", $status)
28        if $status != BZ_OK ;
29
30    return bless {'Def'        => $def,
31                  'Error'      => '',
32                  'ErrorNo'    => 0,
33                 }  ;
34}
35
36sub compr
37{
38    my $self = shift ;
39
40    my $def   = $self->{Def};
41
42    #my ($out, $status) = $def->bzdeflate(defined ${$_[0]} ? ${$_[0]} : "") ;
43    my $status = $def->bzdeflate($_[0], $_[1]) ;
44    $self->{ErrorNo} = $status;
45
46    if ($status != BZ_RUN_OK)
47    {
48        $self->{Error} = "Deflate Error: $status";
49        return STATUS_ERROR;
50    }
51
52    #${ $_[1] } .= $out if defined $out;
53
54    return STATUS_OK;
55}
56
57sub flush
58{
59    my $self = shift ;
60
61    my $def   = $self->{Def};
62
63    #my ($out, $status) = $def->bzflush($opt);
64    #my $status = $def->bzflush($_[0], $opt);
65    my $status = $def->bzflush($_[0]);
66    $self->{ErrorNo} = $status;
67
68    if ($status != BZ_RUN_OK)
69    {
70        $self->{Error} = "Deflate Error: $status";
71        return STATUS_ERROR;
72    }
73
74    #${ $_[0] } .= $out if defined $out ;
75    return STATUS_OK;
76
77}
78
79sub close
80{
81    my $self = shift ;
82
83    my $def   = $self->{Def};
84
85    #my ($out, $status) = $def->bzclose();
86    my $status = $def->bzclose($_[0]);
87    $self->{ErrorNo} = $status;
88
89    if ($status != BZ_STREAM_END)
90    {
91        $self->{Error} = "Deflate Error: $status";
92        return STATUS_ERROR;
93    }
94
95    #${ $_[0] } .= $out if defined $out ;
96    return STATUS_OK;
97
98}
99
100
101sub reset
102{
103    my $self = shift ;
104
105    my $outer = $self->{Outer};
106
107    my ($def, $status) = new Compress::Raw::Bzip2();
108    $self->{ErrorNo} = ($status == BZ_OK) ? 0 : $status ;
109
110    if ($status != BZ_OK)
111    {
112        $self->{Error} = "Cannot create Deflate object: $status";
113        return STATUS_ERROR;
114    }
115
116    $self->{Def} = $def;
117
118    return STATUS_OK;
119}
120
121sub compressedBytes
122{
123    my $self = shift ;
124    $self->{Def}->compressedBytes();
125}
126
127sub uncompressedBytes
128{
129    my $self = shift ;
130    $self->{Def}->uncompressedBytes();
131}
132
133#sub total_out
134#{
135#    my $self = shift ;
136#    0;
137#}
138#
139
140#sub total_in
141#{
142#    my $self = shift ;
143#    $self->{Def}->total_in();
144#}
145#
146#sub crc32
147#{
148#    my $self = shift ;
149#    $self->{Def}->crc32();
150#}
151#
152#sub adler32
153#{
154#    my $self = shift ;
155#    $self->{Def}->adler32();
156#}
157
158
1591;
160
161__END__
162
163