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