author | sr |
Tue, 31 Aug 2010 10:29:28 +0200 | |
changeset 2488 | 702fc73e1b3c |
parent 2335 | 609923563c1d |
child 2489 | 9a520f4a1d6a |
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 |
|
2488 | 105 |
[ (c := zipStream next) notNil ] whileTrue:[ |
106 |
stream nextPut:c |
|
107 |
]. |
|
108 |
stream close. |
|
109 |
uncompressedData := stream contents. |
|
1847 | 110 |
]. |
111 |
^ uncompressedData |
|
2488 | 112 |
[exEnd] |
1847 | 113 |
|
114 |
||
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
115 |
" |
2488 | 116 |
! |
117 |
||
118 |
examples2 |
|
119 |
|file fstream zipStream c| |
|
120 |
||
121 |
file := 'C:\gg.zip' asFilename. |
|
122 |
file exists ifTrue:[ file delete ]. |
|
123 |
||
124 |
fstream := file writeStream. |
|
125 |
zipStream := ZipStream writeOpenOn:fstream. |
|
126 |
zipStream nextPutAll:'hallo Welt(1) - test....'. |
|
127 |
zipStream cr. |
|
128 |
zipStream nextPutAll:'hallo Welt(2) - test....'. |
|
129 |
zipStream cr. |
|
130 |
||
131 |
zipStream close. |
|
132 |
fstream close. |
|
133 |
||
134 |
fstream := file readStream. |
|
135 |
zipStream := ZipStream readOpenOn:fstream. |
|
136 |
||
137 |
[ (c := zipStream next) notNil ] whileTrue:[ |
|
138 |
Transcript show:c. |
|
139 |
]. |
|
140 |
Transcript cr. |
|
141 |
zipStream close. |
|
142 |
fstream close. |
|
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 |
|
1061 | 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 |
! ! |
|
168 |
||
2006
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
169 |
!ZipStream class methodsFor:'instance creation'! |
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
170 |
|
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
171 |
readOpenAsZipStreamOn:aStream |
2190 | 172 |
"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
|
173 |
the default readOpenOn: will open ZipStream as gzip stream" |
2196 | 174 |
|
175 |
^ self |
|
176 |
readOpenAsZipStreamOn:aStream |
|
177 |
suppressHeaderAndChecksum:(self defaultSuppressHeaderAndChecksum) |
|
178 |
! |
|
179 |
||
180 |
readOpenAsZipStreamOn:aStream suppressHeaderAndChecksum:aBoolean |
|
181 |
"open to read data compressed from stream, |
|
182 |
the default readOpenOn: will open ZipStream as gzip stream" |
|
183 |
||
184 |
^ self basicNew |
|
185 |
streamOpenWithMode:#readonly |
|
186 |
on:aStream |
|
187 |
suppressHeaderAndChecksum:aBoolean |
|
2006
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
188 |
! |
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
189 |
|
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
190 |
writeOpenAsZipStreamOn:aStream |
2190 | 191 |
"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
|
192 |
the default writeOpenOn: will open ZipStream as gzip stream" |
2196 | 193 |
|
194 |
^ self |
|
195 |
writeOpenAsZipStreamOn:aStream |
|
196 |
suppressHeaderAndChecksum:(self defaultSuppressHeaderAndChecksum) |
|
197 |
! |
|
198 |
||
199 |
writeOpenAsZipStreamOn:aStream suppressHeaderAndChecksum:aBoolean |
|
200 |
"open to write data compressed to stream, |
|
201 |
the default writeOpenOn: will open ZipStream as gzip stream" |
|
202 |
||
203 |
^ self basicNew |
|
204 |
streamOpenWithMode:#writeonly |
|
205 |
on:aStream |
|
206 |
suppressHeaderAndChecksum:aBoolean |
|
2006
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
207 |
! ! |
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
208 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
209 |
!ZipStream class methodsFor:'ZipInterface compatibility - compress/uncompress'! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
210 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
211 |
compress: aUncompressedByteArray into: aCompressedByteArray |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
212 |
^ self flatBytesIn: aUncompressedByteArray |
1828 | 213 |
from: 1 |
214 |
to: (aUncompressedByteArray size) |
|
215 |
into: aCompressedByteArray |
|
216 |
doCompress: true. |
|
1439
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 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
219 |
flatBytesIn:bytesIn from:start to:stop into:bytesOut doCompress:doCompress |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
220 |
"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
|
221 |
the un/compressed size; on error an exception is raised |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
222 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
223 |
|errorNr size| |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
224 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
225 |
size := stop - start + 1. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
226 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
227 |
( (start between:1 and:stop) |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
228 |
and:[size > 0 |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
229 |
and:[bytesIn size >= stop |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
230 |
and:[bytesOut size > 0]]] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
231 |
) ifFalse:[ |
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
232 |
^ self error:'invalid argument size' |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
233 |
]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
234 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
235 |
%{ |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
236 |
char * __bytesIn = 0; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
237 |
uLong __countIn = 0; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
238 |
char * __bytesOut = 0; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
239 |
uLong __countOut = 0; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
240 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
241 |
if( (__isSmallInteger(start)) && (__isSmallInteger(stop)) && (__isSmallInteger(size)) ) |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
242 |
{ |
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
243 |
__countIn = __intVal( size ); |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
244 |
|
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
245 |
if (__isBytes(bytesIn)) { |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
246 |
__bytesIn = __ByteArrayInstPtr(bytesIn)->ba_element; |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
247 |
} else { |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
248 |
if (__isStringLike(bytesIn)) { |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
249 |
__bytesIn = __stringVal( bytesIn ); |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
250 |
} |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
251 |
} |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
252 |
|
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
253 |
if (__isBytes(bytesOut)) { |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
254 |
__bytesOut = __ByteArrayInstPtr(bytesOut)->ba_element; |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
255 |
__countOut = __byteArraySize( bytesOut ); |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
256 |
} else { |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
257 |
if (__isString(bytesOut)) { |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
258 |
__bytesOut = __stringVal( bytesOut ); |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
259 |
__countOut = __stringSize( bytesOut ); |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
260 |
} |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
261 |
} |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
262 |
} |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
263 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
264 |
if( __bytesOut && __bytesIn ) |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
265 |
{ |
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
266 |
int __result = Z_OK; |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
267 |
|
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
268 |
__bytesIn += (__intVal( start)) - 1; |
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( doCompress == true ) |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
271 |
__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
|
272 |
else |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
273 |
__result = uncompress( (Byte *) __bytesOut, & __countOut, (Byte *) __bytesIn, __countIn ); |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
274 |
|
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
275 |
if( __result == Z_OK ) |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
276 |
{ RETURN(__MKSMALLINT(__countOut)); } |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
277 |
|
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
278 |
errorNr = __MKSMALLINT( __result ); |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
279 |
} |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
280 |
%}. |
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 |
errorNr isNil ifTrue:[ ^ self error:'invalid arguments' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
283 |
errorNr == 1 ifTrue:[ ^ self error:'stream at end' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
284 |
errorNr == -3 ifTrue:[ ^ self error:'input data are corrupted' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
285 |
errorNr == -4 ifTrue:[ ^ self error:'not enough memory' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
286 |
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
|
287 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
288 |
self error:('compressing error: ', errorNr printString). |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
289 |
! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
290 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
291 |
uncompress: aCompressedByteArray into: aUncompressedByteArray |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
292 |
^ self flatBytesIn: aCompressedByteArray |
1828 | 293 |
from: 1 |
294 |
to: (aCompressedByteArray size) |
|
295 |
into: aUncompressedByteArray |
|
296 |
doCompress: false. |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
297 |
! ! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
298 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
299 |
!ZipStream class methodsFor:'ZipInterface compatibility - crc'! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
300 |
|
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
301 |
crc32Add:aCharacterOrByte crc:crc |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
302 |
"Update a running crc waCharacterOrByte |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
303 |
and return the updated crc " |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
304 |
%{ |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
305 |
if( (__isInteger(crc))) { |
2190 | 306 |
char __byte; |
307 |
uLong __crc; |
|
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
308 |
|
2190 | 309 |
if (__isCharacter(aCharacterOrByte)) { |
310 |
__byte = __smallIntegerVal(__characterVal(aCharacterOrByte)); |
|
311 |
} else if (__isSmallInteger(aCharacterOrByte)) { |
|
312 |
__byte = __intVal(aCharacterOrByte); |
|
313 |
} else{ |
|
314 |
goto err; |
|
315 |
} |
|
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
316 |
|
2190 | 317 |
__crc = __unsignedLongIntVal( crc ); |
318 |
__crc = crc32(__crc, (Byte *) &__byte, 1 ); |
|
319 |
RETURN( __MKUINT(__crc) ); |
|
2178
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 |
err:; |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
322 |
%}. |
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 |
^ self error:'invalid argument' |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
325 |
! |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
326 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
327 |
crc32BytesIn:bytesIn |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
328 |
"compute crc with the bytes buf[1.. bytesIn size] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
329 |
and return the crc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
330 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
331 |
^ self crc32BytesIn:bytesIn from:1 |
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 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
334 |
crc32BytesIn:bytesIn crc:aCrc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
335 |
"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
|
336 |
and return the updated |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
337 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
338 |
^ self crc32BytesIn:bytesIn from:1 crc:aCrc |
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 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
341 |
crc32BytesIn:bytesIn from:start |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
342 |
"compute crc with the bytes buf[start.. bytesIn size] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
343 |
and return the crc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
344 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
345 |
^ self crc32BytesIn:bytesIn from:start to:(bytesIn size) |
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 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
348 |
crc32BytesIn:bytesIn from:start crc:aCrc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
349 |
"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
|
350 |
and return the updated |
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 |
^ self crc32BytesIn:bytesIn from:start to:(bytesIn size) crc:aCrc |
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 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
355 |
crc32BytesIn:bytesIn from:start to:stop |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
356 |
"compute crc with the bytes buf[start.. stop] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
357 |
and return the crc |
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 |
^ self crc32BytesIn:bytesIn from:start to:stop crc:0 |
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 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
362 |
crc32BytesIn:bytesIn from:start to:stop crc:crc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
363 |
"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
|
364 |
and return the updated crc" |
1439
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 |
%{ |
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
367 |
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
|
368 |
char * __bytes = 0; |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
369 |
unsigned int __size; |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
370 |
uLong __crc = __unsignedLongIntVal( crc ); |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
371 |
uInt __start = __intVal( start ); |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
372 |
uInt __stop = __intVal( stop ); |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
373 |
|
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
374 |
if (__isBytes(bytesIn)) { |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
375 |
__bytes = __byteArrayVal(bytesIn); |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
376 |
__size = __byteArraySize(bytesIn); |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
377 |
} else if (__isStringLike(bytesIn)) { |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
378 |
__bytes = __stringVal(bytesIn); |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
379 |
__size = __stringSize(bytesIn); |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
380 |
} else { |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
381 |
goto err; |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
382 |
} |
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
383 |
|
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 |
if (__start < 1 || __start > __size) goto err; |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
386 |
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
|
387 |
|
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
388 |
__size = __stop - __start + 1; |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
389 |
|
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
390 |
__bytes += __start - 1; |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
391 |
__crc = crc32(__crc, (Byte *) __bytes, __size ); |
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 |
RETURN( __MKUINT(__crc) ); |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
394 |
} |
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
395 |
err:; |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
396 |
%}. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
397 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
398 |
^ self error:'invalid argument size' |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
399 |
! ! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
400 |
|
1045 | 401 |
!ZipStream methodsFor:'low level'! |
402 |
||
403 |
zclose |
|
1052 | 404 |
"low level close of the zip stream |
405 |
" |
|
1045 | 406 |
%{ |
407 |
OBJ _zstreamObj = __INST( zstream ); |
|
408 |
||
409 |
if( _zstreamObj != nil ) |
|
410 |
{ |
|
1828 | 411 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
1045 | 412 |
|
1828 | 413 |
__INST(zstream) = nil; |
1045 | 414 |
|
1828 | 415 |
if( _zstream->stream.state != NULL ) |
416 |
{ |
|
417 |
if( _zstream->op_mode == e_opmode_inflate ) |
|
418 |
inflateEnd( & _zstream->stream ); |
|
419 |
else |
|
420 |
deflateEnd( & _zstream->stream ); |
|
421 |
} |
|
422 |
free( _zstream ); |
|
1045 | 423 |
} |
424 |
%}. |
|
425 |
! |
|
426 |
||
1057 | 427 |
zdeflate |
1570 | 428 |
"low level - deflate" |
429 |
||
1045 | 430 |
|errorNo| |
431 |
errorNo := nil. |
|
432 |
||
433 |
%{ |
|
434 |
OBJ _zstreamObj = __INST( zstream ); |
|
435 |
||
1056 | 436 |
if( _zstreamObj != nil ) |
1045 | 437 |
{ |
1828 | 438 |
int _errorNo, _action; |
439 |
uLong _bfsize; |
|
440 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1047 | 441 |
|
1828 | 442 |
if( _zstream->op_mode != e_opmode_deflate ) |
443 |
RETURN( false ); |
|
1051 | 444 |
|
1828 | 445 |
_bfsize = _zstream->out_total; |
1051 | 446 |
|
1828 | 447 |
if( _zstream->stream.state == NULL ) |
448 |
{ |
|
449 |
/* processing finished; write crc_32 and the total size |
|
450 |
*/ |
|
451 |
uLong v, i; |
|
452 |
Bytef * p = _zstream->out_ref; |
|
1051 | 453 |
|
1828 | 454 |
v = _zstream->crc_32; |
455 |
for( i = 0; i < 4; ++i ) { p[i] = v & 0xff; v >>= 8; } |
|
1051 | 456 |
|
1828 | 457 |
v = _zstream->stream.total_in; |
458 |
for( i = 4; i < 8; ++i ) { p[i] = v & 0xff; v >>= 8; } |
|
1051 | 459 |
|
1828 | 460 |
_zstream->op_mode = e_opmode_unspecified; |
461 |
_zstream->stream.avail_in = 0; |
|
462 |
_zstream->stream.next_in = Z_NULL; |
|
463 |
_zstream->stream.avail_out = _bfsize - 8; |
|
464 |
RETURN( true ); |
|
465 |
} |
|
466 |
_zstream->stream.avail_out = _bfsize; |
|
467 |
_zstream->stream.next_out = _zstream->out_ref; |
|
1056 | 468 |
|
1828 | 469 |
_action = (__INST(hitEOF) == true) ? Z_FINISH : Z_NO_FLUSH; |
470 |
_errorNo = deflate( & _zstream->stream, _action ); |
|
1045 | 471 |
|
1828 | 472 |
if( _errorNo == Z_STREAM_END ) |
473 |
{ |
|
474 |
_zstream->stream.avail_in = 0; |
|
475 |
_zstream->stream.next_in = Z_NULL; |
|
476 |
_errorNo = deflateEnd( & _zstream->stream ); |
|
477 |
} |
|
1045 | 478 |
|
1828 | 479 |
if( _errorNo == Z_OK ) |
480 |
{ |
|
481 |
if( _zstream->stream.avail_out == 0 ) |
|
482 |
RETURN( true ); |
|
1050 | 483 |
|
1828 | 484 |
RETURN( false ); |
485 |
} |
|
486 |
errorNo = __MKSMALLINT( _errorNo ); |
|
1045 | 487 |
} |
488 |
%}. |
|
489 |
errorNo ifNil:[ |
|
1828 | 490 |
zstream ifNil:[self errorNotOpen]. |
491 |
self invalidArgument. |
|
1045 | 492 |
]. |
493 |
self zerror:errorNo. |
|
494 |
! |
|
495 |
||
1059 | 496 |
zdeflateInit |
1570 | 497 |
"low level - deflateInit" |
498 |
||
2193 | 499 |
|errorNo level windowBits| |
1045 | 500 |
|
501 |
errorNo := nil. |
|
1059 | 502 |
level := BlockSize. |
2193 | 503 |
windowBits := self zget_windowBits. |
504 |
||
1045 | 505 |
%{ |
506 |
OBJ _zstreamObj = __INST( zstream ); |
|
507 |
||
1059 | 508 |
if( (_zstreamObj != nil) && __isSmallInteger(level) ) |
1045 | 509 |
{ |
1828 | 510 |
int _errorNo; |
511 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1045 | 512 |
|
1828 | 513 |
_zstream->op_mode = e_opmode_deflate; |
1051 | 514 |
|
1828 | 515 |
_errorNo = deflateInit2( & _zstream->stream |
516 |
, __intVal( level ) |
|
517 |
, Z_DEFLATED |
|
2193 | 518 |
, __intVal( windowBits ) |
1828 | 519 |
, DEF_MEM_LEVEL |
520 |
, Z_DEFAULT_STRATEGY |
|
521 |
); |
|
1045 | 522 |
|
1828 | 523 |
if( _errorNo == Z_OK ) |
524 |
RETURN( self ); |
|
1045 | 525 |
|
1828 | 526 |
errorNo = __MKSMALLINT( _errorNo ); |
1045 | 527 |
} |
528 |
%}. |
|
529 |
errorNo ifNil:[ |
|
1828 | 530 |
zstream ifNil:[ self errorNotOpen ]. |
531 |
self invalidArgument . |
|
1045 | 532 |
]. |
533 |
self zerror:errorNo. |
|
534 |
! |
|
535 |
||
1059 | 536 |
zget_avail_out |
537 |
"low level - get the number of available out bytes |
|
538 |
" |
|
539 |
%{ |
|
540 |
OBJ _zstreamObj = __INST( zstream ); |
|
541 |
||
542 |
if( _zstreamObj != nil ) |
|
543 |
{ |
|
1195 | 544 |
uInt _count; |
545 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1059 | 546 |
|
1195 | 547 |
_count = _zstream->out_total - _zstream->stream.avail_out; |
1059 | 548 |
|
1195 | 549 |
RETURN( __MKSMALLINT (_count) ); |
1059 | 550 |
} |
551 |
%}. |
|
552 |
self errorNotOpen. |
|
553 |
! |
|
554 |
||
2193 | 555 |
zget_windowBits |
556 |
"answer the bits used for inflateInit2 or deflateInit2... |
|
557 |
a negative WindowBits value suppresses the zlib header and the checksum..." |
|
558 |
||
559 |
|windowBits| |
|
560 |
%{ |
|
561 |
windowBits = __MKSMALLINT( MAX_WBITS ); |
|
562 |
%}. |
|
563 |
||
564 |
self isHeaderAndChecksumSuppressed ifTrue:[ |
|
565 |
"/ undocumented feature..... |
|
566 |
^ windowBits negated |
|
567 |
]. |
|
568 |
^ windowBits |
|
569 |
! |
|
570 |
||
1050 | 571 |
zinflate |
1052 | 572 |
"low level - inflate |
573 |
" |
|
1061 | 574 |
|errorNo tailError| |
1050 | 575 |
|
1061 | 576 |
tailError := nil. |
577 |
errorNo := nil. |
|
1050 | 578 |
%{ |
579 |
OBJ _zstreamObj = __INST( zstream ); |
|
580 |
||
581 |
if( _zstreamObj != nil ) |
|
582 |
{ |
|
1195 | 583 |
int _errorNo, _count; |
584 |
zstream_s * _zstream; |
|
585 |
int _avail_in; |
|
1050 | 586 |
|
1195 | 587 |
_zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
1050 | 588 |
|
1195 | 589 |
if( _zstream->op_mode != e_opmode_inflate ) |
590 |
RETURN( nil ); |
|
1051 | 591 |
|
1195 | 592 |
_avail_in = _zstream->stream.avail_in; |
1061 | 593 |
|
1195 | 594 |
if( _zstream->stream.state == NULL ) |
595 |
{ |
|
596 |
/* processing finished : check crc and data length */ |
|
597 |
Bytef * _next_in; |
|
598 |
Bytef * _buff; |
|
599 |
uLong _tnum; |
|
600 |
int _i; |
|
1061 | 601 |
|
1195 | 602 |
_next_in = _zstream->stream.next_in; |
603 |
_buff = _zstream->tail_buff; |
|
604 |
_tnum = _zstream->tail_size; |
|
1061 | 605 |
|
1195 | 606 |
while( (_avail_in > 0) && (_tnum < 8) ) |
607 |
{ |
|
608 |
_buff[_tnum] = * _next_in; |
|
1061 | 609 |
|
1195 | 610 |
++_next_in; |
611 |
++_tnum; |
|
612 |
--_avail_in; |
|
613 |
} |
|
614 |
_zstream->tail_size = _tnum; |
|
1061 | 615 |
|
1195 | 616 |
if( _tnum < 8 ) /* test whether tail is read */ |
617 |
RETURN( __MKSMALLINT (0) ); /* need more data */ |
|
1061 | 618 |
|
1195 | 619 |
/* compute and check crc */ |
620 |
for( _tnum = 0, _i = 4; --_i >= 0; _tnum = (_tnum << 8) + _buff[_i] ); |
|
1061 | 621 |
|
1195 | 622 |
if( _tnum != _zstream->crc_32 ) |
623 |
{ tailError = __MKSMALLINT( 1 ); goto badTail; } |
|
1061 | 624 |
|
1195 | 625 |
/* compute and check data length */ |
626 |
for( _tnum = 0, _i = 8; --_i >= 4; _tnum = (_tnum << 8) + _buff[_i] ); |
|
1061 | 627 |
|
1195 | 628 |
if( _zstream->stream.total_out != _tnum ) |
629 |
{ tailError = __MKSMALLINT( 2 ); goto badTail; } |
|
1051 | 630 |
|
1195 | 631 |
_zstream->op_mode = e_opmode_unspecified; |
632 |
RETURN( nil ); |
|
633 |
} |
|
634 |
if( _avail_in == 0 ) |
|
635 |
RETURN( __MKSMALLINT (0) ); |
|
1050 | 636 |
|
1195 | 637 |
_zstream->stream.avail_out = _zstream->out_total; |
638 |
_zstream->stream.next_out = _zstream->out_ref; |
|
1050 | 639 |
|
1195 | 640 |
_errorNo = inflate( & _zstream->stream, Z_NO_FLUSH ); |
1050 | 641 |
|
1195 | 642 |
if( _errorNo == Z_STREAM_END ) |
643 |
_errorNo = inflateEnd( & _zstream->stream ); |
|
1050 | 644 |
|
1195 | 645 |
if( _errorNo == Z_OK ) |
646 |
{ |
|
647 |
_count = _zstream->out_total - _zstream->stream.avail_out; |
|
1051 | 648 |
|
1195 | 649 |
if( _count > 0 ) |
650 |
_zstream->crc_32 = crc32( _zstream->crc_32, _zstream->out_ref, _count ); |
|
1051 | 651 |
|
1195 | 652 |
RETURN( __MKSMALLINT (_count) ); |
653 |
} |
|
654 |
errorNo = __MKSMALLINT( _errorNo ); |
|
1050 | 655 |
} |
1061 | 656 |
badTail:; |
1050 | 657 |
%}. |
1061 | 658 |
errorNo ifNil:[ |
1195 | 659 |
tailError ifNotNil:[ |
660 |
tailError == 1 ifTrue:[ |
|
661 |
self zerror:'invalid compressed data--crc error' |
|
662 |
]. |
|
663 |
self zerror:'invalid compressed data--length error' |
|
664 |
]. |
|
665 |
self errorNotOpen |
|
1061 | 666 |
]. |
1050 | 667 |
self zerror:errorNo. |
668 |
! |
|
669 |
||
1045 | 670 |
zinflateInit |
1052 | 671 |
"low level - inflateInit |
672 |
" |
|
2193 | 673 |
|errorNo windowBits| |
1045 | 674 |
|
675 |
errorNo := nil. |
|
2193 | 676 |
windowBits := self zget_windowBits. |
1045 | 677 |
|
678 |
%{ |
|
679 |
OBJ _zstreamObj = __INST( zstream ); |
|
680 |
||
681 |
if( _zstreamObj != nil ) |
|
682 |
{ |
|
1195 | 683 |
int _errorNo; |
684 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1045 | 685 |
|
1195 | 686 |
_zstream->op_mode = e_opmode_inflate; |
2193 | 687 |
_errorNo = inflateInit2 ( & _zstream->stream |
688 |
, __intVal( windowBits ) |
|
689 |
); |
|
1045 | 690 |
|
1195 | 691 |
if( _errorNo == Z_OK ) |
692 |
RETURN( self ); |
|
1045 | 693 |
|
1195 | 694 |
_zstream->stream.avail_in = 0; |
695 |
errorNo = __MKSMALLINT( _errorNo ); |
|
1045 | 696 |
} |
697 |
%}. |
|
698 |
errorNo ifNil:[ self errorNotOpen ]. |
|
699 |
self zerror:errorNo. |
|
700 |
! |
|
1047 | 701 |
|
1059 | 702 |
zopen |
1052 | 703 |
"low level - opens the zip stream |
704 |
" |
|
1051 | 705 |
|outTotal| |
1045 | 706 |
|
1059 | 707 |
outTotal := outputBytes size. |
1045 | 708 |
%{ |
709 |
zstream_s * _zstream = (zstream_s *) malloc( sizeof(zstream_s) ); |
|
710 |
||
711 |
if( _zstream ) |
|
712 |
{ |
|
1195 | 713 |
OBJ _zobj = __MKEXTERNALADDRESS( _zstream ); |
714 |
OBJ _outObj = __INST( outputBytes ); |
|
715 |
OBJ _inpObj = __INST( inputBytes ); |
|
1045 | 716 |
|
1195 | 717 |
zmemzero( _zstream, sizeof(zstream_s) ); |
1045 | 718 |
|
1195 | 719 |
_zstream->in_ref = (Bytef *) __externalBytesAddress( _inpObj ); |
720 |
_zstream->stream.next_in = Z_NULL; |
|
721 |
_zstream->stream.avail_in = 0; |
|
722 |
_zstream->stream.total_in = 0; |
|
1045 | 723 |
|
1195 | 724 |
_zstream->out_total = __intVal( outTotal ); |
725 |
_zstream->out_ref = (Bytef *) __externalBytesAddress( _outObj ); |
|
726 |
_zstream->stream.next_out = _zstream->out_ref; |
|
727 |
_zstream->stream.avail_out = _zstream->out_total; |
|
728 |
_zstream->stream.total_out = 0; |
|
1045 | 729 |
|
1195 | 730 |
_zstream->stream.zalloc = (alloc_func)0; |
731 |
_zstream->stream.zfree = (free_func) 0; |
|
732 |
_zstream->stream.opaque = (voidpf) 0; |
|
1045 | 733 |
|
1195 | 734 |
_zstream->crc_32 = crc32( 0L, Z_NULL, 0 ); |
735 |
_zstream->op_mode = e_opmode_unspecified; |
|
736 |
_zstream->tail_size = 0; |
|
1045 | 737 |
|
1195 | 738 |
__INST (zstream) = _zobj; |
739 |
__STORE(self, _zobj); |
|
1045 | 740 |
} |
741 |
%}. |
|
742 |
! |
|
743 |
||
1059 | 744 |
zset_avail_in:count |
1570 | 745 |
"set the 'avail_in' and compute the crc" |
1059 | 746 |
%{ |
747 |
OBJ _zstreamObj = __INST( zstream ); |
|
1045 | 748 |
|
1059 | 749 |
if( (_zstreamObj != nil) && __isSmallInteger(count) ) |
750 |
{ |
|
1828 | 751 |
int _count; |
752 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1045 | 753 |
|
1828 | 754 |
if( (_count = __intVal( count )) > 0 ) |
755 |
{ |
|
756 |
Bytef * _in_ref = _zstream->in_ref; |
|
1045 | 757 |
|
1828 | 758 |
_zstream->stream.avail_in = _count; |
759 |
_zstream->stream.next_in = _in_ref; |
|
1045 | 760 |
|
1828 | 761 |
if( _zstream->op_mode == e_opmode_deflate ) |
762 |
_zstream->crc_32 = crc32( _zstream->crc_32, _in_ref, _count ); |
|
763 |
} else { |
|
764 |
_zstream->stream.avail_in = 0; |
|
765 |
_zstream->stream.next_in = Z_NULL; |
|
766 |
} |
|
767 |
RETURN( self ); |
|
1059 | 768 |
} |
769 |
%}. |
|
770 |
zstream ifNil:[ self errorNotOpen ]. |
|
1570 | 771 |
self invalidArgument. |
1045 | 772 |
! ! |
773 |
||
774 |
!ZipStream methodsFor:'startup & release'! |
|
775 |
||
2196 | 776 |
openWithMode:aMode on:aStream suppressHeaderAndChecksum:aBoolean |
2006
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
777 |
"open stream and write or check gzip header" |
2019 | 778 |
|
2196 | 779 |
super |
780 |
openWithMode:aMode |
|
781 |
on:aStream |
|
782 |
suppressHeaderAndChecksum:aBoolean. |
|
2019 | 783 |
|
1193 | 784 |
self isReadable ifTrue:[ |
2196 | 785 |
"Check for the gzip magic id" |
786 |
self readHeader |
|
2019 | 787 |
] ifFalse:[ |
2196 | 788 |
"write the gzip magic id" |
789 |
self writeHeader |
|
2019 | 790 |
]. |
791 |
! |
|
1045 | 792 |
|
2019 | 793 |
readHeader |
794 |
"Check for the gzip magic id" |
|
795 |
|flags| |
|
1045 | 796 |
|
2019 | 797 |
GZ_MAGIC_ID do:[:b| |
2190 | 798 |
onStream nextByte ~~ b ifTrue:[ self zerror:'version error' ] |
2019 | 799 |
]. |
800 |
||
801 |
onStream nextByte ~~ Z_DEFLATED ifTrue:[ |
|
2190 | 802 |
self zerror:'invalid method (not deflated)' |
2019 | 803 |
]. |
1045 | 804 |
|
2019 | 805 |
flags := onStream nextByte. |
806 |
(flags bitAnd:HEAD_RESERVED) ~~ 0 ifTrue:[ |
|
2190 | 807 |
self zerror:'wrong data format' |
2019 | 808 |
]. |
1045 | 809 |
|
2019 | 810 |
"discard time, xflags and OS code" |
811 |
onStream skip:6. |
|
1045 | 812 |
|
2019 | 813 |
(flags bitAnd:HEAD_EXTRA_FIELD) ~~ 0 ifTrue:[|len| |
2190 | 814 |
"skip the extra field" |
815 |
len := onStream nextByte + (onStream nextByte bitShift:8). |
|
816 |
len timesRepeat:[ onStream nextByte ]. |
|
2019 | 817 |
]. |
1050 | 818 |
|
2019 | 819 |
(flags bitAnd:HEAD_ORIG_NAME) ~~ 0 ifTrue:[|b| |
2190 | 820 |
"skip the original file name" |
821 |
[ (b := onStream nextByte) ~~ 0 ] whileTrue. |
|
2019 | 822 |
]. |
823 |
||
824 |
(flags bitAnd:HEAD_CRC) ~~ 0 ifTrue:[ |
|
2190 | 825 |
"skip the header crc" |
826 |
onStream skip:2. |
|
2019 | 827 |
]. |
828 |
! |
|
1050 | 829 |
|
2019 | 830 |
writeHeader |
831 |
"write the gzip magic id" |
|
1059 | 832 |
|
2019 | 833 |
GZ_MAGIC_ID do:[:b| onStream nextPutByte:b ]. |
834 |
||
835 |
"write the method" |
|
836 |
onStream nextPutByte:Z_DEFLATED. |
|
1050 | 837 |
|
2019 | 838 |
"write the flags" |
839 |
onStream nextPutByte:0. |
|
840 |
||
841 |
"write time" |
|
842 |
4 timesRepeat:[ onStream nextPutByte:0 ]. |
|
1045 | 843 |
|
2019 | 844 |
"write xflags" |
845 |
onStream nextPutByte:0. |
|
1059 | 846 |
|
2019 | 847 |
"write OS code" |
848 |
onStream nextPutByte:HEAD_OS_CODE. |
|
1045 | 849 |
! ! |
1044 | 850 |
|
851 |
!ZipStream class methodsFor:'documentation'! |
|
852 |
||
853 |
version |
|
2488 | 854 |
^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.38 2010-08-31 08:29:28 sr Exp $' |
2335
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
855 |
! |
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
856 |
|
609923563c1d
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
2196
diff
changeset
|
857 |
version_CVS |
2488 | 858 |
^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.38 2010-08-31 08:29:28 sr Exp $' |
1044 | 859 |
! ! |
1193 | 860 |
|
1047 | 861 |
ZipStream initialize! |