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