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