author | Claus Gittinger <cg@exept.de> |
Thu, 06 Sep 2007 17:31:09 +0200 | |
changeset 1894 | 8bf137acc445 |
parent 1847 | 5364b697ad8f |
child 2006 | 0ad76801137e |
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 |
" |
1847 | 88 |
[exBegin] |
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:[ |
101 |
|stream c| |
|
102 |
||
103 |
stream := '' writeStream. |
|
104 |
||
105 |
[ (c := zipStream next) notNil ] whileTrue:[ |
|
106 |
stream nextPut:c |
|
107 |
]. |
|
108 |
stream close. |
|
109 |
uncompressedData := stream contents. |
|
110 |
]. |
|
111 |
^ uncompressedData |
|
112 |
[exEnd] |
|
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 |
||
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
142 |
!ZipStream class methodsFor:'ZipInterface compatibility - compress/uncompress'! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
143 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
144 |
compress: aUncompressedByteArray into: aCompressedByteArray |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
145 |
^ self flatBytesIn: aUncompressedByteArray |
1828 | 146 |
from: 1 |
147 |
to: (aUncompressedByteArray size) |
|
148 |
into: aCompressedByteArray |
|
149 |
doCompress: true. |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
150 |
! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
151 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
152 |
flatBytesIn:bytesIn from:start to:stop into:bytesOut doCompress:doCompress |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
153 |
"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
|
154 |
the un/compressed size; on error an exception is raised |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
155 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
156 |
|errorNr size| |
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 |
size := stop - start + 1. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
159 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
160 |
( (start between:1 and:stop) |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
161 |
and:[size > 0 |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
162 |
and:[bytesIn size >= stop |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
163 |
and:[bytesOut size > 0]]] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
164 |
) ifFalse:[ |
1828 | 165 |
^ self error:'invalid argument size' |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
166 |
]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
167 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
168 |
%{ |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
169 |
char * __bytesIn = 0; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
170 |
uLong __countIn = 0; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
171 |
char * __bytesOut = 0; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
172 |
uLong __countOut = 0; |
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 |
if( (__isSmallInteger(start)) && (__isSmallInteger(stop)) && (__isSmallInteger(size)) ) |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
175 |
{ |
1828 | 176 |
__countIn = __intVal( size ); |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
177 |
|
1828 | 178 |
if (__isBytes(bytesIn)) { |
179 |
__bytesIn = __ByteArrayInstPtr(bytesIn)->ba_element; |
|
180 |
} else { |
|
181 |
if (__isString(bytesIn)) { |
|
182 |
__bytesIn = __stringVal( bytesIn ); |
|
183 |
} |
|
184 |
} |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
185 |
|
1828 | 186 |
if (__isBytes(bytesOut)) { |
187 |
__bytesOut = __ByteArrayInstPtr(bytesOut)->ba_element; |
|
188 |
__countOut = __byteArraySize( bytesOut ); |
|
189 |
} else { |
|
190 |
if (__isString(bytesOut)) { |
|
191 |
__bytesOut = __stringVal( bytesOut ); |
|
192 |
__countOut = __stringSize( bytesOut ); |
|
193 |
} |
|
194 |
} |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
195 |
} |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
196 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
197 |
if( __bytesOut && __bytesIn ) |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
198 |
{ |
1828 | 199 |
int __result = Z_OK; |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
200 |
|
1828 | 201 |
__bytesIn += (__intVal( start)) - 1; |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
202 |
|
1828 | 203 |
if( doCompress == true ) |
204 |
__result = compress ( (Byte *) __bytesOut, & __countOut, (Byte *) __bytesIn, __countIn ); |
|
205 |
else |
|
206 |
__result = uncompress( (Byte *) __bytesOut, & __countOut, (Byte *) __bytesIn, __countIn ); |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
207 |
|
1828 | 208 |
if( __result == Z_OK ) |
209 |
{ RETURN(__MKSMALLINT(__countOut)); } |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
210 |
|
1828 | 211 |
errorNr = __MKSMALLINT( __result ); |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
212 |
} |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
213 |
%}. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
214 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
215 |
errorNr isNil ifTrue:[ ^ self error:'invalid arguments' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
216 |
errorNr == 1 ifTrue:[ ^ self error:'stream at end' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
217 |
errorNr == -3 ifTrue:[ ^ self error:'input data are corrupted' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
218 |
errorNr == -4 ifTrue:[ ^ self error:'not enough memory' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
219 |
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
|
220 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
221 |
self error:('compressing error: ', errorNr printString). |
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 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
224 |
uncompress: aCompressedByteArray into: aUncompressedByteArray |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
225 |
^ self flatBytesIn: aCompressedByteArray |
1828 | 226 |
from: 1 |
227 |
to: (aCompressedByteArray size) |
|
228 |
into: aUncompressedByteArray |
|
229 |
doCompress: false. |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
230 |
! ! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
231 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
232 |
!ZipStream class methodsFor:'ZipInterface compatibility - crc'! |
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 |
crc32BytesIn:bytesIn |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
235 |
"compute crc with the bytes buf[1.. bytesIn size] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
236 |
and return the crc |
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 |
^ self crc32BytesIn:bytesIn from:1 |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
239 |
! |
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 |
crc32BytesIn:bytesIn crc:aCrc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
242 |
"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
|
243 |
and return the updated |
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 |
^ self crc32BytesIn:bytesIn from:1 crc:aCrc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
246 |
! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
247 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
248 |
crc32BytesIn:bytesIn from:start |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
249 |
"compute crc with the bytes buf[start.. bytesIn size] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
250 |
and return the crc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
251 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
252 |
^ self crc32BytesIn:bytesIn from:start to:(bytesIn size) |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
253 |
! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
254 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
255 |
crc32BytesIn:bytesIn from:start crc:aCrc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
256 |
"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
|
257 |
and return the updated |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
258 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
259 |
^ self crc32BytesIn:bytesIn from:start to:(bytesIn size) crc:aCrc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
260 |
! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
261 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
262 |
crc32BytesIn:bytesIn from:start to:stop |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
263 |
"compute crc with the bytes buf[start.. stop] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
264 |
and return the crc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
265 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
266 |
^ self crc32BytesIn:bytesIn from:start to:stop crc:0 |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
267 |
! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
268 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
269 |
crc32BytesIn:bytesIn from:start to:stop crc:crc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
270 |
"Update a running crc with the bytes buf[start.. stop] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
271 |
and return the updated |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
272 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
273 |
|size| |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
274 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
275 |
size := stop - start + 1. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
276 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
277 |
( (start between:1 and:stop) |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
278 |
and:[size > 0 |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
279 |
and:[bytesIn size >= stop]] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
280 |
) ifFalse:[ |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
281 |
^ self error:'invalid argument size' |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
282 |
]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
283 |
%{ |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
284 |
if( (__isInteger(crc)) && (__isSmallInteger(start)) && (__isSmallInteger(size)) ) |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
285 |
{ |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
286 |
char * __bytes = 0; |
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 |
if (__isBytes(bytesIn)) { |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
289 |
__bytes = __ByteArrayInstPtr(bytesIn)->ba_element; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
290 |
} else { |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
291 |
if (__isString(bytesIn)) { |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
292 |
__bytes = __stringVal( bytesIn ); |
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 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
296 |
if( __bytes ) |
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 |
uLong __crc = __longIntVal( crc ); |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
299 |
uInt __size = __intVal( size ); |
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 |
__bytes += (__intVal( start)) - 1; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
302 |
__crc = crc32(__crc, (Byte *) __bytes, __size ); |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
303 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
304 |
RETURN( __MKUINT(__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 |
} |
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 |
^ self error:'invalid argument size' |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
310 |
! ! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
311 |
|
1045 | 312 |
!ZipStream methodsFor:'low level'! |
313 |
||
314 |
zclose |
|
1052 | 315 |
"low level close of the zip stream |
316 |
" |
|
1045 | 317 |
%{ |
318 |
OBJ _zstreamObj = __INST( zstream ); |
|
319 |
||
320 |
if( _zstreamObj != nil ) |
|
321 |
{ |
|
1828 | 322 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
1045 | 323 |
|
1828 | 324 |
__INST(zstream) = nil; |
1045 | 325 |
|
1828 | 326 |
if( _zstream->stream.state != NULL ) |
327 |
{ |
|
328 |
if( _zstream->op_mode == e_opmode_inflate ) |
|
329 |
inflateEnd( & _zstream->stream ); |
|
330 |
else |
|
331 |
deflateEnd( & _zstream->stream ); |
|
332 |
} |
|
333 |
free( _zstream ); |
|
1045 | 334 |
} |
335 |
%}. |
|
336 |
! |
|
337 |
||
1057 | 338 |
zdeflate |
1570 | 339 |
"low level - deflate" |
340 |
||
1045 | 341 |
|errorNo| |
342 |
errorNo := nil. |
|
343 |
||
344 |
%{ |
|
345 |
OBJ _zstreamObj = __INST( zstream ); |
|
346 |
||
1056 | 347 |
if( _zstreamObj != nil ) |
1045 | 348 |
{ |
1828 | 349 |
int _errorNo, _action; |
350 |
uLong _bfsize; |
|
351 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1047 | 352 |
|
1828 | 353 |
if( _zstream->op_mode != e_opmode_deflate ) |
354 |
RETURN( false ); |
|
1051 | 355 |
|
1828 | 356 |
_bfsize = _zstream->out_total; |
1051 | 357 |
|
1828 | 358 |
if( _zstream->stream.state == NULL ) |
359 |
{ |
|
360 |
/* processing finished; write crc_32 and the total size |
|
361 |
*/ |
|
362 |
uLong v, i; |
|
363 |
Bytef * p = _zstream->out_ref; |
|
1051 | 364 |
|
1828 | 365 |
v = _zstream->crc_32; |
366 |
for( i = 0; i < 4; ++i ) { p[i] = v & 0xff; v >>= 8; } |
|
1051 | 367 |
|
1828 | 368 |
v = _zstream->stream.total_in; |
369 |
for( i = 4; i < 8; ++i ) { p[i] = v & 0xff; v >>= 8; } |
|
1051 | 370 |
|
1828 | 371 |
_zstream->op_mode = e_opmode_unspecified; |
372 |
_zstream->stream.avail_in = 0; |
|
373 |
_zstream->stream.next_in = Z_NULL; |
|
374 |
_zstream->stream.avail_out = _bfsize - 8; |
|
375 |
RETURN( true ); |
|
376 |
} |
|
377 |
_zstream->stream.avail_out = _bfsize; |
|
378 |
_zstream->stream.next_out = _zstream->out_ref; |
|
1056 | 379 |
|
1828 | 380 |
_action = (__INST(hitEOF) == true) ? Z_FINISH : Z_NO_FLUSH; |
381 |
_errorNo = deflate( & _zstream->stream, _action ); |
|
1045 | 382 |
|
1828 | 383 |
if( _errorNo == Z_STREAM_END ) |
384 |
{ |
|
385 |
_zstream->stream.avail_in = 0; |
|
386 |
_zstream->stream.next_in = Z_NULL; |
|
387 |
_errorNo = deflateEnd( & _zstream->stream ); |
|
388 |
} |
|
1045 | 389 |
|
1828 | 390 |
if( _errorNo == Z_OK ) |
391 |
{ |
|
392 |
if( _zstream->stream.avail_out == 0 ) |
|
393 |
RETURN( true ); |
|
1050 | 394 |
|
1828 | 395 |
RETURN( false ); |
396 |
} |
|
397 |
errorNo = __MKSMALLINT( _errorNo ); |
|
1045 | 398 |
} |
399 |
%}. |
|
400 |
errorNo ifNil:[ |
|
1828 | 401 |
zstream ifNil:[self errorNotOpen]. |
402 |
self invalidArgument. |
|
1045 | 403 |
]. |
404 |
self zerror:errorNo. |
|
405 |
! |
|
406 |
||
1059 | 407 |
zdeflateInit |
1570 | 408 |
"low level - deflateInit" |
409 |
||
1059 | 410 |
|errorNo level| |
1045 | 411 |
|
412 |
errorNo := nil. |
|
1059 | 413 |
level := BlockSize. |
1045 | 414 |
%{ |
415 |
OBJ _zstreamObj = __INST( zstream ); |
|
416 |
||
1059 | 417 |
if( (_zstreamObj != nil) && __isSmallInteger(level) ) |
1045 | 418 |
{ |
1828 | 419 |
int _errorNo; |
420 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1045 | 421 |
|
1828 | 422 |
_zstream->op_mode = e_opmode_deflate; |
1051 | 423 |
|
1828 | 424 |
_errorNo = deflateInit2( & _zstream->stream |
425 |
, __intVal( level ) |
|
426 |
, Z_DEFLATED |
|
427 |
, -MAX_WBITS |
|
428 |
, DEF_MEM_LEVEL |
|
429 |
, Z_DEFAULT_STRATEGY |
|
430 |
); |
|
1045 | 431 |
|
1828 | 432 |
if( _errorNo == Z_OK ) |
433 |
RETURN( self ); |
|
1045 | 434 |
|
1828 | 435 |
errorNo = __MKSMALLINT( _errorNo ); |
1045 | 436 |
} |
437 |
%}. |
|
438 |
errorNo ifNil:[ |
|
1828 | 439 |
zstream ifNil:[ self errorNotOpen ]. |
440 |
self invalidArgument . |
|
1045 | 441 |
]. |
442 |
self zerror:errorNo. |
|
443 |
! |
|
444 |
||
1059 | 445 |
zget_avail_out |
446 |
"low level - get the number of available out bytes |
|
447 |
" |
|
448 |
%{ |
|
449 |
OBJ _zstreamObj = __INST( zstream ); |
|
450 |
||
451 |
if( _zstreamObj != nil ) |
|
452 |
{ |
|
1195 | 453 |
uInt _count; |
454 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1059 | 455 |
|
1195 | 456 |
_count = _zstream->out_total - _zstream->stream.avail_out; |
1059 | 457 |
|
1195 | 458 |
RETURN( __MKSMALLINT (_count) ); |
1059 | 459 |
} |
460 |
%}. |
|
461 |
self errorNotOpen. |
|
462 |
! |
|
463 |
||
1050 | 464 |
zinflate |
1052 | 465 |
"low level - inflate |
466 |
" |
|
1061 | 467 |
|errorNo tailError| |
1050 | 468 |
|
1061 | 469 |
tailError := nil. |
470 |
errorNo := nil. |
|
1050 | 471 |
%{ |
472 |
OBJ _zstreamObj = __INST( zstream ); |
|
473 |
||
474 |
if( _zstreamObj != nil ) |
|
475 |
{ |
|
1195 | 476 |
int _errorNo, _count; |
477 |
zstream_s * _zstream; |
|
478 |
int _avail_in; |
|
1050 | 479 |
|
1195 | 480 |
_zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
1050 | 481 |
|
1195 | 482 |
if( _zstream->op_mode != e_opmode_inflate ) |
483 |
RETURN( nil ); |
|
1051 | 484 |
|
1195 | 485 |
_avail_in = _zstream->stream.avail_in; |
1061 | 486 |
|
1195 | 487 |
if( _zstream->stream.state == NULL ) |
488 |
{ |
|
489 |
/* processing finished : check crc and data length */ |
|
490 |
Bytef * _next_in; |
|
491 |
Bytef * _buff; |
|
492 |
uLong _tnum; |
|
493 |
int _i; |
|
1061 | 494 |
|
1195 | 495 |
_next_in = _zstream->stream.next_in; |
496 |
_buff = _zstream->tail_buff; |
|
497 |
_tnum = _zstream->tail_size; |
|
1061 | 498 |
|
1195 | 499 |
while( (_avail_in > 0) && (_tnum < 8) ) |
500 |
{ |
|
501 |
_buff[_tnum] = * _next_in; |
|
1061 | 502 |
|
1195 | 503 |
++_next_in; |
504 |
++_tnum; |
|
505 |
--_avail_in; |
|
506 |
} |
|
507 |
_zstream->tail_size = _tnum; |
|
1061 | 508 |
|
1195 | 509 |
if( _tnum < 8 ) /* test whether tail is read */ |
510 |
RETURN( __MKSMALLINT (0) ); /* need more data */ |
|
1061 | 511 |
|
1195 | 512 |
/* compute and check crc */ |
513 |
for( _tnum = 0, _i = 4; --_i >= 0; _tnum = (_tnum << 8) + _buff[_i] ); |
|
1061 | 514 |
|
1195 | 515 |
if( _tnum != _zstream->crc_32 ) |
516 |
{ tailError = __MKSMALLINT( 1 ); goto badTail; } |
|
1061 | 517 |
|
1195 | 518 |
/* compute and check data length */ |
519 |
for( _tnum = 0, _i = 8; --_i >= 4; _tnum = (_tnum << 8) + _buff[_i] ); |
|
1061 | 520 |
|
1195 | 521 |
if( _zstream->stream.total_out != _tnum ) |
522 |
{ tailError = __MKSMALLINT( 2 ); goto badTail; } |
|
1051 | 523 |
|
1195 | 524 |
_zstream->op_mode = e_opmode_unspecified; |
525 |
RETURN( nil ); |
|
526 |
} |
|
527 |
if( _avail_in == 0 ) |
|
528 |
RETURN( __MKSMALLINT (0) ); |
|
1050 | 529 |
|
1195 | 530 |
_zstream->stream.avail_out = _zstream->out_total; |
531 |
_zstream->stream.next_out = _zstream->out_ref; |
|
1050 | 532 |
|
1195 | 533 |
_errorNo = inflate( & _zstream->stream, Z_NO_FLUSH ); |
1050 | 534 |
|
1195 | 535 |
if( _errorNo == Z_STREAM_END ) |
536 |
_errorNo = inflateEnd( & _zstream->stream ); |
|
1050 | 537 |
|
1195 | 538 |
if( _errorNo == Z_OK ) |
539 |
{ |
|
540 |
_count = _zstream->out_total - _zstream->stream.avail_out; |
|
1051 | 541 |
|
1195 | 542 |
if( _count > 0 ) |
543 |
_zstream->crc_32 = crc32( _zstream->crc_32, _zstream->out_ref, _count ); |
|
1051 | 544 |
|
1195 | 545 |
RETURN( __MKSMALLINT (_count) ); |
546 |
} |
|
547 |
errorNo = __MKSMALLINT( _errorNo ); |
|
1050 | 548 |
} |
1061 | 549 |
badTail:; |
1050 | 550 |
%}. |
1061 | 551 |
errorNo ifNil:[ |
1195 | 552 |
tailError ifNotNil:[ |
553 |
tailError == 1 ifTrue:[ |
|
554 |
self zerror:'invalid compressed data--crc error' |
|
555 |
]. |
|
556 |
self zerror:'invalid compressed data--length error' |
|
557 |
]. |
|
558 |
self errorNotOpen |
|
1061 | 559 |
]. |
1050 | 560 |
self zerror:errorNo. |
561 |
! |
|
562 |
||
1045 | 563 |
zinflateInit |
1052 | 564 |
"low level - inflateInit |
565 |
" |
|
1045 | 566 |
|errorNo| |
567 |
||
568 |
errorNo := nil. |
|
569 |
||
570 |
%{ |
|
571 |
OBJ _zstreamObj = __INST( zstream ); |
|
572 |
||
573 |
if( _zstreamObj != nil ) |
|
574 |
{ |
|
1195 | 575 |
int _errorNo; |
576 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1045 | 577 |
|
1195 | 578 |
_zstream->op_mode = e_opmode_inflate; |
579 |
_errorNo = inflateInit2( & _zstream->stream, -MAX_WBITS ); |
|
1045 | 580 |
|
1195 | 581 |
if( _errorNo == Z_OK ) |
582 |
RETURN( self ); |
|
1045 | 583 |
|
1195 | 584 |
_zstream->stream.avail_in = 0; |
585 |
errorNo = __MKSMALLINT( _errorNo ); |
|
1045 | 586 |
} |
587 |
%}. |
|
588 |
errorNo ifNil:[ self errorNotOpen ]. |
|
589 |
self zerror:errorNo. |
|
590 |
! |
|
1047 | 591 |
|
1059 | 592 |
zopen |
1052 | 593 |
"low level - opens the zip stream |
594 |
" |
|
1051 | 595 |
|outTotal| |
1045 | 596 |
|
1059 | 597 |
outTotal := outputBytes size. |
1045 | 598 |
%{ |
599 |
zstream_s * _zstream = (zstream_s *) malloc( sizeof(zstream_s) ); |
|
600 |
||
601 |
if( _zstream ) |
|
602 |
{ |
|
1195 | 603 |
OBJ _zobj = __MKEXTERNALADDRESS( _zstream ); |
604 |
OBJ _outObj = __INST( outputBytes ); |
|
605 |
OBJ _inpObj = __INST( inputBytes ); |
|
1045 | 606 |
|
1195 | 607 |
zmemzero( _zstream, sizeof(zstream_s) ); |
1045 | 608 |
|
1195 | 609 |
_zstream->in_ref = (Bytef *) __externalBytesAddress( _inpObj ); |
610 |
_zstream->stream.next_in = Z_NULL; |
|
611 |
_zstream->stream.avail_in = 0; |
|
612 |
_zstream->stream.total_in = 0; |
|
1045 | 613 |
|
1195 | 614 |
_zstream->out_total = __intVal( outTotal ); |
615 |
_zstream->out_ref = (Bytef *) __externalBytesAddress( _outObj ); |
|
616 |
_zstream->stream.next_out = _zstream->out_ref; |
|
617 |
_zstream->stream.avail_out = _zstream->out_total; |
|
618 |
_zstream->stream.total_out = 0; |
|
1045 | 619 |
|
1195 | 620 |
_zstream->stream.zalloc = (alloc_func)0; |
621 |
_zstream->stream.zfree = (free_func) 0; |
|
622 |
_zstream->stream.opaque = (voidpf) 0; |
|
1045 | 623 |
|
1195 | 624 |
_zstream->crc_32 = crc32( 0L, Z_NULL, 0 ); |
625 |
_zstream->op_mode = e_opmode_unspecified; |
|
626 |
_zstream->tail_size = 0; |
|
1045 | 627 |
|
1195 | 628 |
__INST (zstream) = _zobj; |
629 |
__STORE(self, _zobj); |
|
1045 | 630 |
} |
631 |
%}. |
|
632 |
! |
|
633 |
||
1059 | 634 |
zset_avail_in:count |
1570 | 635 |
"set the 'avail_in' and compute the crc" |
1059 | 636 |
%{ |
637 |
OBJ _zstreamObj = __INST( zstream ); |
|
1045 | 638 |
|
1059 | 639 |
if( (_zstreamObj != nil) && __isSmallInteger(count) ) |
640 |
{ |
|
1828 | 641 |
int _count; |
642 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1045 | 643 |
|
1828 | 644 |
if( (_count = __intVal( count )) > 0 ) |
645 |
{ |
|
646 |
Bytef * _in_ref = _zstream->in_ref; |
|
1045 | 647 |
|
1828 | 648 |
_zstream->stream.avail_in = _count; |
649 |
_zstream->stream.next_in = _in_ref; |
|
1045 | 650 |
|
1828 | 651 |
if( _zstream->op_mode == e_opmode_deflate ) |
652 |
_zstream->crc_32 = crc32( _zstream->crc_32, _in_ref, _count ); |
|
653 |
} else { |
|
654 |
_zstream->stream.avail_in = 0; |
|
655 |
_zstream->stream.next_in = Z_NULL; |
|
656 |
} |
|
657 |
RETURN( self ); |
|
1059 | 658 |
} |
659 |
%}. |
|
660 |
zstream ifNil:[ self errorNotOpen ]. |
|
1570 | 661 |
self invalidArgument. |
1045 | 662 |
! ! |
663 |
||
664 |
!ZipStream methodsFor:'startup & release'! |
|
665 |
||
1059 | 666 |
openWithMode:aMode on:aStream |
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
667 |
|
1059 | 668 |
super openWithMode:aMode on:aStream. |
1193 | 669 |
self isReadable ifTrue:[ |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
670 |
"Check for the gzip magic id" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
671 |
|flags| |
1045 | 672 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
673 |
GZ_MAGIC_ID do:[:b| |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
674 |
onStream nextByte ~~ b ifTrue:[ self zerror:'version error' ] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
675 |
]. |
1045 | 676 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
677 |
onStream nextByte ~~ Z_DEFLATED ifTrue:[ |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
678 |
self zerror:'invalid method (not deflated)' |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
679 |
]. |
1045 | 680 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
681 |
flags := onStream nextByte. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
682 |
(flags bitAnd:HEAD_RESERVED) ~~ 0 ifTrue:[ |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
683 |
self zerror:'wrong data format' |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
684 |
]. |
1045 | 685 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
686 |
"discard time, xflags and OS code" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
687 |
onStream skip:6. |
1045 | 688 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
689 |
(flags bitAnd:HEAD_EXTRA_FIELD) ~~ 0 ifTrue:[|len| |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
690 |
"skip the extra field" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
691 |
len := onStream nextByte + (onStream nextByte bitShift:8). |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
692 |
len timesRepeat:[ onStream nextByte ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
693 |
]. |
1045 | 694 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
695 |
(flags bitAnd:HEAD_ORIG_NAME) ~~ 0 ifTrue:[|b| |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
696 |
"skip the original file name" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
697 |
[ (b := onStream nextByte) ~~ 0 ] whileTrue. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
698 |
]. |
1050 | 699 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
700 |
(flags bitAnd:HEAD_CRC) ~~ 0 ifTrue:[ |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
701 |
"skip the header crc" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
702 |
onStream skip:2. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
703 |
]. |
1059 | 704 |
] ifFalse:[ |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
705 |
"write the gzip magic id |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
706 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
707 |
GZ_MAGIC_ID do:[:b| onStream nextPutByte:b ]. |
1050 | 708 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
709 |
"write the method" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
710 |
onStream nextPutByte:Z_DEFLATED. |
1059 | 711 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
712 |
"write the flags" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
713 |
onStream nextPutByte:0. |
1050 | 714 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
715 |
"write time" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
716 |
4 timesRepeat:[ onStream nextPutByte:0 ]. |
1045 | 717 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
718 |
"write xflags" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
719 |
onStream nextPutByte:0. |
1059 | 720 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
721 |
"write OS code" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
722 |
onStream nextPutByte:HEAD_OS_CODE. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
723 |
]. |
1045 | 724 |
! ! |
1044 | 725 |
|
726 |
!ZipStream class methodsFor:'documentation'! |
|
727 |
||
728 |
version |
|
1847 | 729 |
^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.28 2007-02-15 14:46:40 sr Exp $' |
1044 | 730 |
! ! |
1193 | 731 |
|
1047 | 732 |
ZipStream initialize! |