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