Commit | Line | Data |
319fab50 |
1 | package IO::Uncompress::Adapter::Bunzip2; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use bytes; |
6 | |
80b215cb |
7 | use IO::Compress::Base::Common 2.019 qw(:Status); |
319fab50 |
8 | |
80b215cb |
9 | use Compress::Raw::Bzip2 2.019 ; |
319fab50 |
10 | |
11 | our ($VERSION, @ISA); |
80b215cb |
12 | $VERSION = '2.019'; |
319fab50 |
13 | |
14 | sub mkUncompObject |
15 | { |
16 | my $small = shift || 0; |
17 | my $verbosity = shift || 0; |
18 | |
ea6efd2c |
19 | my ($inflate, $status) = new Compress::Raw::Bunzip2(1, 1, $small, $verbosity, 1); |
319fab50 |
20 | |
21 | return (undef, "Could not create Inflation object: $status", $status) |
22 | if $status != BZ_OK ; |
23 | |
24 | return bless {'Inf' => $inflate, |
25 | 'CompSize' => 0, |
26 | 'UnCompSize' => 0, |
27 | 'Error' => '', |
28 | } ; |
29 | |
30 | } |
31 | |
32 | sub uncompr |
33 | { |
34 | my $self = shift ; |
35 | my $from = shift ; |
36 | my $to = shift ; |
37 | my $eof = shift ; |
38 | |
39 | my $inf = $self->{Inf}; |
40 | |
41 | my $status = $inf->bzinflate($from, $to); |
42 | $self->{ErrorNo} = $status; |
43 | |
319fab50 |
44 | if ($status != BZ_OK && $status != BZ_STREAM_END ) |
45 | { |
46 | $self->{Error} = "Inflation Error: $status"; |
47 | return STATUS_ERROR; |
48 | } |
49 | |
50 | |
51 | return STATUS_OK if $status == BZ_OK ; |
52 | return STATUS_ENDSTREAM if $status == BZ_STREAM_END ; |
53 | return STATUS_ERROR ; |
54 | } |
55 | |
56 | |
319fab50 |
57 | sub reset |
58 | { |
59 | my $self = shift ; |
60 | |
61 | my ($inf, $status) = new Compress::Raw::Bunzip2(); |
62 | $self->{ErrorNo} = ($status == BZ_OK) ? 0 : $status ; |
63 | |
64 | if ($status != BZ_OK) |
65 | { |
66 | $self->{Error} = "Cannot create Inflate object: $status"; |
67 | return STATUS_ERROR; |
68 | } |
69 | |
70 | $self->{Inf} = $inf; |
71 | |
72 | return STATUS_OK ; |
73 | } |
74 | |
319fab50 |
75 | sub compressedBytes |
76 | { |
77 | my $self = shift ; |
78 | $self->{Inf}->compressedBytes(); |
79 | } |
80 | |
81 | sub uncompressedBytes |
82 | { |
83 | my $self = shift ; |
84 | $self->{Inf}->uncompressedBytes(); |
85 | } |
86 | |
87 | sub crc32 |
88 | { |
89 | my $self = shift ; |
90 | #$self->{Inf}->crc32(); |
91 | } |
92 | |
93 | sub adler32 |
94 | { |
95 | my $self = shift ; |
96 | #$self->{Inf}->adler32(); |
97 | } |
98 | |
99 | sub sync |
100 | { |
101 | my $self = shift ; |
102 | #( $self->{Inf}->inflateSync(@_) == BZ_OK) |
103 | # ? STATUS_OK |
104 | # : STATUS_ERROR ; |
105 | } |
106 | |
107 | |
108 | 1; |
109 | |
110 | __END__ |
111 | |