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