1b39c5158Smillertpackage IO::Uncompress::Adapter::Inflate;
2b39c5158Smillert
3b39c5158Smillertuse strict;
4b39c5158Smillertuse warnings;
59f11ffb7Safresh1use bytes;
6b39c5158Smillert
7*e0680481Safresh1use IO::Compress::Base::Common  2.204 qw(:Status);
8*e0680481Safresh1use Compress::Raw::Zlib  2.204 qw(Z_OK Z_BUF_ERROR Z_STREAM_END Z_FINISH MAX_WBITS);
9b39c5158Smillert
10b39c5158Smillertour ($VERSION);
11*e0680481Safresh1$VERSION = '2.204';
12b39c5158Smillert
13b39c5158Smillert
14b39c5158Smillert
15b39c5158Smillertsub mkUncompObject
16b39c5158Smillert{
17b39c5158Smillert    my $crc32   = shift || 1;
18b39c5158Smillert    my $adler32 = shift || 1;
19b39c5158Smillert    my $scan    = shift || 0;
20b39c5158Smillert
21b39c5158Smillert    my $inflate ;
22b39c5158Smillert    my $status ;
23b39c5158Smillert
24b39c5158Smillert    if ($scan)
25b39c5158Smillert    {
26eac174f2Safresh1        ($inflate, $status) = Compress::Raw::Zlib::InflateScan->new(
27b39c5158Smillert                                    #LimitOutput  => 1,
28b39c5158Smillert                                    CRC32        => $crc32,
29b39c5158Smillert                                    ADLER32      => $adler32,
30eac174f2Safresh1                                    WindowBits   => - MAX_WBITS );
31b39c5158Smillert    }
32b39c5158Smillert    else
33b39c5158Smillert    {
34eac174f2Safresh1        ($inflate, $status) = Compress::Raw::Zlib::Inflate->new(
35b39c5158Smillert                                    AppendOutput => 1,
36b39c5158Smillert                                    LimitOutput  => 1,
37b39c5158Smillert                                    CRC32        => $crc32,
38b39c5158Smillert                                    ADLER32      => $adler32,
39eac174f2Safresh1                                    WindowBits   => - MAX_WBITS );
40b39c5158Smillert    }
41b39c5158Smillert
42b39c5158Smillert    return (undef, "Could not create Inflation object: $status", $status)
43b39c5158Smillert        if $status != Z_OK ;
44b39c5158Smillert
45b39c5158Smillert    return bless {'Inf'        => $inflate,
46b39c5158Smillert                  'CompSize'   => 0,
47b39c5158Smillert                  'UnCompSize' => 0,
48b39c5158Smillert                  'Error'      => '',
49b39c5158Smillert                  'ConsumesInput' => 1,
50b39c5158Smillert                 } ;
51b39c5158Smillert
52b39c5158Smillert}
53b39c5158Smillert
54b39c5158Smillertsub uncompr
55b39c5158Smillert{
56b39c5158Smillert    my $self = shift ;
57b39c5158Smillert    my $from = shift ;
58b39c5158Smillert    my $to   = shift ;
59b39c5158Smillert    my $eof  = shift ;
60b39c5158Smillert
61b39c5158Smillert    my $inf   = $self->{Inf};
62b39c5158Smillert
63b39c5158Smillert    my $status = $inf->inflate($from, $to, $eof);
64b39c5158Smillert    $self->{ErrorNo} = $status;
65b39c5158Smillert    if ($status != Z_OK && $status != Z_STREAM_END && $status != Z_BUF_ERROR)
66b39c5158Smillert    {
67b39c5158Smillert        $self->{Error} = "Inflation Error: $status";
68b39c5158Smillert        return STATUS_ERROR;
69b39c5158Smillert    }
70b39c5158Smillert
71b39c5158Smillert    return STATUS_OK        if $status == Z_BUF_ERROR ; # ???
72b39c5158Smillert    return STATUS_OK        if $status == Z_OK ;
73b39c5158Smillert    return STATUS_ENDSTREAM if $status == Z_STREAM_END ;
74b39c5158Smillert    return STATUS_ERROR ;
75b39c5158Smillert}
76b39c5158Smillert
77b39c5158Smillertsub reset
78b39c5158Smillert{
79b39c5158Smillert    my $self = shift ;
80b39c5158Smillert    $self->{Inf}->inflateReset();
81b39c5158Smillert
82b39c5158Smillert    return STATUS_OK ;
83b39c5158Smillert}
84b39c5158Smillert
85b39c5158Smillert#sub count
86b39c5158Smillert#{
87b39c5158Smillert#    my $self = shift ;
88b39c5158Smillert#    $self->{Inf}->inflateCount();
89b39c5158Smillert#}
90b39c5158Smillert
91b39c5158Smillertsub crc32
92b39c5158Smillert{
93b39c5158Smillert    my $self = shift ;
94b39c5158Smillert    $self->{Inf}->crc32();
95b39c5158Smillert}
96b39c5158Smillert
97b39c5158Smillertsub compressedBytes
98b39c5158Smillert{
99b39c5158Smillert    my $self = shift ;
100b39c5158Smillert    $self->{Inf}->compressedBytes();
101b39c5158Smillert}
102b39c5158Smillert
103b39c5158Smillertsub uncompressedBytes
104b39c5158Smillert{
105b39c5158Smillert    my $self = shift ;
106b39c5158Smillert    $self->{Inf}->uncompressedBytes();
107b39c5158Smillert}
108b39c5158Smillert
109b39c5158Smillertsub adler32
110b39c5158Smillert{
111b39c5158Smillert    my $self = shift ;
112b39c5158Smillert    $self->{Inf}->adler32();
113b39c5158Smillert}
114b39c5158Smillert
115b39c5158Smillertsub sync
116b39c5158Smillert{
117b39c5158Smillert    my $self = shift ;
118b39c5158Smillert    ( $self->{Inf}->inflateSync(@_) == Z_OK)
119b39c5158Smillert            ? STATUS_OK
120b39c5158Smillert            : STATUS_ERROR ;
121b39c5158Smillert}
122b39c5158Smillert
123b39c5158Smillert
124b39c5158Smillertsub getLastBlockOffset
125b39c5158Smillert{
126b39c5158Smillert    my $self = shift ;
127b39c5158Smillert    $self->{Inf}->getLastBlockOffset();
128b39c5158Smillert}
129b39c5158Smillert
130b39c5158Smillertsub getEndOffset
131b39c5158Smillert{
132b39c5158Smillert    my $self = shift ;
133b39c5158Smillert    $self->{Inf}->getEndOffset();
134b39c5158Smillert}
135b39c5158Smillert
136b39c5158Smillertsub resetLastBlockByte
137b39c5158Smillert{
138b39c5158Smillert    my $self = shift ;
139b39c5158Smillert    $self->{Inf}->resetLastBlockByte(@_);
140b39c5158Smillert}
141b39c5158Smillert
142b39c5158Smillertsub createDeflateStream
143b39c5158Smillert{
144b39c5158Smillert    my $self = shift ;
145b39c5158Smillert    my $deflate = $self->{Inf}->createDeflateStream(@_);
146b39c5158Smillert    return bless {'Def'        => $deflate,
147b39c5158Smillert                  'CompSize'   => 0,
148b39c5158Smillert                  'UnCompSize' => 0,
149b39c5158Smillert                  'Error'      => '',
150b39c5158Smillert                 }, 'IO::Compress::Adapter::Deflate';
151b39c5158Smillert}
152b39c5158Smillert
153b39c5158Smillert1;
154b39c5158Smillert
155b39c5158Smillert
156b39c5158Smillert__END__
157