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