author | Stefan Vogel <sv@exept.de> |
Fri, 03 Apr 2020 18:50:48 +0200 | |
changeset 5471 | 0bee7a5e40e8 |
parent 4777 | b22943151ce0 |
permissions | -rw-r--r-- |
4694 | 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:'' |
|
4260 | 23 |
category:'Streams-Compressed' |
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 |
" |
4260 | 76 |
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
|
77 |
|
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
78 |
[author:] |
4260 | 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 |
|
4777 | 230 |
compress:anUncompressedByteArrayOrString into:aCompressedByteArrayOrString |
4260 | 231 |
^ self |
4777 | 232 |
flatBytesIn:anUncompressedByteArrayOrString |
233 |
from:1 to:(anUncompressedByteArrayOrString size) |
|
234 |
into:aCompressedByteArrayOrString |
|
235 |
doCompress:true. |
|
236 |
||
237 |
" |
|
238 |
|buffer len1 len2 compressed uncompressed| |
|
239 |
buffer := String new:100. |
|
240 |
len1 := self compress:'hello world hello world hello world hello world hello world' into:buffer. |
|
241 |
compressed := buffer copyTo:len1. |
|
242 |
||
243 |
len2 := self uncompress:compressed into:buffer. |
|
244 |
uncompressed := buffer copyTo:len2. |
|
245 |
" |
|
246 |
||
247 |
"Modified (format): / 18-12-2018 / 12:53:17 / Claus Gittinger" |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
248 |
! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
249 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
250 |
flatBytesIn:bytesIn from:start to:stop into:bytesOut doCompress:doCompress |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
251 |
"compress or uncompress the bytesIn buffer into the bytesOut buffer; returns |
4179 | 252 |
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
|
253 |
|
4179 | 254 |
|errorNr| |
255 |
||
256 |
((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
|
257 |
^ self error:'invalid argument size' |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
258 |
]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
259 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
260 |
%{ |
4179 | 261 |
if (__bothSmallInteger(start, stop)) { |
262 |
uLong __start = __intVal(start); |
|
263 |
uLong __stop = __intVal(stop); |
|
264 |
uLong __countIn = __stop - __start + 1; |
|
265 |
char *__bytesIn; |
|
266 |
char *__bytesOut; |
|
267 |
uLong __countOut; |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
268 |
|
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
269 |
if (__isBytes(bytesIn)) { |
4179 | 270 |
__bytesIn = __byteArrayVal(bytesIn); |
271 |
} else if (__isStringLike(bytesIn)) { |
|
272 |
__bytesIn = __stringVal(bytesIn); |
|
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
273 |
} |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
274 |
|
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
275 |
if (__isBytes(bytesOut)) { |
4179 | 276 |
__bytesOut = __byteArrayVal(bytesOut); |
277 |
__countOut = __byteArraySize(bytesOut); |
|
278 |
} else if (__isString(bytesOut)) { |
|
279 |
__bytesOut = __stringVal(bytesOut); |
|
280 |
__countOut = __stringSize(bytesOut); |
|
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
281 |
} |
4179 | 282 |
|
283 |
if (__bytesOut && __bytesIn && __countOut > 0) { |
|
284 |
int __result; |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
285 |
|
4179 | 286 |
__bytesIn += __intVal(start) - 1; |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
287 |
|
4179 | 288 |
__result = (doCompress == true) |
289 |
? compress ((Byte *) __bytesOut, &__countOut, (Byte *) __bytesIn, __countIn) |
|
290 |
: uncompress((Byte *) __bytesOut, &__countOut, (Byte *) __bytesIn, __countIn); |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
291 |
|
4179 | 292 |
if (__result == Z_OK) { |
293 |
RETURN(__MKSMALLINT(__countOut)); |
|
294 |
} |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
295 |
|
4179 | 296 |
errorNr = __MKSMALLINT(__result); |
297 |
} |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
298 |
} |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
299 |
%}. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
300 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
301 |
errorNr isNil ifTrue:[ ^ self error:'invalid arguments' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
302 |
errorNr == 1 ifTrue:[ ^ self error:'stream at end' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
303 |
errorNr == -3 ifTrue:[ ^ self error:'input data are corrupted' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
304 |
errorNr == -4 ifTrue:[ ^ self error:'not enough memory' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
305 |
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
|
306 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
307 |
self error:('compressing error: ', errorNr printString). |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
308 |
! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
309 |
|
4777 | 310 |
uncompress:aCompressedByteArrayOrString into:anUncompressedByteArrayOrString |
4260 | 311 |
^ self |
4777 | 312 |
flatBytesIn:aCompressedByteArrayOrString |
313 |
from:1 to:(aCompressedByteArrayOrString size) |
|
314 |
into:anUncompressedByteArrayOrString |
|
315 |
doCompress:false. |
|
316 |
||
317 |
"Modified (format): / 18-12-2018 / 12:53:09 / Claus Gittinger" |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
318 |
! ! |
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 |
!ZipStream class methodsFor:'ZipInterface compatibility - crc'! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
321 |
|
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
322 |
crc32Add:aCharacterOrByte crc:crc |
4179 | 323 |
"Update a running crc with aCharacterOrByte |
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
324 |
and return the updated crc " |
4179 | 325 |
%{ /* NOCONTEXT */ |
326 |
if (__isInteger(crc)) { |
|
327 |
int __int; |
|
328 |
char __byte; |
|
329 |
uLong __crc; |
|
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
330 |
|
4179 | 331 |
if (__isCharacter(aCharacterOrByte)) { |
332 |
__int = __smallIntegerVal(__characterVal(aCharacterOrByte)); |
|
333 |
} else if (__isSmallInteger(aCharacterOrByte)) { |
|
334 |
__int = __smallIntegerVal(aCharacterOrByte); |
|
335 |
} else{ |
|
336 |
goto err; |
|
337 |
} |
|
338 |
if (__int < 0 || __int > 255) goto err; |
|
339 |
__byte = __int; |
|
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
340 |
|
4179 | 341 |
__crc = __unsignedLongIntVal( crc ); |
342 |
__crc = crc32(__crc, (Byte *) &__byte, 1 ); |
|
343 |
RETURN( __MKUINT(__crc) ); |
|
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
344 |
} |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
345 |
err:; |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
346 |
%}. |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
347 |
|
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
348 |
^ self error:'invalid argument' |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
349 |
! |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
350 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
351 |
crc32BytesIn:bytesIn from:start to:stop crc:crc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
352 |
"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
|
353 |
and return the updated crc" |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
354 |
|
4179 | 355 |
%{ /* NOCONTEXT */ |
356 |
if (__isInteger(crc) && __bothSmallInteger(start, stop)) { |
|
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
357 |
char * __bytes = 0; |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
358 |
unsigned int __size; |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
359 |
uLong __crc = __unsignedLongIntVal( crc ); |
4179 | 360 |
int __start = __intVal( start ); |
361 |
int __stop = __intVal( stop ); |
|
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 |
if (__isBytes(bytesIn)) { |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
364 |
__bytes = __byteArrayVal(bytesIn); |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
365 |
__size = __byteArraySize(bytesIn); |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
366 |
} else if (__isStringLike(bytesIn)) { |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
367 |
__bytes = __stringVal(bytesIn); |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
368 |
__size = __stringSize(bytesIn); |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
369 |
} else { |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
370 |
goto err; |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
371 |
} |
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
372 |
|
4179 | 373 |
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
|
374 |
|
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
375 |
__size = __stop - __start + 1; |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
376 |
__bytes += __start - 1; |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
377 |
__crc = crc32(__crc, (Byte *) __bytes, __size ); |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
378 |
|
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
379 |
RETURN( __MKUINT(__crc) ); |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
380 |
} |
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
381 |
err:; |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
382 |
%}. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
383 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
384 |
^ self error:'invalid argument size' |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
385 |
! ! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
386 |
|
2639 | 387 |
!ZipStream class methodsFor:'queries'! |
388 |
||
389 |
maxDistanceCodes |
|
390 |
^ 30 |
|
391 |
||
392 |
"Created: / 11-09-2011 / 17:11:36 / cg" |
|
393 |
! |
|
394 |
||
395 |
maxLiteralCodes |
|
396 |
^ 286 |
|
397 |
||
398 |
"Created: / 11-09-2011 / 17:11:15 / cg" |
|
399 |
! ! |
|
400 |
||
1045 | 401 |
!ZipStream methodsFor:'low level'! |
402 |
||
403 |
zclose |
|
1052 | 404 |
"low level close of the zip stream |
405 |
" |
|
1045 | 406 |
%{ |
407 |
OBJ _zstreamObj = __INST( zstream ); |
|
408 |
||
409 |
if( _zstreamObj != nil ) |
|
410 |
{ |
|
1828 | 411 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
1045 | 412 |
|
1828 | 413 |
__INST(zstream) = nil; |
1045 | 414 |
|
1828 | 415 |
if( _zstream->stream.state != NULL ) |
416 |
{ |
|
417 |
if( _zstream->op_mode == e_opmode_inflate ) |
|
418 |
inflateEnd( & _zstream->stream ); |
|
419 |
else |
|
420 |
deflateEnd( & _zstream->stream ); |
|
421 |
} |
|
422 |
free( _zstream ); |
|
1045 | 423 |
} |
424 |
%}. |
|
425 |
! |
|
426 |
||
1057 | 427 |
zdeflate |
1570 | 428 |
"low level - deflate" |
429 |
||
1045 | 430 |
|errorNo| |
431 |
errorNo := nil. |
|
432 |
||
4694 | 433 |
%{ /* STACK: 102400 */ |
1045 | 434 |
OBJ _zstreamObj = __INST( zstream ); |
435 |
||
1056 | 436 |
if( _zstreamObj != nil ) |
1045 | 437 |
{ |
4694 | 438 |
int _errorNo, _action; |
439 |
uLong _bfsize; |
|
440 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1047 | 441 |
|
4694 | 442 |
if( _zstream->op_mode != e_opmode_deflate ) |
443 |
RETURN( false ); |
|
1051 | 444 |
|
4694 | 445 |
_bfsize = _zstream->out_total; |
1051 | 446 |
|
4694 | 447 |
if( _zstream->stream.state == NULL ) |
448 |
{ |
|
449 |
/* processing finished; write crc_32 and the total size |
|
450 |
*/ |
|
451 |
uLong v, i; |
|
452 |
Bytef * p = _zstream->out_ref; |
|
1051 | 453 |
|
4694 | 454 |
v = _zstream->crc_32; |
455 |
for( i = 0; i < 4; ++i ) { p[i] = v & 0xff; v >>= 8; } |
|
1051 | 456 |
|
4694 | 457 |
v = _zstream->stream.total_in; |
458 |
for( i = 4; i < 8; ++i ) { p[i] = v & 0xff; v >>= 8; } |
|
1051 | 459 |
|
4694 | 460 |
_zstream->op_mode = e_opmode_unspecified; |
461 |
_zstream->stream.avail_in = 0; |
|
462 |
_zstream->stream.next_in = Z_NULL; |
|
463 |
_zstream->stream.avail_out = _bfsize - 8; |
|
464 |
RETURN( true ); |
|
465 |
} |
|
466 |
_zstream->stream.avail_out = _bfsize; |
|
467 |
_zstream->stream.next_out = _zstream->out_ref; |
|
1056 | 468 |
|
4694 | 469 |
_action = (__INST(hitEOF) == true) ? Z_FINISH : Z_NO_FLUSH; |
470 |
_errorNo = deflate( & _zstream->stream, _action ); |
|
1045 | 471 |
|
4694 | 472 |
if( _errorNo == Z_STREAM_END ) |
473 |
{ |
|
474 |
_zstream->stream.avail_in = 0; |
|
475 |
_zstream->stream.next_in = Z_NULL; |
|
476 |
_errorNo = deflateEnd( & _zstream->stream ); |
|
477 |
} |
|
1045 | 478 |
|
4694 | 479 |
if( _errorNo == Z_OK ) |
480 |
{ |
|
481 |
if( _zstream->stream.avail_out == 0 ) |
|
482 |
RETURN( true ); |
|
1050 | 483 |
|
4694 | 484 |
RETURN( false ); |
485 |
} |
|
486 |
errorNo = __MKSMALLINT( _errorNo ); |
|
1045 | 487 |
} |
488 |
%}. |
|
4054 | 489 |
errorNo isNil ifTrue:[ |
4694 | 490 |
zstream isNil ifTrue:[self errorNotOpen]. |
491 |
self invalidArgument. |
|
1045 | 492 |
]. |
493 |
self zerror:errorNo. |
|
4694 | 494 |
|
495 |
"Modified: / 05-07-2018 / 19:38:45 / Stefan Vogel" |
|
1045 | 496 |
! |
497 |
||
1059 | 498 |
zdeflateInit |
1570 | 499 |
"low level - deflateInit" |
500 |
||
2193 | 501 |
|errorNo level windowBits| |
1045 | 502 |
|
503 |
errorNo := nil. |
|
1059 | 504 |
level := BlockSize. |
2193 | 505 |
windowBits := self zget_windowBits. |
506 |
||
1045 | 507 |
%{ |
508 |
OBJ _zstreamObj = __INST( zstream ); |
|
509 |
||
1059 | 510 |
if( (_zstreamObj != nil) && __isSmallInteger(level) ) |
1045 | 511 |
{ |
1828 | 512 |
int _errorNo; |
513 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1045 | 514 |
|
1828 | 515 |
_zstream->op_mode = e_opmode_deflate; |
1051 | 516 |
|
1828 | 517 |
_errorNo = deflateInit2( & _zstream->stream |
518 |
, __intVal( level ) |
|
519 |
, Z_DEFLATED |
|
2193 | 520 |
, __intVal( windowBits ) |
1828 | 521 |
, DEF_MEM_LEVEL |
522 |
, Z_DEFAULT_STRATEGY |
|
523 |
); |
|
1045 | 524 |
|
1828 | 525 |
if( _errorNo == Z_OK ) |
526 |
RETURN( self ); |
|
1045 | 527 |
|
1828 | 528 |
errorNo = __MKSMALLINT( _errorNo ); |
1045 | 529 |
} |
530 |
%}. |
|
4054 | 531 |
errorNo isNil ifTrue:[ |
532 |
zstream isNil ifTrue:[ self errorNotOpen ]. |
|
1828 | 533 |
self invalidArgument . |
1045 | 534 |
]. |
535 |
self zerror:errorNo. |
|
536 |
! |
|
537 |
||
1059 | 538 |
zget_avail_out |
539 |
"low level - get the number of available out bytes |
|
540 |
" |
|
541 |
%{ |
|
542 |
OBJ _zstreamObj = __INST( zstream ); |
|
543 |
||
544 |
if( _zstreamObj != nil ) |
|
545 |
{ |
|
1195 | 546 |
uInt _count; |
547 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1059 | 548 |
|
1195 | 549 |
_count = _zstream->out_total - _zstream->stream.avail_out; |
1059 | 550 |
|
1195 | 551 |
RETURN( __MKSMALLINT (_count) ); |
1059 | 552 |
} |
553 |
%}. |
|
554 |
self errorNotOpen. |
|
555 |
! |
|
556 |
||
2193 | 557 |
zget_windowBits |
558 |
"answer the bits used for inflateInit2 or deflateInit2... |
|
559 |
a negative WindowBits value suppresses the zlib header and the checksum..." |
|
560 |
||
561 |
|windowBits| |
|
562 |
%{ |
|
563 |
windowBits = __MKSMALLINT( MAX_WBITS ); |
|
564 |
%}. |
|
565 |
||
566 |
self isHeaderAndChecksumSuppressed ifTrue:[ |
|
567 |
"/ undocumented feature..... |
|
568 |
^ windowBits negated |
|
569 |
]. |
|
570 |
^ windowBits |
|
571 |
! |
|
572 |
||
1050 | 573 |
zinflate |
1052 | 574 |
"low level - inflate |
575 |
" |
|
1061 | 576 |
|errorNo tailError| |
1050 | 577 |
|
1061 | 578 |
tailError := nil. |
579 |
errorNo := nil. |
|
4694 | 580 |
%{ /* STACK: 102400 */ |
1050 | 581 |
OBJ _zstreamObj = __INST( zstream ); |
582 |
||
583 |
if( _zstreamObj != nil ) |
|
584 |
{ |
|
4694 | 585 |
int _errorNo, _count; |
586 |
zstream_s * _zstream; |
|
587 |
int _avail_in; |
|
1050 | 588 |
|
4694 | 589 |
_zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
1050 | 590 |
|
4694 | 591 |
if( _zstream->op_mode != e_opmode_inflate ) |
592 |
RETURN( nil ); |
|
1051 | 593 |
|
4694 | 594 |
_avail_in = _zstream->stream.avail_in; |
1061 | 595 |
|
4694 | 596 |
if( _zstream->stream.state == NULL ) |
597 |
{ |
|
598 |
/* processing finished : check crc and data length */ |
|
599 |
Bytef * _next_in; |
|
600 |
Bytef * _buff; |
|
601 |
uLong _tnum; |
|
602 |
int _i; |
|
1061 | 603 |
|
4694 | 604 |
_next_in = _zstream->stream.next_in; |
605 |
_buff = _zstream->tail_buff; |
|
606 |
_tnum = _zstream->tail_size; |
|
1061 | 607 |
|
4694 | 608 |
while( (_avail_in > 0) && (_tnum < 8) ) |
609 |
{ |
|
610 |
_buff[_tnum] = * _next_in; |
|
1061 | 611 |
|
4694 | 612 |
++_next_in; |
613 |
++_tnum; |
|
614 |
--_avail_in; |
|
615 |
} |
|
616 |
_zstream->tail_size = _tnum; |
|
1061 | 617 |
|
4694 | 618 |
if( _tnum < 8 ) /* test whether tail is read */ |
619 |
RETURN( __MKSMALLINT (0) ); /* need more data */ |
|
1061 | 620 |
|
4694 | 621 |
/* compute and check crc */ |
622 |
for( _tnum = 0, _i = 4; --_i >= 0; _tnum = (_tnum << 8) + _buff[_i] ); |
|
1061 | 623 |
|
4694 | 624 |
if( _tnum != _zstream->crc_32 ) |
625 |
{ tailError = __MKSMALLINT( 1 ); goto badTail; } |
|
1061 | 626 |
|
4694 | 627 |
/* compute and check data length */ |
628 |
for( _tnum = 0, _i = 8; --_i >= 4; _tnum = (_tnum << 8) + _buff[_i] ); |
|
1061 | 629 |
|
4694 | 630 |
if( _zstream->stream.total_out != _tnum ) |
631 |
{ tailError = __MKSMALLINT( 2 ); goto badTail; } |
|
1051 | 632 |
|
4694 | 633 |
_zstream->op_mode = e_opmode_unspecified; |
634 |
RETURN( nil ); |
|
635 |
} |
|
636 |
if( _avail_in == 0 ) |
|
637 |
RETURN( __MKSMALLINT (0) ); |
|
1050 | 638 |
|
4694 | 639 |
_zstream->stream.avail_out = _zstream->out_total; |
640 |
_zstream->stream.next_out = _zstream->out_ref; |
|
1050 | 641 |
|
4694 | 642 |
_errorNo = inflate( & _zstream->stream, Z_NO_FLUSH ); |
1050 | 643 |
|
4694 | 644 |
if( _errorNo == Z_STREAM_END ) |
645 |
_errorNo = inflateEnd( & _zstream->stream ); |
|
1050 | 646 |
|
4694 | 647 |
if( _errorNo == Z_OK ) |
648 |
{ |
|
649 |
_count = _zstream->out_total - _zstream->stream.avail_out; |
|
1051 | 650 |
|
4694 | 651 |
if( _count > 0 ) |
652 |
_zstream->crc_32 = crc32( _zstream->crc_32, _zstream->out_ref, _count ); |
|
1051 | 653 |
|
4694 | 654 |
RETURN( __MKSMALLINT (_count) ); |
655 |
} |
|
656 |
errorNo = __MKSMALLINT( _errorNo ); |
|
1050 | 657 |
} |
1061 | 658 |
badTail:; |
1050 | 659 |
%}. |
4054 | 660 |
errorNo isNil ifTrue:[ |
4694 | 661 |
tailError ifNotNil:[ |
662 |
tailError == 1 ifTrue:[ |
|
663 |
self zerror:'invalid compressed data--crc error' |
|
664 |
]. |
|
665 |
self zerror:'invalid compressed data--length error' |
|
666 |
]. |
|
667 |
self errorNotOpen |
|
1061 | 668 |
]. |
1050 | 669 |
self zerror:errorNo. |
4694 | 670 |
|
671 |
"Modified: / 05-07-2018 / 19:06:33 / Stefan Vogel" |
|
1050 | 672 |
! |
673 |
||
1045 | 674 |
zinflateInit |
1052 | 675 |
"low level - inflateInit |
676 |
" |
|
2193 | 677 |
|errorNo windowBits| |
1045 | 678 |
|
679 |
errorNo := nil. |
|
2193 | 680 |
windowBits := self zget_windowBits. |
1045 | 681 |
|
682 |
%{ |
|
683 |
OBJ _zstreamObj = __INST( zstream ); |
|
684 |
||
685 |
if( _zstreamObj != nil ) |
|
686 |
{ |
|
1195 | 687 |
int _errorNo; |
688 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1045 | 689 |
|
1195 | 690 |
_zstream->op_mode = e_opmode_inflate; |
2193 | 691 |
_errorNo = inflateInit2 ( & _zstream->stream |
692 |
, __intVal( windowBits ) |
|
693 |
); |
|
1045 | 694 |
|
1195 | 695 |
if( _errorNo == Z_OK ) |
696 |
RETURN( self ); |
|
1045 | 697 |
|
1195 | 698 |
_zstream->stream.avail_in = 0; |
699 |
errorNo = __MKSMALLINT( _errorNo ); |
|
1045 | 700 |
} |
701 |
%}. |
|
4054 | 702 |
errorNo isNil ifTrue:[ self errorNotOpen ]. |
1045 | 703 |
self zerror:errorNo. |
704 |
! |
|
1047 | 705 |
|
1059 | 706 |
zopen |
1052 | 707 |
"low level - opens the zip stream |
708 |
" |
|
1051 | 709 |
|outTotal| |
1045 | 710 |
|
1059 | 711 |
outTotal := outputBytes size. |
1045 | 712 |
%{ |
713 |
zstream_s * _zstream = (zstream_s *) malloc( sizeof(zstream_s) ); |
|
714 |
||
715 |
if( _zstream ) |
|
716 |
{ |
|
1195 | 717 |
OBJ _zobj = __MKEXTERNALADDRESS( _zstream ); |
718 |
OBJ _outObj = __INST( outputBytes ); |
|
719 |
OBJ _inpObj = __INST( inputBytes ); |
|
1045 | 720 |
|
1195 | 721 |
zmemzero( _zstream, sizeof(zstream_s) ); |
1045 | 722 |
|
1195 | 723 |
_zstream->in_ref = (Bytef *) __externalBytesAddress( _inpObj ); |
724 |
_zstream->stream.next_in = Z_NULL; |
|
725 |
_zstream->stream.avail_in = 0; |
|
726 |
_zstream->stream.total_in = 0; |
|
1045 | 727 |
|
1195 | 728 |
_zstream->out_total = __intVal( outTotal ); |
729 |
_zstream->out_ref = (Bytef *) __externalBytesAddress( _outObj ); |
|
730 |
_zstream->stream.next_out = _zstream->out_ref; |
|
731 |
_zstream->stream.avail_out = _zstream->out_total; |
|
732 |
_zstream->stream.total_out = 0; |
|
1045 | 733 |
|
1195 | 734 |
_zstream->stream.zalloc = (alloc_func)0; |
735 |
_zstream->stream.zfree = (free_func) 0; |
|
736 |
_zstream->stream.opaque = (voidpf) 0; |
|
1045 | 737 |
|
1195 | 738 |
_zstream->crc_32 = crc32( 0L, Z_NULL, 0 ); |
739 |
_zstream->op_mode = e_opmode_unspecified; |
|
740 |
_zstream->tail_size = 0; |
|
1045 | 741 |
|
1195 | 742 |
__INST (zstream) = _zobj; |
743 |
__STORE(self, _zobj); |
|
1045 | 744 |
} |
745 |
%}. |
|
746 |
! |
|
747 |
||
1059 | 748 |
zset_avail_in:count |
1570 | 749 |
"set the 'avail_in' and compute the crc" |
1059 | 750 |
%{ |
751 |
OBJ _zstreamObj = __INST( zstream ); |
|
1045 | 752 |
|
1059 | 753 |
if( (_zstreamObj != nil) && __isSmallInteger(count) ) |
754 |
{ |
|
1828 | 755 |
int _count; |
756 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1045 | 757 |
|
1828 | 758 |
if( (_count = __intVal( count )) > 0 ) |
759 |
{ |
|
760 |
Bytef * _in_ref = _zstream->in_ref; |
|
1045 | 761 |
|
1828 | 762 |
_zstream->stream.avail_in = _count; |
763 |
_zstream->stream.next_in = _in_ref; |
|
1045 | 764 |
|
1828 | 765 |
if( _zstream->op_mode == e_opmode_deflate ) |
766 |
_zstream->crc_32 = crc32( _zstream->crc_32, _in_ref, _count ); |
|
767 |
} else { |
|
768 |
_zstream->stream.avail_in = 0; |
|
769 |
_zstream->stream.next_in = Z_NULL; |
|
770 |
} |
|
771 |
RETURN( self ); |
|
1059 | 772 |
} |
773 |
%}. |
|
4054 | 774 |
zstream isNil ifTrue:[ self errorNotOpen ]. |
1570 | 775 |
self invalidArgument. |
1045 | 776 |
! ! |
777 |
||
778 |
!ZipStream methodsFor:'startup & release'! |
|
779 |
||
3535 | 780 |
openWithMode:aMode on:aStream suppressFileHeader:suppressFileHeader suppressZipHeaderAndChecksum:suppressZipHeaderAndChecksum |
781 |
"open stream and write or check gzip header |
|
782 |
suppressFileHeader: |
|
783 |
if true, the gzip header (magic number and a few extra fields) is not written/read |
|
784 |
suppressZipHeaderAndChecksum |
|
785 |
controls if the gzip checksum and 2 header bytes should be written/checked" |
|
2019 | 786 |
|
2196 | 787 |
super |
788 |
openWithMode:aMode |
|
789 |
on:aStream |
|
3535 | 790 |
suppressHeaderAndChecksum:suppressZipHeaderAndChecksum. |
2019 | 791 |
|
4263 | 792 |
suppressZipHeaderAndChecksum ifFalse:[ |
793 |
suppressFileHeader ifFalse:[ |
|
794 |
self isReadable ifTrue:[ |
|
795 |
"Check for the gzip magic id" |
|
796 |
self readHeader |
|
797 |
] ifFalse:[ |
|
798 |
"write the gzip magic id" |
|
799 |
self writeHeader |
|
800 |
]. |
|
3535 | 801 |
]. |
2019 | 802 |
]. |
803 |
! |
|
1045 | 804 |
|
3535 | 805 |
openWithMode:aMode on:aStream suppressHeaderAndChecksum:aBoolean |
806 |
"open stream and write or check gzip header. |
|
807 |
Caveat: |
|
808 |
Backward compatibility: aBoolean controls if the gzip checksum and 2 header bytes should be written/checked |
|
809 |
(i.e. NOT the file header with the zip magic)" |
|
810 |
||
4054 | 811 |
self |
812 |
openWithMode:aMode |
|
813 |
on:aStream |
|
814 |
suppressFileHeader:false |
|
3535 | 815 |
suppressZipHeaderAndChecksum:aBoolean |
816 |
! |
|
817 |
||
2019 | 818 |
readHeader |
819 |
"Check for the gzip magic id" |
|
820 |
|flags| |
|
1045 | 821 |
|
2019 | 822 |
GZ_MAGIC_ID do:[:b| |
3283 | 823 |
onStream nextByte ~~ b ifTrue:[ self zerror:'version error' ] |
2019 | 824 |
]. |
825 |
||
826 |
onStream nextByte ~~ Z_DEFLATED ifTrue:[ |
|
3283 | 827 |
self zerror:'invalid method (not deflated)' |
2019 | 828 |
]. |
1045 | 829 |
|
2019 | 830 |
flags := onStream nextByte. |
831 |
(flags bitAnd:HEAD_RESERVED) ~~ 0 ifTrue:[ |
|
3283 | 832 |
self zerror:'wrong data format' |
2019 | 833 |
]. |
1045 | 834 |
|
2019 | 835 |
"discard time, xflags and OS code" |
836 |
onStream skip:6. |
|
1045 | 837 |
|
3535 | 838 |
(flags bitAnd:HEAD_EXTRA_FIELD) ~~ 0 ifTrue:[ |
839 |
|len| |
|
3283 | 840 |
"skip the extra field" |
841 |
len := onStream nextByte + (onStream nextByte bitShift:8). |
|
3535 | 842 |
"/ len timesRepeat:[ onStream nextByte ]. |
843 |
"/ faster: |
|
844 |
onStream skip:len. |
|
2019 | 845 |
]. |
1050 | 846 |
|
3283 | 847 |
(flags bitAnd:HEAD_ORIG_NAME) ~~ 0 ifTrue:[ |
848 |
|b| |
|
3535 | 849 |
"skip the original file name (up to zero byte)" |
3283 | 850 |
[ (b := onStream nextByte) ~~ 0 ] whileTrue. |
2019 | 851 |
]. |
852 |
||
853 |
(flags bitAnd:HEAD_CRC) ~~ 0 ifTrue:[ |
|
3283 | 854 |
"skip the header crc" |
855 |
onStream skip:2. |
|
2019 | 856 |
]. |
857 |
! |
|
1050 | 858 |
|
2019 | 859 |
writeHeader |
1059 | 860 |
|
4054 | 861 |
"write the gzip magic id" |
3283 | 862 |
onStream nextPutBytes:GZ_MAGIC_ID. |
2019 | 863 |
|
864 |
"write the method" |
|
865 |
onStream nextPutByte:Z_DEFLATED. |
|
1050 | 866 |
|
3283 | 867 |
onStream nextPutBytes:#[ |
4054 | 868 |
0 "write the flags" |
3283 | 869 |
0 0 0 0 "write time" |
870 |
0 "write xflags" |
|
871 |
]. |
|
1059 | 872 |
|
2019 | 873 |
"write OS code" |
874 |
onStream nextPutByte:HEAD_OS_CODE. |
|
1045 | 875 |
! ! |
1044 | 876 |
|
877 |
!ZipStream class methodsFor:'documentation'! |
|
878 |
||
879 |
version |
|
4054 | 880 |
^ '$Header$' |
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
881 |
! |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
882 |
|
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
883 |
version_CVS |
4054 | 884 |
^ '$Header$' |
1044 | 885 |
! ! |
1193 | 886 |
|
3283 | 887 |
|
1047 | 888 |
ZipStream initialize! |