author | ca |
Mon, 03 Aug 2009 15:38:33 +0200 | |
changeset 2196 | 9eecfefd08aa |
parent 2193 | db70507b21ba |
child 2335 | 609923563c1d |
permissions | -rw-r--r-- |
1308 | 1 |
" |
2 |
COPYRIGHT (c) 2002 by eXept Software AG |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
3 |
All Rights Reserved |
1308 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
1195 | 12 |
"{ Package: 'stx:libbasic2' }" |
1044 | 13 |
|
1059 | 14 |
CompressionStream subclass:#ZipStream |
1193 | 15 |
instanceVariableNames:'' |
16 |
classVariableNames:'Z_DEFLATED HEAD_OS_CODE HEAD_RESERVED HEAD_EXTRA_FIELD |
|
17 |
HEAD_ORIG_NAME HEAD_COMMENT HEAD_CRC GZ_MAGIC_ID' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'System-Compress' |
|
1044 | 20 |
! |
21 |
||
1045 | 22 |
!ZipStream primitiveDefinitions! |
23 |
%{ |
|
24 |
||
25 |
/* |
|
26 |
* includes, defines, structure definitions |
|
27 |
* and typedefs come here. |
|
28 |
*/ |
|
1836 | 29 |
#include "zlib.h" |
30 |
#include "zutil.h" |
|
1045 | 31 |
|
1051 | 32 |
typedef enum { |
1195 | 33 |
e_opmode_unspecified /* processing done */ |
34 |
, e_opmode_deflate /* running deflate */ |
|
35 |
, e_opmode_inflate /* running inflate */ |
|
1051 | 36 |
} e_opmode; |
37 |
||
1045 | 38 |
typedef struct { |
1195 | 39 |
z_stream stream; /* pointer to the external in -stream */ |
40 |
Bytef * in_ref; /* size of the external in -stream */ |
|
41 |
Bytef * out_ref; /* pointer to the external out-stream */ |
|
42 |
uLong out_total; /* size of the external out-stream */ |
|
1045 | 43 |
|
1195 | 44 |
e_opmode op_mode; /* current operational mode */ |
45 |
uLong crc_32; /* keeps the current crc */ |
|
1061 | 46 |
|
1195 | 47 |
Bytef tail_buff[ 8 ]; /* store the tail in the read modus */ |
48 |
uLong tail_size; /* to check the crc and data length */ |
|
1045 | 49 |
} zstream_s; |
50 |
||
51 |
%} |
|
52 |
! ! |
|
53 |
||
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
54 |
!ZipStream class methodsFor:'documentation'! |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
55 |
|
1308 | 56 |
copyright |
57 |
" |
|
58 |
COPYRIGHT (c) 2002 by eXept Software AG |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
59 |
All Rights Reserved |
1308 | 60 |
|
61 |
This software is furnished under a license and may be used |
|
62 |
only in accordance with the terms of that license and with the |
|
63 |
inclusion of the above copyright notice. This software may not |
|
64 |
be provided or otherwise made available to, or used by, any |
|
65 |
other person. No title to or ownership of the software is |
|
66 |
hereby transferred. |
|
67 |
" |
|
68 |
! |
|
69 |
||
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
70 |
documentation |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
71 |
" |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
72 |
Zip compression and decompression (used in gzip and zip) |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
73 |
|
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
74 |
[author:] |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
75 |
Claus Atzkern |
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
76 |
|
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
77 |
[instance variables:] |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
78 |
|
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
79 |
[class variables:] |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
80 |
|
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
81 |
[see also:] |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
82 |
|
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
83 |
" |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
84 |
! |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
85 |
|
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
86 |
examples |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
87 |
" |
2190 | 88 |
[exBegin] |
1847 | 89 |
|compressedDataStream zipStream compressedData uncompressedData| |
90 |
||
91 |
compressedDataStream := #[] writeStream. |
|
92 |
zipStream := ZipStream writeOpenOn:compressedDataStream. |
|
93 |
zipStream nextPutAll:'hallo Welt'. |
|
94 |
zipStream close. |
|
95 |
||
96 |
compressedData := compressedDataStream contents. |
|
97 |
||
98 |
zipStream := ZipStream readOpenOn:(compressedData readStream). |
|
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
99 |
|
1847 | 100 |
zipStream notNil ifTrue:[ |
2190 | 101 |
|stream c| |
1847 | 102 |
|
2190 | 103 |
stream := '' writeStream. |
1847 | 104 |
|
2190 | 105 |
[ (c := zipStream next) notNil ] whileTrue:[ |
106 |
stream nextPut:c |
|
107 |
]. |
|
108 |
stream close. |
|
109 |
uncompressedData := stream contents. |
|
1847 | 110 |
]. |
111 |
^ uncompressedData |
|
2190 | 112 |
[exEnd] |
1847 | 113 |
|
114 |
||
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
115 |
" |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
116 |
! ! |
1045 | 117 |
|
118 |
!ZipStream class methodsFor:'initialization'! |
|
119 |
||
120 |
initialize |
|
1061 | 121 |
"setup class attributes derived from the library |
122 |
" |
|
1059 | 123 |
|z_deflated os_code| |
1045 | 124 |
%{ |
1059 | 125 |
z_deflated = __MKSMALLINT( Z_DEFLATED ); |
126 |
os_code = __MKSMALLINT( OS_CODE ); |
|
1045 | 127 |
%}. |
128 |
||
1059 | 129 |
Z_DEFLATED := z_deflated. |
1045 | 130 |
|
1059 | 131 |
HEAD_OS_CODE := os_code. |
1045 | 132 |
HEAD_RESERVED := 16rE0. " bits 5..7: reserved " |
133 |
HEAD_EXTRA_FIELD := 16r04. " bit 2 set: extra field present " |
|
134 |
HEAD_ORIG_NAME := 16r08. " bit 3 set: original file name present " |
|
135 |
HEAD_COMMENT := 16r10. " bit 4 set: file comment present " |
|
136 |
HEAD_CRC := 16r02. " bit 1 set: header CRC present " |
|
137 |
||
138 |
GZ_MAGIC_ID := #[ 16r1f 16r8b ] |
|
139 |
||
140 |
! ! |
|
141 |
||
2006
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
142 |
!ZipStream class methodsFor:'instance creation'! |
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
143 |
|
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
144 |
readOpenAsZipStreamOn:aStream |
2190 | 145 |
"open to read data compressed from stream, |
2006
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
146 |
the default readOpenOn: will open ZipStream as gzip stream" |
2196 | 147 |
|
148 |
^ self |
|
149 |
readOpenAsZipStreamOn:aStream |
|
150 |
suppressHeaderAndChecksum:(self defaultSuppressHeaderAndChecksum) |
|
151 |
! |
|
152 |
||
153 |
readOpenAsZipStreamOn:aStream suppressHeaderAndChecksum:aBoolean |
|
154 |
"open to read data compressed from stream, |
|
155 |
the default readOpenOn: will open ZipStream as gzip stream" |
|
156 |
||
157 |
^ self basicNew |
|
158 |
streamOpenWithMode:#readonly |
|
159 |
on:aStream |
|
160 |
suppressHeaderAndChecksum:aBoolean |
|
2006
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
161 |
! |
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
162 |
|
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
163 |
writeOpenAsZipStreamOn:aStream |
2190 | 164 |
"open to write data compressed to stream, |
2006
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
165 |
the default writeOpenOn: will open ZipStream as gzip stream" |
2196 | 166 |
|
167 |
^ self |
|
168 |
writeOpenAsZipStreamOn:aStream |
|
169 |
suppressHeaderAndChecksum:(self defaultSuppressHeaderAndChecksum) |
|
170 |
! |
|
171 |
||
172 |
writeOpenAsZipStreamOn:aStream suppressHeaderAndChecksum:aBoolean |
|
173 |
"open to write data compressed to stream, |
|
174 |
the default writeOpenOn: will open ZipStream as gzip stream" |
|
175 |
||
176 |
^ self basicNew |
|
177 |
streamOpenWithMode:#writeonly |
|
178 |
on:aStream |
|
179 |
suppressHeaderAndChecksum:aBoolean |
|
2006
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
180 |
! ! |
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
181 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
182 |
!ZipStream class methodsFor:'ZipInterface compatibility - compress/uncompress'! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
183 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
184 |
compress: aUncompressedByteArray into: aCompressedByteArray |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
185 |
^ self flatBytesIn: aUncompressedByteArray |
1828 | 186 |
from: 1 |
187 |
to: (aUncompressedByteArray size) |
|
188 |
into: aCompressedByteArray |
|
189 |
doCompress: true. |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
190 |
! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
191 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
192 |
flatBytesIn:bytesIn from:start to:stop into:bytesOut doCompress:doCompress |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
193 |
"compress or uncompress the bytesIn buffer into the bytesOut buffer; returns |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
194 |
the un/compressed size; on error an exception is raised |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
195 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
196 |
|errorNr size| |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
197 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
198 |
size := stop - start + 1. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
199 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
200 |
( (start between:1 and:stop) |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
201 |
and:[size > 0 |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
202 |
and:[bytesIn size >= stop |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
203 |
and:[bytesOut size > 0]]] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
204 |
) ifFalse:[ |
1828 | 205 |
^ self error:'invalid argument size' |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
206 |
]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
207 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
208 |
%{ |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
209 |
char * __bytesIn = 0; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
210 |
uLong __countIn = 0; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
211 |
char * __bytesOut = 0; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
212 |
uLong __countOut = 0; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
213 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
214 |
if( (__isSmallInteger(start)) && (__isSmallInteger(stop)) && (__isSmallInteger(size)) ) |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
215 |
{ |
1828 | 216 |
__countIn = __intVal( size ); |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
217 |
|
1828 | 218 |
if (__isBytes(bytesIn)) { |
219 |
__bytesIn = __ByteArrayInstPtr(bytesIn)->ba_element; |
|
220 |
} else { |
|
221 |
if (__isString(bytesIn)) { |
|
222 |
__bytesIn = __stringVal( bytesIn ); |
|
223 |
} |
|
224 |
} |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
225 |
|
1828 | 226 |
if (__isBytes(bytesOut)) { |
227 |
__bytesOut = __ByteArrayInstPtr(bytesOut)->ba_element; |
|
228 |
__countOut = __byteArraySize( bytesOut ); |
|
229 |
} else { |
|
230 |
if (__isString(bytesOut)) { |
|
231 |
__bytesOut = __stringVal( bytesOut ); |
|
232 |
__countOut = __stringSize( bytesOut ); |
|
233 |
} |
|
234 |
} |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
235 |
} |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
236 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
237 |
if( __bytesOut && __bytesIn ) |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
238 |
{ |
1828 | 239 |
int __result = Z_OK; |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
240 |
|
1828 | 241 |
__bytesIn += (__intVal( start)) - 1; |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
242 |
|
1828 | 243 |
if( doCompress == true ) |
244 |
__result = compress ( (Byte *) __bytesOut, & __countOut, (Byte *) __bytesIn, __countIn ); |
|
245 |
else |
|
246 |
__result = uncompress( (Byte *) __bytesOut, & __countOut, (Byte *) __bytesIn, __countIn ); |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
247 |
|
1828 | 248 |
if( __result == Z_OK ) |
249 |
{ RETURN(__MKSMALLINT(__countOut)); } |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
250 |
|
1828 | 251 |
errorNr = __MKSMALLINT( __result ); |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
252 |
} |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
253 |
%}. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
254 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
255 |
errorNr isNil ifTrue:[ ^ self error:'invalid arguments' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
256 |
errorNr == 1 ifTrue:[ ^ self error:'stream at end' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
257 |
errorNr == -3 ifTrue:[ ^ self error:'input data are corrupted' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
258 |
errorNr == -4 ifTrue:[ ^ self error:'not enough memory' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
259 |
errorNr == -5 ifTrue:[ ^ self error:'not enough memory in the output stream' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
260 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
261 |
self error:('compressing error: ', errorNr printString). |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
262 |
! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
263 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
264 |
uncompress: aCompressedByteArray into: aUncompressedByteArray |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
265 |
^ self flatBytesIn: aCompressedByteArray |
1828 | 266 |
from: 1 |
267 |
to: (aCompressedByteArray size) |
|
268 |
into: aUncompressedByteArray |
|
269 |
doCompress: false. |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
270 |
! ! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
271 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
272 |
!ZipStream class methodsFor:'ZipInterface compatibility - crc'! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
273 |
|
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
274 |
crc32Add:aCharacterOrByte crc:crc |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
275 |
"Update a running crc waCharacterOrByte |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
276 |
and return the updated crc " |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
277 |
%{ |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
278 |
if( (__isInteger(crc))) { |
2190 | 279 |
char __byte; |
280 |
uLong __crc; |
|
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
281 |
|
2190 | 282 |
if (__isCharacter(aCharacterOrByte)) { |
283 |
__byte = __smallIntegerVal(__characterVal(aCharacterOrByte)); |
|
284 |
} else if (__isSmallInteger(aCharacterOrByte)) { |
|
285 |
__byte = __intVal(aCharacterOrByte); |
|
286 |
} else{ |
|
287 |
goto err; |
|
288 |
} |
|
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
289 |
|
2190 | 290 |
__crc = __unsignedLongIntVal( crc ); |
291 |
__crc = crc32(__crc, (Byte *) &__byte, 1 ); |
|
292 |
RETURN( __MKUINT(__crc) ); |
|
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
293 |
} |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
294 |
err:; |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
295 |
%}. |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
296 |
|
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
297 |
^ self error:'invalid argument' |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
298 |
! |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
299 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
300 |
crc32BytesIn:bytesIn |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
301 |
"compute crc with the bytes buf[1.. bytesIn size] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
302 |
and return the crc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
303 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
304 |
^ self crc32BytesIn:bytesIn from:1 |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
305 |
! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
306 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
307 |
crc32BytesIn:bytesIn crc:aCrc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
308 |
"Update a running crc with the bytes buf[1.. bytesIn size] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
309 |
and return the updated |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
310 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
311 |
^ self crc32BytesIn:bytesIn from:1 crc:aCrc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
312 |
! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
313 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
314 |
crc32BytesIn:bytesIn from:start |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
315 |
"compute crc with the bytes buf[start.. bytesIn size] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
316 |
and return the crc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
317 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
318 |
^ self crc32BytesIn:bytesIn from:start to:(bytesIn size) |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
319 |
! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
320 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
321 |
crc32BytesIn:bytesIn from:start crc:aCrc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
322 |
"Update a running crc with the bytes buf[start.. bytesIn size] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
323 |
and return the updated |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
324 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
325 |
^ self crc32BytesIn:bytesIn from:start to:(bytesIn size) crc:aCrc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
326 |
! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
327 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
328 |
crc32BytesIn:bytesIn from:start to:stop |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
329 |
"compute crc with the bytes buf[start.. stop] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
330 |
and return the crc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
331 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
332 |
^ self crc32BytesIn:bytesIn from:start to:stop crc:0 |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
333 |
! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
334 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
335 |
crc32BytesIn:bytesIn from:start to:stop crc:crc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
336 |
"Update a running crc with the bytes buf[start.. stop] |
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
337 |
and return the updated crc" |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
338 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
339 |
%{ |
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
340 |
if (__isInteger(crc) && __isSmallInteger(start) && __isSmallInteger(stop)) { |
2190 | 341 |
char * __bytes = 0; |
342 |
unsigned int __size; |
|
343 |
uLong __crc = __unsignedLongIntVal( crc ); |
|
344 |
uInt __start = __intVal( start ); |
|
345 |
uInt __stop = __intVal( stop ); |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
346 |
|
2190 | 347 |
if (__isBytes(bytesIn)) { |
348 |
__bytes = __byteArrayVal(bytesIn); |
|
349 |
__size = __byteArraySize(bytesIn); |
|
350 |
} else if (__isString(bytesIn)) { |
|
351 |
__bytes = __stringVal(bytesIn); |
|
352 |
__size = __stringSize(bytesIn); |
|
353 |
} else { |
|
354 |
goto err; |
|
355 |
} |
|
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
356 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
357 |
|
2190 | 358 |
if (__start < 1 || __start > __size) goto err; |
359 |
if (__stop < 1 || __stop > __size) goto err; |
|
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
360 |
|
2190 | 361 |
__size = __stop - __start + 1; |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
362 |
|
2190 | 363 |
__bytes += __start - 1; |
364 |
__crc = crc32(__crc, (Byte *) __bytes, __size ); |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
365 |
|
2190 | 366 |
RETURN( __MKUINT(__crc) ); |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
367 |
} |
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
368 |
err:; |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
369 |
%}. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
370 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
371 |
^ self error:'invalid argument size' |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
372 |
! ! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
373 |
|
1045 | 374 |
!ZipStream methodsFor:'low level'! |
375 |
||
376 |
zclose |
|
1052 | 377 |
"low level close of the zip stream |
378 |
" |
|
1045 | 379 |
%{ |
380 |
OBJ _zstreamObj = __INST( zstream ); |
|
381 |
||
382 |
if( _zstreamObj != nil ) |
|
383 |
{ |
|
1828 | 384 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
1045 | 385 |
|
1828 | 386 |
__INST(zstream) = nil; |
1045 | 387 |
|
1828 | 388 |
if( _zstream->stream.state != NULL ) |
389 |
{ |
|
390 |
if( _zstream->op_mode == e_opmode_inflate ) |
|
391 |
inflateEnd( & _zstream->stream ); |
|
392 |
else |
|
393 |
deflateEnd( & _zstream->stream ); |
|
394 |
} |
|
395 |
free( _zstream ); |
|
1045 | 396 |
} |
397 |
%}. |
|
398 |
! |
|
399 |
||
1057 | 400 |
zdeflate |
1570 | 401 |
"low level - deflate" |
402 |
||
1045 | 403 |
|errorNo| |
404 |
errorNo := nil. |
|
405 |
||
406 |
%{ |
|
407 |
OBJ _zstreamObj = __INST( zstream ); |
|
408 |
||
1056 | 409 |
if( _zstreamObj != nil ) |
1045 | 410 |
{ |
1828 | 411 |
int _errorNo, _action; |
412 |
uLong _bfsize; |
|
413 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1047 | 414 |
|
1828 | 415 |
if( _zstream->op_mode != e_opmode_deflate ) |
416 |
RETURN( false ); |
|
1051 | 417 |
|
1828 | 418 |
_bfsize = _zstream->out_total; |
1051 | 419 |
|
1828 | 420 |
if( _zstream->stream.state == NULL ) |
421 |
{ |
|
422 |
/* processing finished; write crc_32 and the total size |
|
423 |
*/ |
|
424 |
uLong v, i; |
|
425 |
Bytef * p = _zstream->out_ref; |
|
1051 | 426 |
|
1828 | 427 |
v = _zstream->crc_32; |
428 |
for( i = 0; i < 4; ++i ) { p[i] = v & 0xff; v >>= 8; } |
|
1051 | 429 |
|
1828 | 430 |
v = _zstream->stream.total_in; |
431 |
for( i = 4; i < 8; ++i ) { p[i] = v & 0xff; v >>= 8; } |
|
1051 | 432 |
|
1828 | 433 |
_zstream->op_mode = e_opmode_unspecified; |
434 |
_zstream->stream.avail_in = 0; |
|
435 |
_zstream->stream.next_in = Z_NULL; |
|
436 |
_zstream->stream.avail_out = _bfsize - 8; |
|
437 |
RETURN( true ); |
|
438 |
} |
|
439 |
_zstream->stream.avail_out = _bfsize; |
|
440 |
_zstream->stream.next_out = _zstream->out_ref; |
|
1056 | 441 |
|
1828 | 442 |
_action = (__INST(hitEOF) == true) ? Z_FINISH : Z_NO_FLUSH; |
443 |
_errorNo = deflate( & _zstream->stream, _action ); |
|
1045 | 444 |
|
1828 | 445 |
if( _errorNo == Z_STREAM_END ) |
446 |
{ |
|
447 |
_zstream->stream.avail_in = 0; |
|
448 |
_zstream->stream.next_in = Z_NULL; |
|
449 |
_errorNo = deflateEnd( & _zstream->stream ); |
|
450 |
} |
|
1045 | 451 |
|
1828 | 452 |
if( _errorNo == Z_OK ) |
453 |
{ |
|
454 |
if( _zstream->stream.avail_out == 0 ) |
|
455 |
RETURN( true ); |
|
1050 | 456 |
|
1828 | 457 |
RETURN( false ); |
458 |
} |
|
459 |
errorNo = __MKSMALLINT( _errorNo ); |
|
1045 | 460 |
} |
461 |
%}. |
|
462 |
errorNo ifNil:[ |
|
1828 | 463 |
zstream ifNil:[self errorNotOpen]. |
464 |
self invalidArgument. |
|
1045 | 465 |
]. |
466 |
self zerror:errorNo. |
|
467 |
! |
|
468 |
||
1059 | 469 |
zdeflateInit |
1570 | 470 |
"low level - deflateInit" |
471 |
||
2193 | 472 |
|errorNo level windowBits| |
1045 | 473 |
|
474 |
errorNo := nil. |
|
1059 | 475 |
level := BlockSize. |
2193 | 476 |
windowBits := self zget_windowBits. |
477 |
||
1045 | 478 |
%{ |
479 |
OBJ _zstreamObj = __INST( zstream ); |
|
480 |
||
1059 | 481 |
if( (_zstreamObj != nil) && __isSmallInteger(level) ) |
1045 | 482 |
{ |
1828 | 483 |
int _errorNo; |
484 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1045 | 485 |
|
1828 | 486 |
_zstream->op_mode = e_opmode_deflate; |
1051 | 487 |
|
1828 | 488 |
_errorNo = deflateInit2( & _zstream->stream |
489 |
, __intVal( level ) |
|
490 |
, Z_DEFLATED |
|
2193 | 491 |
, __intVal( windowBits ) |
1828 | 492 |
, DEF_MEM_LEVEL |
493 |
, Z_DEFAULT_STRATEGY |
|
494 |
); |
|
1045 | 495 |
|
1828 | 496 |
if( _errorNo == Z_OK ) |
497 |
RETURN( self ); |
|
1045 | 498 |
|
1828 | 499 |
errorNo = __MKSMALLINT( _errorNo ); |
1045 | 500 |
} |
501 |
%}. |
|
502 |
errorNo ifNil:[ |
|
1828 | 503 |
zstream ifNil:[ self errorNotOpen ]. |
504 |
self invalidArgument . |
|
1045 | 505 |
]. |
506 |
self zerror:errorNo. |
|
507 |
! |
|
508 |
||
1059 | 509 |
zget_avail_out |
510 |
"low level - get the number of available out bytes |
|
511 |
" |
|
512 |
%{ |
|
513 |
OBJ _zstreamObj = __INST( zstream ); |
|
514 |
||
515 |
if( _zstreamObj != nil ) |
|
516 |
{ |
|
1195 | 517 |
uInt _count; |
518 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1059 | 519 |
|
1195 | 520 |
_count = _zstream->out_total - _zstream->stream.avail_out; |
1059 | 521 |
|
1195 | 522 |
RETURN( __MKSMALLINT (_count) ); |
1059 | 523 |
} |
524 |
%}. |
|
525 |
self errorNotOpen. |
|
526 |
! |
|
527 |
||
2193 | 528 |
zget_windowBits |
529 |
"answer the bits used for inflateInit2 or deflateInit2... |
|
530 |
a negative WindowBits value suppresses the zlib header and the checksum..." |
|
531 |
||
532 |
|windowBits| |
|
533 |
%{ |
|
534 |
windowBits = __MKSMALLINT( MAX_WBITS ); |
|
535 |
%}. |
|
536 |
||
537 |
self isHeaderAndChecksumSuppressed ifTrue:[ |
|
538 |
"/ undocumented feature..... |
|
539 |
^ windowBits negated |
|
540 |
]. |
|
541 |
^ windowBits |
|
542 |
! |
|
543 |
||
1050 | 544 |
zinflate |
1052 | 545 |
"low level - inflate |
546 |
" |
|
1061 | 547 |
|errorNo tailError| |
1050 | 548 |
|
1061 | 549 |
tailError := nil. |
550 |
errorNo := nil. |
|
1050 | 551 |
%{ |
552 |
OBJ _zstreamObj = __INST( zstream ); |
|
553 |
||
554 |
if( _zstreamObj != nil ) |
|
555 |
{ |
|
1195 | 556 |
int _errorNo, _count; |
557 |
zstream_s * _zstream; |
|
558 |
int _avail_in; |
|
1050 | 559 |
|
1195 | 560 |
_zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
1050 | 561 |
|
1195 | 562 |
if( _zstream->op_mode != e_opmode_inflate ) |
563 |
RETURN( nil ); |
|
1051 | 564 |
|
1195 | 565 |
_avail_in = _zstream->stream.avail_in; |
1061 | 566 |
|
1195 | 567 |
if( _zstream->stream.state == NULL ) |
568 |
{ |
|
569 |
/* processing finished : check crc and data length */ |
|
570 |
Bytef * _next_in; |
|
571 |
Bytef * _buff; |
|
572 |
uLong _tnum; |
|
573 |
int _i; |
|
1061 | 574 |
|
1195 | 575 |
_next_in = _zstream->stream.next_in; |
576 |
_buff = _zstream->tail_buff; |
|
577 |
_tnum = _zstream->tail_size; |
|
1061 | 578 |
|
1195 | 579 |
while( (_avail_in > 0) && (_tnum < 8) ) |
580 |
{ |
|
581 |
_buff[_tnum] = * _next_in; |
|
1061 | 582 |
|
1195 | 583 |
++_next_in; |
584 |
++_tnum; |
|
585 |
--_avail_in; |
|
586 |
} |
|
587 |
_zstream->tail_size = _tnum; |
|
1061 | 588 |
|
1195 | 589 |
if( _tnum < 8 ) /* test whether tail is read */ |
590 |
RETURN( __MKSMALLINT (0) ); /* need more data */ |
|
1061 | 591 |
|
1195 | 592 |
/* compute and check crc */ |
593 |
for( _tnum = 0, _i = 4; --_i >= 0; _tnum = (_tnum << 8) + _buff[_i] ); |
|
1061 | 594 |
|
1195 | 595 |
if( _tnum != _zstream->crc_32 ) |
596 |
{ tailError = __MKSMALLINT( 1 ); goto badTail; } |
|
1061 | 597 |
|
1195 | 598 |
/* compute and check data length */ |
599 |
for( _tnum = 0, _i = 8; --_i >= 4; _tnum = (_tnum << 8) + _buff[_i] ); |
|
1061 | 600 |
|
1195 | 601 |
if( _zstream->stream.total_out != _tnum ) |
602 |
{ tailError = __MKSMALLINT( 2 ); goto badTail; } |
|
1051 | 603 |
|
1195 | 604 |
_zstream->op_mode = e_opmode_unspecified; |
605 |
RETURN( nil ); |
|
606 |
} |
|
607 |
if( _avail_in == 0 ) |
|
608 |
RETURN( __MKSMALLINT (0) ); |
|
1050 | 609 |
|
1195 | 610 |
_zstream->stream.avail_out = _zstream->out_total; |
611 |
_zstream->stream.next_out = _zstream->out_ref; |
|
1050 | 612 |
|
1195 | 613 |
_errorNo = inflate( & _zstream->stream, Z_NO_FLUSH ); |
1050 | 614 |
|
1195 | 615 |
if( _errorNo == Z_STREAM_END ) |
616 |
_errorNo = inflateEnd( & _zstream->stream ); |
|
1050 | 617 |
|
1195 | 618 |
if( _errorNo == Z_OK ) |
619 |
{ |
|
620 |
_count = _zstream->out_total - _zstream->stream.avail_out; |
|
1051 | 621 |
|
1195 | 622 |
if( _count > 0 ) |
623 |
_zstream->crc_32 = crc32( _zstream->crc_32, _zstream->out_ref, _count ); |
|
1051 | 624 |
|
1195 | 625 |
RETURN( __MKSMALLINT (_count) ); |
626 |
} |
|
627 |
errorNo = __MKSMALLINT( _errorNo ); |
|
1050 | 628 |
} |
1061 | 629 |
badTail:; |
1050 | 630 |
%}. |
1061 | 631 |
errorNo ifNil:[ |
1195 | 632 |
tailError ifNotNil:[ |
633 |
tailError == 1 ifTrue:[ |
|
634 |
self zerror:'invalid compressed data--crc error' |
|
635 |
]. |
|
636 |
self zerror:'invalid compressed data--length error' |
|
637 |
]. |
|
638 |
self errorNotOpen |
|
1061 | 639 |
]. |
1050 | 640 |
self zerror:errorNo. |
641 |
! |
|
642 |
||
1045 | 643 |
zinflateInit |
1052 | 644 |
"low level - inflateInit |
645 |
" |
|
2193 | 646 |
|errorNo windowBits| |
1045 | 647 |
|
648 |
errorNo := nil. |
|
2193 | 649 |
windowBits := self zget_windowBits. |
1045 | 650 |
|
651 |
%{ |
|
652 |
OBJ _zstreamObj = __INST( zstream ); |
|
653 |
||
654 |
if( _zstreamObj != nil ) |
|
655 |
{ |
|
1195 | 656 |
int _errorNo; |
657 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1045 | 658 |
|
1195 | 659 |
_zstream->op_mode = e_opmode_inflate; |
2193 | 660 |
_errorNo = inflateInit2 ( & _zstream->stream |
661 |
, __intVal( windowBits ) |
|
662 |
); |
|
1045 | 663 |
|
1195 | 664 |
if( _errorNo == Z_OK ) |
665 |
RETURN( self ); |
|
1045 | 666 |
|
1195 | 667 |
_zstream->stream.avail_in = 0; |
668 |
errorNo = __MKSMALLINT( _errorNo ); |
|
1045 | 669 |
} |
670 |
%}. |
|
671 |
errorNo ifNil:[ self errorNotOpen ]. |
|
672 |
self zerror:errorNo. |
|
673 |
! |
|
1047 | 674 |
|
1059 | 675 |
zopen |
1052 | 676 |
"low level - opens the zip stream |
677 |
" |
|
1051 | 678 |
|outTotal| |
1045 | 679 |
|
1059 | 680 |
outTotal := outputBytes size. |
1045 | 681 |
%{ |
682 |
zstream_s * _zstream = (zstream_s *) malloc( sizeof(zstream_s) ); |
|
683 |
||
684 |
if( _zstream ) |
|
685 |
{ |
|
1195 | 686 |
OBJ _zobj = __MKEXTERNALADDRESS( _zstream ); |
687 |
OBJ _outObj = __INST( outputBytes ); |
|
688 |
OBJ _inpObj = __INST( inputBytes ); |
|
1045 | 689 |
|
1195 | 690 |
zmemzero( _zstream, sizeof(zstream_s) ); |
1045 | 691 |
|
1195 | 692 |
_zstream->in_ref = (Bytef *) __externalBytesAddress( _inpObj ); |
693 |
_zstream->stream.next_in = Z_NULL; |
|
694 |
_zstream->stream.avail_in = 0; |
|
695 |
_zstream->stream.total_in = 0; |
|
1045 | 696 |
|
1195 | 697 |
_zstream->out_total = __intVal( outTotal ); |
698 |
_zstream->out_ref = (Bytef *) __externalBytesAddress( _outObj ); |
|
699 |
_zstream->stream.next_out = _zstream->out_ref; |
|
700 |
_zstream->stream.avail_out = _zstream->out_total; |
|
701 |
_zstream->stream.total_out = 0; |
|
1045 | 702 |
|
1195 | 703 |
_zstream->stream.zalloc = (alloc_func)0; |
704 |
_zstream->stream.zfree = (free_func) 0; |
|
705 |
_zstream->stream.opaque = (voidpf) 0; |
|
1045 | 706 |
|
1195 | 707 |
_zstream->crc_32 = crc32( 0L, Z_NULL, 0 ); |
708 |
_zstream->op_mode = e_opmode_unspecified; |
|
709 |
_zstream->tail_size = 0; |
|
1045 | 710 |
|
1195 | 711 |
__INST (zstream) = _zobj; |
712 |
__STORE(self, _zobj); |
|
1045 | 713 |
} |
714 |
%}. |
|
715 |
! |
|
716 |
||
1059 | 717 |
zset_avail_in:count |
1570 | 718 |
"set the 'avail_in' and compute the crc" |
1059 | 719 |
%{ |
720 |
OBJ _zstreamObj = __INST( zstream ); |
|
1045 | 721 |
|
1059 | 722 |
if( (_zstreamObj != nil) && __isSmallInteger(count) ) |
723 |
{ |
|
1828 | 724 |
int _count; |
725 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1045 | 726 |
|
1828 | 727 |
if( (_count = __intVal( count )) > 0 ) |
728 |
{ |
|
729 |
Bytef * _in_ref = _zstream->in_ref; |
|
1045 | 730 |
|
1828 | 731 |
_zstream->stream.avail_in = _count; |
732 |
_zstream->stream.next_in = _in_ref; |
|
1045 | 733 |
|
1828 | 734 |
if( _zstream->op_mode == e_opmode_deflate ) |
735 |
_zstream->crc_32 = crc32( _zstream->crc_32, _in_ref, _count ); |
|
736 |
} else { |
|
737 |
_zstream->stream.avail_in = 0; |
|
738 |
_zstream->stream.next_in = Z_NULL; |
|
739 |
} |
|
740 |
RETURN( self ); |
|
1059 | 741 |
} |
742 |
%}. |
|
743 |
zstream ifNil:[ self errorNotOpen ]. |
|
1570 | 744 |
self invalidArgument. |
1045 | 745 |
! ! |
746 |
||
747 |
!ZipStream methodsFor:'startup & release'! |
|
748 |
||
2196 | 749 |
openWithMode:aMode on:aStream suppressHeaderAndChecksum:aBoolean |
2006
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
750 |
"open stream and write or check gzip header" |
2019 | 751 |
|
2196 | 752 |
super |
753 |
openWithMode:aMode |
|
754 |
on:aStream |
|
755 |
suppressHeaderAndChecksum:aBoolean. |
|
2019 | 756 |
|
1193 | 757 |
self isReadable ifTrue:[ |
2196 | 758 |
"Check for the gzip magic id" |
759 |
self readHeader |
|
2019 | 760 |
] ifFalse:[ |
2196 | 761 |
"write the gzip magic id" |
762 |
self writeHeader |
|
2019 | 763 |
]. |
764 |
! |
|
1045 | 765 |
|
2019 | 766 |
readHeader |
767 |
"Check for the gzip magic id" |
|
768 |
|flags| |
|
1045 | 769 |
|
2019 | 770 |
GZ_MAGIC_ID do:[:b| |
2190 | 771 |
onStream nextByte ~~ b ifTrue:[ self zerror:'version error' ] |
2019 | 772 |
]. |
773 |
||
774 |
onStream nextByte ~~ Z_DEFLATED ifTrue:[ |
|
2190 | 775 |
self zerror:'invalid method (not deflated)' |
2019 | 776 |
]. |
1045 | 777 |
|
2019 | 778 |
flags := onStream nextByte. |
779 |
(flags bitAnd:HEAD_RESERVED) ~~ 0 ifTrue:[ |
|
2190 | 780 |
self zerror:'wrong data format' |
2019 | 781 |
]. |
1045 | 782 |
|
2019 | 783 |
"discard time, xflags and OS code" |
784 |
onStream skip:6. |
|
1045 | 785 |
|
2019 | 786 |
(flags bitAnd:HEAD_EXTRA_FIELD) ~~ 0 ifTrue:[|len| |
2190 | 787 |
"skip the extra field" |
788 |
len := onStream nextByte + (onStream nextByte bitShift:8). |
|
789 |
len timesRepeat:[ onStream nextByte ]. |
|
2019 | 790 |
]. |
1050 | 791 |
|
2019 | 792 |
(flags bitAnd:HEAD_ORIG_NAME) ~~ 0 ifTrue:[|b| |
2190 | 793 |
"skip the original file name" |
794 |
[ (b := onStream nextByte) ~~ 0 ] whileTrue. |
|
2019 | 795 |
]. |
796 |
||
797 |
(flags bitAnd:HEAD_CRC) ~~ 0 ifTrue:[ |
|
2190 | 798 |
"skip the header crc" |
799 |
onStream skip:2. |
|
2019 | 800 |
]. |
801 |
! |
|
1050 | 802 |
|
2019 | 803 |
writeHeader |
804 |
"write the gzip magic id" |
|
1059 | 805 |
|
2019 | 806 |
GZ_MAGIC_ID do:[:b| onStream nextPutByte:b ]. |
807 |
||
808 |
"write the method" |
|
809 |
onStream nextPutByte:Z_DEFLATED. |
|
1050 | 810 |
|
2019 | 811 |
"write the flags" |
812 |
onStream nextPutByte:0. |
|
813 |
||
814 |
"write time" |
|
815 |
4 timesRepeat:[ onStream nextPutByte:0 ]. |
|
1045 | 816 |
|
2019 | 817 |
"write xflags" |
818 |
onStream nextPutByte:0. |
|
1059 | 819 |
|
2019 | 820 |
"write OS code" |
821 |
onStream nextPutByte:HEAD_OS_CODE. |
|
1045 | 822 |
! ! |
1044 | 823 |
|
824 |
!ZipStream class methodsFor:'documentation'! |
|
825 |
||
826 |
version |
|
2196 | 827 |
^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.36 2009-08-03 13:38:33 ca Exp $' |
1044 | 828 |
! ! |
1193 | 829 |
|
1047 | 830 |
ZipStream initialize! |