author | ca |
Tue, 16 Jan 2007 17:21:51 +0100 | |
changeset 1828 | 47cd819e24af |
parent 1619 | b20d5b1af962 |
child 1836 | e9e1ba3735c6 |
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 |
" |
|
12 |
||
1195 | 13 |
"{ Package: 'stx:libbasic2' }" |
1044 | 14 |
|
1059 | 15 |
CompressionStream subclass:#ZipStream |
1193 | 16 |
instanceVariableNames:'' |
17 |
classVariableNames:'Z_DEFLATED HEAD_OS_CODE HEAD_RESERVED HEAD_EXTRA_FIELD |
|
18 |
HEAD_ORIG_NAME HEAD_COMMENT HEAD_CRC GZ_MAGIC_ID' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'System-Compress' |
|
1044 | 21 |
! |
22 |
||
1045 | 23 |
!ZipStream primitiveDefinitions! |
24 |
%{ |
|
25 |
||
26 |
/* |
|
27 |
* includes, defines, structure definitions |
|
28 |
* and typedefs come here. |
|
29 |
*/ |
|
1060 | 30 |
#include "zlib/zlib.h" |
31 |
#include "zlib/zutil.h" |
|
1045 | 32 |
|
1051 | 33 |
typedef enum { |
1195 | 34 |
e_opmode_unspecified /* processing done */ |
35 |
, e_opmode_deflate /* running deflate */ |
|
36 |
, e_opmode_inflate /* running inflate */ |
|
1051 | 37 |
} e_opmode; |
38 |
||
1045 | 39 |
typedef struct { |
1195 | 40 |
z_stream stream; /* pointer to the external in -stream */ |
41 |
Bytef * in_ref; /* size of the external in -stream */ |
|
42 |
Bytef * out_ref; /* pointer to the external out-stream */ |
|
43 |
uLong out_total; /* size of the external out-stream */ |
|
1045 | 44 |
|
1195 | 45 |
e_opmode op_mode; /* current operational mode */ |
46 |
uLong crc_32; /* keeps the current crc */ |
|
1061 | 47 |
|
1195 | 48 |
Bytef tail_buff[ 8 ]; /* store the tail in the read modus */ |
49 |
uLong tail_size; /* to check the crc and data length */ |
|
1045 | 50 |
} zstream_s; |
51 |
||
52 |
%} |
|
53 |
! ! |
|
54 |
||
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
55 |
!ZipStream class methodsFor:'documentation'! |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
56 |
|
1308 | 57 |
copyright |
58 |
" |
|
59 |
COPYRIGHT (c) 2002 by eXept Software AG |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
60 |
All Rights Reserved |
1308 | 61 |
|
62 |
This software is furnished under a license and may be used |
|
63 |
only in accordance with the terms of that license and with the |
|
64 |
inclusion of the above copyright notice. This software may not |
|
65 |
be provided or otherwise made available to, or used by, any |
|
66 |
other person. No title to or ownership of the software is |
|
67 |
hereby transferred. |
|
68 |
" |
|
69 |
! |
|
70 |
||
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
71 |
documentation |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
72 |
" |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
73 |
Zip compression and decompression (used in gzip and zip) |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
74 |
|
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
75 |
[author:] |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
76 |
Claus Atzkern |
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
77 |
|
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
78 |
[instance variables:] |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
79 |
|
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
80 |
[class variables:] |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
81 |
|
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
82 |
[see also:] |
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 |
|
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
87 |
examples |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
88 |
" |
1828 | 89 |
[exBegin] |
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
90 |
|compressed zipStream| |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
91 |
|
1570 | 92 |
self halt. |
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
93 |
compressed := #[] writeStream. |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
94 |
zipStream := self writeOpenOn:compressed. |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
95 |
zipStream nextPutAll:'This is some text 1234567890'. |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
96 |
zipStream flush. |
1570 | 97 |
self information:'Compressed size: ', compressed contents size printString. |
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
98 |
self halt. |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
99 |
zipStream := self readOpenOn:compressed contents readStream. |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
100 |
self information:zipStream contents. |
1828 | 101 |
[exEnd] |
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
102 |
" |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
103 |
! ! |
1045 | 104 |
|
105 |
!ZipStream class methodsFor:'initialization'! |
|
106 |
||
107 |
initialize |
|
1061 | 108 |
"setup class attributes derived from the library |
109 |
" |
|
1059 | 110 |
|z_deflated os_code| |
1045 | 111 |
%{ |
1059 | 112 |
z_deflated = __MKSMALLINT( Z_DEFLATED ); |
113 |
os_code = __MKSMALLINT( OS_CODE ); |
|
1045 | 114 |
%}. |
115 |
||
1059 | 116 |
Z_DEFLATED := z_deflated. |
1045 | 117 |
|
1059 | 118 |
HEAD_OS_CODE := os_code. |
1045 | 119 |
HEAD_RESERVED := 16rE0. " bits 5..7: reserved " |
120 |
HEAD_EXTRA_FIELD := 16r04. " bit 2 set: extra field present " |
|
121 |
HEAD_ORIG_NAME := 16r08. " bit 3 set: original file name present " |
|
122 |
HEAD_COMMENT := 16r10. " bit 4 set: file comment present " |
|
123 |
HEAD_CRC := 16r02. " bit 1 set: header CRC present " |
|
124 |
||
125 |
GZ_MAGIC_ID := #[ 16r1f 16r8b ] |
|
126 |
||
127 |
! ! |
|
128 |
||
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
129 |
!ZipStream class methodsFor:'ZipInterface compatibility - compress/uncompress'! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
130 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
131 |
compress: aUncompressedByteArray into: aCompressedByteArray |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
132 |
^ self flatBytesIn: aUncompressedByteArray |
1828 | 133 |
from: 1 |
134 |
to: (aUncompressedByteArray size) |
|
135 |
into: aCompressedByteArray |
|
136 |
doCompress: true. |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
137 |
! |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
138 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
139 |
flatBytesIn:bytesIn from:start to:stop into:bytesOut doCompress:doCompress |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
140 |
"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
|
141 |
the un/compressed size; on error an exception is raised |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
142 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
143 |
|errorNr size| |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
144 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
145 |
size := stop - start + 1. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
146 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
147 |
( (start between:1 and:stop) |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
148 |
and:[size > 0 |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
149 |
and:[bytesIn size >= stop |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
150 |
and:[bytesOut size > 0]]] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
151 |
) ifFalse:[ |
1828 | 152 |
^ self error:'invalid argument size' |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
153 |
]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
154 |
|
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 |
char * __bytesIn = 0; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
157 |
uLong __countIn = 0; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
158 |
char * __bytesOut = 0; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
159 |
uLong __countOut = 0; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
160 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
161 |
if( (__isSmallInteger(start)) && (__isSmallInteger(stop)) && (__isSmallInteger(size)) ) |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
162 |
{ |
1828 | 163 |
__countIn = __intVal( size ); |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
164 |
|
1828 | 165 |
if (__isBytes(bytesIn)) { |
166 |
__bytesIn = __ByteArrayInstPtr(bytesIn)->ba_element; |
|
167 |
} else { |
|
168 |
if (__isString(bytesIn)) { |
|
169 |
__bytesIn = __stringVal( bytesIn ); |
|
170 |
} |
|
171 |
} |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
172 |
|
1828 | 173 |
if (__isBytes(bytesOut)) { |
174 |
__bytesOut = __ByteArrayInstPtr(bytesOut)->ba_element; |
|
175 |
__countOut = __byteArraySize( bytesOut ); |
|
176 |
} else { |
|
177 |
if (__isString(bytesOut)) { |
|
178 |
__bytesOut = __stringVal( bytesOut ); |
|
179 |
__countOut = __stringSize( bytesOut ); |
|
180 |
} |
|
181 |
} |
|
1439
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 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
184 |
if( __bytesOut && __bytesIn ) |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
185 |
{ |
1828 | 186 |
int __result = Z_OK; |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
187 |
|
1828 | 188 |
__bytesIn += (__intVal( start)) - 1; |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
189 |
|
1828 | 190 |
if( doCompress == true ) |
191 |
__result = compress ( (Byte *) __bytesOut, & __countOut, (Byte *) __bytesIn, __countIn ); |
|
192 |
else |
|
193 |
__result = uncompress( (Byte *) __bytesOut, & __countOut, (Byte *) __bytesIn, __countIn ); |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
194 |
|
1828 | 195 |
if( __result == Z_OK ) |
196 |
{ RETURN(__MKSMALLINT(__countOut)); } |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
197 |
|
1828 | 198 |
errorNr = __MKSMALLINT( __result ); |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
199 |
} |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
200 |
%}. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
201 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
202 |
errorNr isNil ifTrue:[ ^ self error:'invalid arguments' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
203 |
errorNr == 1 ifTrue:[ ^ self error:'stream at end' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
204 |
errorNr == -3 ifTrue:[ ^ self error:'input data are corrupted' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
205 |
errorNr == -4 ifTrue:[ ^ self error:'not enough memory' ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
206 |
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
|
207 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
208 |
self error:('compressing error: ', errorNr printString). |
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 |
uncompress: aCompressedByteArray into: aUncompressedByteArray |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
212 |
^ self flatBytesIn: aCompressedByteArray |
1828 | 213 |
from: 1 |
214 |
to: (aCompressedByteArray size) |
|
215 |
into: aUncompressedByteArray |
|
216 |
doCompress: false. |
|
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 |
!ZipStream class methodsFor:'ZipInterface compatibility - crc'! |
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 |
crc32BytesIn:bytesIn |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
222 |
"compute crc with the bytes buf[1.. bytesIn size] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
223 |
and return the crc |
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 |
^ self crc32BytesIn:bytesIn from: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 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
228 |
crc32BytesIn:bytesIn crc:aCrc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
229 |
"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
|
230 |
and return the updated |
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 |
^ self crc32BytesIn:bytesIn from:1 crc:aCrc |
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 |
crc32BytesIn:bytesIn from:start |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
236 |
"compute crc with the bytes buf[start.. bytesIn size] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
237 |
and return the crc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
238 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
239 |
^ self crc32BytesIn:bytesIn from:start to:(bytesIn size) |
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 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
242 |
crc32BytesIn:bytesIn from:start crc:aCrc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
243 |
"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
|
244 |
and return the updated |
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 |
^ self crc32BytesIn:bytesIn from:start to:(bytesIn size) crc:aCrc |
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 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
249 |
crc32BytesIn:bytesIn from:start to:stop |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
250 |
"compute crc with the bytes buf[start.. stop] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
251 |
and return the crc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
252 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
253 |
^ self crc32BytesIn:bytesIn from:start to:stop crc:0 |
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 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
256 |
crc32BytesIn:bytesIn from:start to:stop crc:crc |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
257 |
"Update a running crc with the bytes buf[start.. stop] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
258 |
and return the updated |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
259 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
260 |
|size| |
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 |
size := stop - start + 1. |
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 |
( (start between:1 and:stop) |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
265 |
and:[size > 0 |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
266 |
and:[bytesIn size >= stop]] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
267 |
) ifFalse:[ |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
268 |
^ self error:'invalid argument size' |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
269 |
]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
270 |
%{ |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
271 |
if( (__isInteger(crc)) && (__isSmallInteger(start)) && (__isSmallInteger(size)) ) |
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 |
char * __bytes = 0; |
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 |
if (__isBytes(bytesIn)) { |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
276 |
__bytes = __ByteArrayInstPtr(bytesIn)->ba_element; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
277 |
} else { |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
278 |
if (__isString(bytesIn)) { |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
279 |
__bytes = __stringVal( bytesIn ); |
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 |
|
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
283 |
if( __bytes ) |
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 |
uLong __crc = __longIntVal( crc ); |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
286 |
uInt __size = __intVal( size ); |
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 |
__bytes += (__intVal( start)) - 1; |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
289 |
__crc = crc32(__crc, (Byte *) __bytes, __size ); |
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 |
RETURN( __MKUINT(__crc) ); |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
292 |
} |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
293 |
} |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
294 |
%}. |
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 |
^ self error:'invalid argument size' |
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 |
|
1045 | 299 |
!ZipStream methodsFor:'low level'! |
300 |
||
301 |
zclose |
|
1052 | 302 |
"low level close of the zip stream |
303 |
" |
|
1045 | 304 |
%{ |
305 |
OBJ _zstreamObj = __INST( zstream ); |
|
306 |
||
307 |
if( _zstreamObj != nil ) |
|
308 |
{ |
|
1828 | 309 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
1045 | 310 |
|
1828 | 311 |
__INST(zstream) = nil; |
1045 | 312 |
|
1828 | 313 |
if( _zstream->stream.state != NULL ) |
314 |
{ |
|
315 |
if( _zstream->op_mode == e_opmode_inflate ) |
|
316 |
inflateEnd( & _zstream->stream ); |
|
317 |
else |
|
318 |
deflateEnd( & _zstream->stream ); |
|
319 |
} |
|
320 |
free( _zstream ); |
|
1045 | 321 |
} |
322 |
%}. |
|
323 |
! |
|
324 |
||
1057 | 325 |
zdeflate |
1570 | 326 |
"low level - deflate" |
327 |
||
1045 | 328 |
|errorNo| |
329 |
errorNo := nil. |
|
330 |
||
331 |
%{ |
|
332 |
OBJ _zstreamObj = __INST( zstream ); |
|
333 |
||
1056 | 334 |
if( _zstreamObj != nil ) |
1045 | 335 |
{ |
1828 | 336 |
int _errorNo, _action; |
337 |
uLong _bfsize; |
|
338 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1047 | 339 |
|
1828 | 340 |
if( _zstream->op_mode != e_opmode_deflate ) |
341 |
RETURN( false ); |
|
1051 | 342 |
|
1828 | 343 |
_bfsize = _zstream->out_total; |
1051 | 344 |
|
1828 | 345 |
if( _zstream->stream.state == NULL ) |
346 |
{ |
|
347 |
/* processing finished; write crc_32 and the total size |
|
348 |
*/ |
|
349 |
uLong v, i; |
|
350 |
Bytef * p = _zstream->out_ref; |
|
1051 | 351 |
|
1828 | 352 |
v = _zstream->crc_32; |
353 |
for( i = 0; i < 4; ++i ) { p[i] = v & 0xff; v >>= 8; } |
|
1051 | 354 |
|
1828 | 355 |
v = _zstream->stream.total_in; |
356 |
for( i = 4; i < 8; ++i ) { p[i] = v & 0xff; v >>= 8; } |
|
1051 | 357 |
|
1828 | 358 |
_zstream->op_mode = e_opmode_unspecified; |
359 |
_zstream->stream.avail_in = 0; |
|
360 |
_zstream->stream.next_in = Z_NULL; |
|
361 |
_zstream->stream.avail_out = _bfsize - 8; |
|
362 |
RETURN( true ); |
|
363 |
} |
|
364 |
_zstream->stream.avail_out = _bfsize; |
|
365 |
_zstream->stream.next_out = _zstream->out_ref; |
|
1056 | 366 |
|
1828 | 367 |
_action = (__INST(hitEOF) == true) ? Z_FINISH : Z_NO_FLUSH; |
368 |
_errorNo = deflate( & _zstream->stream, _action ); |
|
1045 | 369 |
|
1828 | 370 |
if( _errorNo == Z_STREAM_END ) |
371 |
{ |
|
372 |
_zstream->stream.avail_in = 0; |
|
373 |
_zstream->stream.next_in = Z_NULL; |
|
374 |
_errorNo = deflateEnd( & _zstream->stream ); |
|
375 |
} |
|
1045 | 376 |
|
1828 | 377 |
if( _errorNo == Z_OK ) |
378 |
{ |
|
379 |
if( _zstream->stream.avail_out == 0 ) |
|
380 |
RETURN( true ); |
|
1050 | 381 |
|
1828 | 382 |
RETURN( false ); |
383 |
} |
|
384 |
errorNo = __MKSMALLINT( _errorNo ); |
|
1045 | 385 |
} |
386 |
%}. |
|
387 |
errorNo ifNil:[ |
|
1828 | 388 |
zstream ifNil:[self errorNotOpen]. |
389 |
self invalidArgument. |
|
1045 | 390 |
]. |
391 |
self zerror:errorNo. |
|
392 |
! |
|
393 |
||
1059 | 394 |
zdeflateInit |
1570 | 395 |
"low level - deflateInit" |
396 |
||
1059 | 397 |
|errorNo level| |
1045 | 398 |
|
399 |
errorNo := nil. |
|
1059 | 400 |
level := BlockSize. |
1045 | 401 |
%{ |
402 |
OBJ _zstreamObj = __INST( zstream ); |
|
403 |
||
1059 | 404 |
if( (_zstreamObj != nil) && __isSmallInteger(level) ) |
1045 | 405 |
{ |
1828 | 406 |
int _errorNo; |
407 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1045 | 408 |
|
1828 | 409 |
_zstream->op_mode = e_opmode_deflate; |
1051 | 410 |
|
1828 | 411 |
_errorNo = deflateInit2( & _zstream->stream |
412 |
, __intVal( level ) |
|
413 |
, Z_DEFLATED |
|
414 |
, -MAX_WBITS |
|
415 |
, DEF_MEM_LEVEL |
|
416 |
, Z_DEFAULT_STRATEGY |
|
417 |
); |
|
1045 | 418 |
|
1828 | 419 |
if( _errorNo == Z_OK ) |
420 |
RETURN( self ); |
|
1045 | 421 |
|
1828 | 422 |
errorNo = __MKSMALLINT( _errorNo ); |
1045 | 423 |
} |
424 |
%}. |
|
425 |
errorNo ifNil:[ |
|
1828 | 426 |
zstream ifNil:[ self errorNotOpen ]. |
427 |
self invalidArgument . |
|
1045 | 428 |
]. |
429 |
self zerror:errorNo. |
|
430 |
! |
|
431 |
||
1059 | 432 |
zget_avail_out |
433 |
"low level - get the number of available out bytes |
|
434 |
" |
|
435 |
%{ |
|
436 |
OBJ _zstreamObj = __INST( zstream ); |
|
437 |
||
438 |
if( _zstreamObj != nil ) |
|
439 |
{ |
|
1195 | 440 |
uInt _count; |
441 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1059 | 442 |
|
1195 | 443 |
_count = _zstream->out_total - _zstream->stream.avail_out; |
1059 | 444 |
|
1195 | 445 |
RETURN( __MKSMALLINT (_count) ); |
1059 | 446 |
} |
447 |
%}. |
|
448 |
self errorNotOpen. |
|
449 |
! |
|
450 |
||
1050 | 451 |
zinflate |
1052 | 452 |
"low level - inflate |
453 |
" |
|
1061 | 454 |
|errorNo tailError| |
1050 | 455 |
|
1061 | 456 |
tailError := nil. |
457 |
errorNo := nil. |
|
1050 | 458 |
%{ |
459 |
OBJ _zstreamObj = __INST( zstream ); |
|
460 |
||
461 |
if( _zstreamObj != nil ) |
|
462 |
{ |
|
1195 | 463 |
int _errorNo, _count; |
464 |
zstream_s * _zstream; |
|
465 |
int _avail_in; |
|
1050 | 466 |
|
1195 | 467 |
_zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
1050 | 468 |
|
1195 | 469 |
if( _zstream->op_mode != e_opmode_inflate ) |
470 |
RETURN( nil ); |
|
1051 | 471 |
|
1195 | 472 |
_avail_in = _zstream->stream.avail_in; |
1061 | 473 |
|
1195 | 474 |
if( _zstream->stream.state == NULL ) |
475 |
{ |
|
476 |
/* processing finished : check crc and data length */ |
|
477 |
Bytef * _next_in; |
|
478 |
Bytef * _buff; |
|
479 |
uLong _tnum; |
|
480 |
int _i; |
|
1061 | 481 |
|
1195 | 482 |
_next_in = _zstream->stream.next_in; |
483 |
_buff = _zstream->tail_buff; |
|
484 |
_tnum = _zstream->tail_size; |
|
1061 | 485 |
|
1195 | 486 |
while( (_avail_in > 0) && (_tnum < 8) ) |
487 |
{ |
|
488 |
_buff[_tnum] = * _next_in; |
|
1061 | 489 |
|
1195 | 490 |
++_next_in; |
491 |
++_tnum; |
|
492 |
--_avail_in; |
|
493 |
} |
|
494 |
_zstream->tail_size = _tnum; |
|
1061 | 495 |
|
1195 | 496 |
if( _tnum < 8 ) /* test whether tail is read */ |
497 |
RETURN( __MKSMALLINT (0) ); /* need more data */ |
|
1061 | 498 |
|
1195 | 499 |
/* compute and check crc */ |
500 |
for( _tnum = 0, _i = 4; --_i >= 0; _tnum = (_tnum << 8) + _buff[_i] ); |
|
1061 | 501 |
|
1195 | 502 |
if( _tnum != _zstream->crc_32 ) |
503 |
{ tailError = __MKSMALLINT( 1 ); goto badTail; } |
|
1061 | 504 |
|
1195 | 505 |
/* compute and check data length */ |
506 |
for( _tnum = 0, _i = 8; --_i >= 4; _tnum = (_tnum << 8) + _buff[_i] ); |
|
1061 | 507 |
|
1195 | 508 |
if( _zstream->stream.total_out != _tnum ) |
509 |
{ tailError = __MKSMALLINT( 2 ); goto badTail; } |
|
1051 | 510 |
|
1195 | 511 |
_zstream->op_mode = e_opmode_unspecified; |
512 |
RETURN( nil ); |
|
513 |
} |
|
514 |
if( _avail_in == 0 ) |
|
515 |
RETURN( __MKSMALLINT (0) ); |
|
1050 | 516 |
|
1195 | 517 |
_zstream->stream.avail_out = _zstream->out_total; |
518 |
_zstream->stream.next_out = _zstream->out_ref; |
|
1050 | 519 |
|
1195 | 520 |
_errorNo = inflate( & _zstream->stream, Z_NO_FLUSH ); |
1050 | 521 |
|
1195 | 522 |
if( _errorNo == Z_STREAM_END ) |
523 |
_errorNo = inflateEnd( & _zstream->stream ); |
|
1050 | 524 |
|
1195 | 525 |
if( _errorNo == Z_OK ) |
526 |
{ |
|
527 |
_count = _zstream->out_total - _zstream->stream.avail_out; |
|
1051 | 528 |
|
1195 | 529 |
if( _count > 0 ) |
530 |
_zstream->crc_32 = crc32( _zstream->crc_32, _zstream->out_ref, _count ); |
|
1051 | 531 |
|
1195 | 532 |
RETURN( __MKSMALLINT (_count) ); |
533 |
} |
|
534 |
errorNo = __MKSMALLINT( _errorNo ); |
|
1050 | 535 |
} |
1061 | 536 |
badTail:; |
1050 | 537 |
%}. |
1061 | 538 |
errorNo ifNil:[ |
1195 | 539 |
tailError ifNotNil:[ |
540 |
tailError == 1 ifTrue:[ |
|
541 |
self zerror:'invalid compressed data--crc error' |
|
542 |
]. |
|
543 |
self zerror:'invalid compressed data--length error' |
|
544 |
]. |
|
545 |
self errorNotOpen |
|
1061 | 546 |
]. |
1050 | 547 |
self zerror:errorNo. |
548 |
! |
|
549 |
||
1045 | 550 |
zinflateInit |
1052 | 551 |
"low level - inflateInit |
552 |
" |
|
1045 | 553 |
|errorNo| |
554 |
||
555 |
errorNo := nil. |
|
556 |
||
557 |
%{ |
|
558 |
OBJ _zstreamObj = __INST( zstream ); |
|
559 |
||
560 |
if( _zstreamObj != nil ) |
|
561 |
{ |
|
1195 | 562 |
int _errorNo; |
563 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1045 | 564 |
|
1195 | 565 |
_zstream->op_mode = e_opmode_inflate; |
566 |
_errorNo = inflateInit2( & _zstream->stream, -MAX_WBITS ); |
|
1045 | 567 |
|
1195 | 568 |
if( _errorNo == Z_OK ) |
569 |
RETURN( self ); |
|
1045 | 570 |
|
1195 | 571 |
_zstream->stream.avail_in = 0; |
572 |
errorNo = __MKSMALLINT( _errorNo ); |
|
1045 | 573 |
} |
574 |
%}. |
|
575 |
errorNo ifNil:[ self errorNotOpen ]. |
|
576 |
self zerror:errorNo. |
|
577 |
! |
|
1047 | 578 |
|
1059 | 579 |
zopen |
1052 | 580 |
"low level - opens the zip stream |
581 |
" |
|
1051 | 582 |
|outTotal| |
1045 | 583 |
|
1059 | 584 |
outTotal := outputBytes size. |
1045 | 585 |
%{ |
586 |
zstream_s * _zstream = (zstream_s *) malloc( sizeof(zstream_s) ); |
|
587 |
||
588 |
if( _zstream ) |
|
589 |
{ |
|
1195 | 590 |
OBJ _zobj = __MKEXTERNALADDRESS( _zstream ); |
591 |
OBJ _outObj = __INST( outputBytes ); |
|
592 |
OBJ _inpObj = __INST( inputBytes ); |
|
1045 | 593 |
|
1195 | 594 |
zmemzero( _zstream, sizeof(zstream_s) ); |
1045 | 595 |
|
1195 | 596 |
_zstream->in_ref = (Bytef *) __externalBytesAddress( _inpObj ); |
597 |
_zstream->stream.next_in = Z_NULL; |
|
598 |
_zstream->stream.avail_in = 0; |
|
599 |
_zstream->stream.total_in = 0; |
|
1045 | 600 |
|
1195 | 601 |
_zstream->out_total = __intVal( outTotal ); |
602 |
_zstream->out_ref = (Bytef *) __externalBytesAddress( _outObj ); |
|
603 |
_zstream->stream.next_out = _zstream->out_ref; |
|
604 |
_zstream->stream.avail_out = _zstream->out_total; |
|
605 |
_zstream->stream.total_out = 0; |
|
1045 | 606 |
|
1195 | 607 |
_zstream->stream.zalloc = (alloc_func)0; |
608 |
_zstream->stream.zfree = (free_func) 0; |
|
609 |
_zstream->stream.opaque = (voidpf) 0; |
|
1045 | 610 |
|
1195 | 611 |
_zstream->crc_32 = crc32( 0L, Z_NULL, 0 ); |
612 |
_zstream->op_mode = e_opmode_unspecified; |
|
613 |
_zstream->tail_size = 0; |
|
1045 | 614 |
|
1195 | 615 |
__INST (zstream) = _zobj; |
616 |
__STORE(self, _zobj); |
|
1045 | 617 |
} |
618 |
%}. |
|
619 |
! |
|
620 |
||
1059 | 621 |
zset_avail_in:count |
1570 | 622 |
"set the 'avail_in' and compute the crc" |
1059 | 623 |
%{ |
624 |
OBJ _zstreamObj = __INST( zstream ); |
|
1045 | 625 |
|
1059 | 626 |
if( (_zstreamObj != nil) && __isSmallInteger(count) ) |
627 |
{ |
|
1828 | 628 |
int _count; |
629 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1045 | 630 |
|
1828 | 631 |
if( (_count = __intVal( count )) > 0 ) |
632 |
{ |
|
633 |
Bytef * _in_ref = _zstream->in_ref; |
|
1045 | 634 |
|
1828 | 635 |
_zstream->stream.avail_in = _count; |
636 |
_zstream->stream.next_in = _in_ref; |
|
1045 | 637 |
|
1828 | 638 |
if( _zstream->op_mode == e_opmode_deflate ) |
639 |
_zstream->crc_32 = crc32( _zstream->crc_32, _in_ref, _count ); |
|
640 |
} else { |
|
641 |
_zstream->stream.avail_in = 0; |
|
642 |
_zstream->stream.next_in = Z_NULL; |
|
643 |
} |
|
644 |
RETURN( self ); |
|
1059 | 645 |
} |
646 |
%}. |
|
647 |
zstream ifNil:[ self errorNotOpen ]. |
|
1570 | 648 |
self invalidArgument. |
1045 | 649 |
! ! |
650 |
||
651 |
!ZipStream methodsFor:'startup & release'! |
|
652 |
||
1059 | 653 |
openWithMode:aMode on:aStream |
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
654 |
|
1059 | 655 |
super openWithMode:aMode on:aStream. |
1193 | 656 |
self isReadable ifTrue:[ |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
657 |
"Check for the gzip magic id" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
658 |
|flags| |
1045 | 659 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
660 |
GZ_MAGIC_ID do:[:b| |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
661 |
onStream nextByte ~~ b ifTrue:[ self zerror:'version error' ] |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
662 |
]. |
1045 | 663 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
664 |
onStream nextByte ~~ Z_DEFLATED ifTrue:[ |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
665 |
self zerror:'invalid method (not deflated)' |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
666 |
]. |
1045 | 667 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
668 |
flags := onStream nextByte. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
669 |
(flags bitAnd:HEAD_RESERVED) ~~ 0 ifTrue:[ |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
670 |
self zerror:'wrong data format' |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
671 |
]. |
1045 | 672 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
673 |
"discard time, xflags and OS code" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
674 |
onStream skip:6. |
1045 | 675 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
676 |
(flags bitAnd:HEAD_EXTRA_FIELD) ~~ 0 ifTrue:[|len| |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
677 |
"skip the extra field" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
678 |
len := onStream nextByte + (onStream nextByte bitShift:8). |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
679 |
len timesRepeat:[ onStream nextByte ]. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
680 |
]. |
1045 | 681 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
682 |
(flags bitAnd:HEAD_ORIG_NAME) ~~ 0 ifTrue:[|b| |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
683 |
"skip the original file name" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
684 |
[ (b := onStream nextByte) ~~ 0 ] whileTrue. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
685 |
]. |
1050 | 686 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
687 |
(flags bitAnd:HEAD_CRC) ~~ 0 ifTrue:[ |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
688 |
"skip the header crc" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
689 |
onStream skip:2. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
690 |
]. |
1059 | 691 |
] ifFalse:[ |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
692 |
"write the gzip magic id |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
693 |
" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
694 |
GZ_MAGIC_ID do:[:b| onStream nextPutByte:b ]. |
1050 | 695 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
696 |
"write the method" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
697 |
onStream nextPutByte:Z_DEFLATED. |
1059 | 698 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
699 |
"write the flags" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
700 |
onStream nextPutByte:0. |
1050 | 701 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
702 |
"write time" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
703 |
4 timesRepeat:[ onStream nextPutByte:0 ]. |
1045 | 704 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
705 |
"write xflags" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
706 |
onStream nextPutByte:0. |
1059 | 707 |
|
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
708 |
"write OS code" |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
709 |
onStream nextPutByte:HEAD_OS_CODE. |
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
710 |
]. |
1045 | 711 |
! ! |
1044 | 712 |
|
713 |
!ZipStream class methodsFor:'documentation'! |
|
714 |
||
715 |
version |
|
1828 | 716 |
^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.26 2007-01-16 16:21:51 ca Exp $' |
1044 | 717 |
! ! |
1193 | 718 |
|
1047 | 719 |
ZipStream initialize! |