author | Stefan Vogel <sv@exept.de> |
Tue, 30 Jun 2009 21:05:10 +0200 | |
changeset 2178 | f6f0d919aed2 |
parent 2177 | 875e7abd9620 |
child 2190 | 6c3f9241753a |
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 |
||
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 |
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
145 |
"open to read data compressed from stream, |
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 |
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
151 |
"open to write data compressed to stream, |
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))) { |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
253 |
char __byte; |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
254 |
uLong __crc; |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
255 |
|
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
256 |
if (__isCharacter(aCharacterOrByte)) { |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
257 |
__byte = __smallIntegerVal(__characterVal(aCharacterOrByte)); |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
258 |
} else if (__isSmallInteger(aCharacterOrByte)) { |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
259 |
__byte = __intVal(aCharacterOrByte); |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
260 |
} else{ |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
261 |
goto err; |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
262 |
} |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
263 |
|
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
264 |
__crc = __unsignedLongIntVal( crc ); |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
265 |
__crc = crc32(__crc, (Byte *) &__byte, 1 ); |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
266 |
RETURN( __MKUINT(__crc) ); |
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)) { |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
315 |
char * __bytes = 0; |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
316 |
unsigned int __size; |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
317 |
uLong __crc = __unsignedLongIntVal( crc ); |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
318 |
uInt __start = __intVal( start ); |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
319 |
uInt __stop = __intVal( stop ); |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
320 |
|
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
321 |
if (__isBytes(bytesIn)) { |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
322 |
__bytes = __byteArrayVal(bytesIn); |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
323 |
__size = __byteArraySize(bytesIn); |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
324 |
} else if (__isString(bytesIn)) { |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
325 |
__bytes = __stringVal(bytesIn); |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
326 |
__size = __stringSize(bytesIn); |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
327 |
} else { |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
328 |
goto err; |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
329 |
} |
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 |
|
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
332 |
if (__start < 1 || __start > __size) goto err; |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
333 |
if (__stop < 1 || __stop > __size) goto err; |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
334 |
|
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
335 |
__size = __stop - __start + 1; |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
336 |
|
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
337 |
__bytes += __start - 1; |
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
338 |
__crc = crc32(__crc, (Byte *) __bytes, __size ); |
1439
134b4620d6d0
add ZipInterface compatibility used by SEL MDT Application
ab
parents:
1308
diff
changeset
|
339 |
|
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
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 |
||
1059 | 446 |
|errorNo level| |
1045 | 447 |
|
448 |
errorNo := nil. |
|
1059 | 449 |
level := BlockSize. |
1045 | 450 |
%{ |
451 |
OBJ _zstreamObj = __INST( zstream ); |
|
452 |
||
1059 | 453 |
if( (_zstreamObj != nil) && __isSmallInteger(level) ) |
1045 | 454 |
{ |
1828 | 455 |
int _errorNo; |
456 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1045 | 457 |
|
1828 | 458 |
_zstream->op_mode = e_opmode_deflate; |
1051 | 459 |
|
1828 | 460 |
_errorNo = deflateInit2( & _zstream->stream |
461 |
, __intVal( level ) |
|
462 |
, Z_DEFLATED |
|
463 |
, -MAX_WBITS |
|
464 |
, DEF_MEM_LEVEL |
|
465 |
, Z_DEFAULT_STRATEGY |
|
466 |
); |
|
1045 | 467 |
|
1828 | 468 |
if( _errorNo == Z_OK ) |
469 |
RETURN( self ); |
|
1045 | 470 |
|
1828 | 471 |
errorNo = __MKSMALLINT( _errorNo ); |
1045 | 472 |
} |
473 |
%}. |
|
474 |
errorNo ifNil:[ |
|
1828 | 475 |
zstream ifNil:[ self errorNotOpen ]. |
476 |
self invalidArgument . |
|
1045 | 477 |
]. |
478 |
self zerror:errorNo. |
|
479 |
! |
|
480 |
||
1059 | 481 |
zget_avail_out |
482 |
"low level - get the number of available out bytes |
|
483 |
" |
|
484 |
%{ |
|
485 |
OBJ _zstreamObj = __INST( zstream ); |
|
486 |
||
487 |
if( _zstreamObj != nil ) |
|
488 |
{ |
|
1195 | 489 |
uInt _count; |
490 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1059 | 491 |
|
1195 | 492 |
_count = _zstream->out_total - _zstream->stream.avail_out; |
1059 | 493 |
|
1195 | 494 |
RETURN( __MKSMALLINT (_count) ); |
1059 | 495 |
} |
496 |
%}. |
|
497 |
self errorNotOpen. |
|
498 |
! |
|
499 |
||
1050 | 500 |
zinflate |
1052 | 501 |
"low level - inflate |
502 |
" |
|
1061 | 503 |
|errorNo tailError| |
1050 | 504 |
|
1061 | 505 |
tailError := nil. |
506 |
errorNo := nil. |
|
1050 | 507 |
%{ |
508 |
OBJ _zstreamObj = __INST( zstream ); |
|
509 |
||
510 |
if( _zstreamObj != nil ) |
|
511 |
{ |
|
1195 | 512 |
int _errorNo, _count; |
513 |
zstream_s * _zstream; |
|
514 |
int _avail_in; |
|
1050 | 515 |
|
1195 | 516 |
_zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
1050 | 517 |
|
1195 | 518 |
if( _zstream->op_mode != e_opmode_inflate ) |
519 |
RETURN( nil ); |
|
1051 | 520 |
|
1195 | 521 |
_avail_in = _zstream->stream.avail_in; |
1061 | 522 |
|
1195 | 523 |
if( _zstream->stream.state == NULL ) |
524 |
{ |
|
525 |
/* processing finished : check crc and data length */ |
|
526 |
Bytef * _next_in; |
|
527 |
Bytef * _buff; |
|
528 |
uLong _tnum; |
|
529 |
int _i; |
|
1061 | 530 |
|
1195 | 531 |
_next_in = _zstream->stream.next_in; |
532 |
_buff = _zstream->tail_buff; |
|
533 |
_tnum = _zstream->tail_size; |
|
1061 | 534 |
|
1195 | 535 |
while( (_avail_in > 0) && (_tnum < 8) ) |
536 |
{ |
|
537 |
_buff[_tnum] = * _next_in; |
|
1061 | 538 |
|
1195 | 539 |
++_next_in; |
540 |
++_tnum; |
|
541 |
--_avail_in; |
|
542 |
} |
|
543 |
_zstream->tail_size = _tnum; |
|
1061 | 544 |
|
1195 | 545 |
if( _tnum < 8 ) /* test whether tail is read */ |
546 |
RETURN( __MKSMALLINT (0) ); /* need more data */ |
|
1061 | 547 |
|
1195 | 548 |
/* compute and check crc */ |
549 |
for( _tnum = 0, _i = 4; --_i >= 0; _tnum = (_tnum << 8) + _buff[_i] ); |
|
1061 | 550 |
|
1195 | 551 |
if( _tnum != _zstream->crc_32 ) |
552 |
{ tailError = __MKSMALLINT( 1 ); goto badTail; } |
|
1061 | 553 |
|
1195 | 554 |
/* compute and check data length */ |
555 |
for( _tnum = 0, _i = 8; --_i >= 4; _tnum = (_tnum << 8) + _buff[_i] ); |
|
1061 | 556 |
|
1195 | 557 |
if( _zstream->stream.total_out != _tnum ) |
558 |
{ tailError = __MKSMALLINT( 2 ); goto badTail; } |
|
1051 | 559 |
|
1195 | 560 |
_zstream->op_mode = e_opmode_unspecified; |
561 |
RETURN( nil ); |
|
562 |
} |
|
563 |
if( _avail_in == 0 ) |
|
564 |
RETURN( __MKSMALLINT (0) ); |
|
1050 | 565 |
|
1195 | 566 |
_zstream->stream.avail_out = _zstream->out_total; |
567 |
_zstream->stream.next_out = _zstream->out_ref; |
|
1050 | 568 |
|
1195 | 569 |
_errorNo = inflate( & _zstream->stream, Z_NO_FLUSH ); |
1050 | 570 |
|
1195 | 571 |
if( _errorNo == Z_STREAM_END ) |
572 |
_errorNo = inflateEnd( & _zstream->stream ); |
|
1050 | 573 |
|
1195 | 574 |
if( _errorNo == Z_OK ) |
575 |
{ |
|
576 |
_count = _zstream->out_total - _zstream->stream.avail_out; |
|
1051 | 577 |
|
1195 | 578 |
if( _count > 0 ) |
579 |
_zstream->crc_32 = crc32( _zstream->crc_32, _zstream->out_ref, _count ); |
|
1051 | 580 |
|
1195 | 581 |
RETURN( __MKSMALLINT (_count) ); |
582 |
} |
|
583 |
errorNo = __MKSMALLINT( _errorNo ); |
|
1050 | 584 |
} |
1061 | 585 |
badTail:; |
1050 | 586 |
%}. |
1061 | 587 |
errorNo ifNil:[ |
1195 | 588 |
tailError ifNotNil:[ |
589 |
tailError == 1 ifTrue:[ |
|
590 |
self zerror:'invalid compressed data--crc error' |
|
591 |
]. |
|
592 |
self zerror:'invalid compressed data--length error' |
|
593 |
]. |
|
594 |
self errorNotOpen |
|
1061 | 595 |
]. |
1050 | 596 |
self zerror:errorNo. |
597 |
! |
|
598 |
||
1045 | 599 |
zinflateInit |
1052 | 600 |
"low level - inflateInit |
601 |
" |
|
1045 | 602 |
|errorNo| |
603 |
||
604 |
errorNo := nil. |
|
605 |
||
606 |
%{ |
|
607 |
OBJ _zstreamObj = __INST( zstream ); |
|
608 |
||
609 |
if( _zstreamObj != nil ) |
|
610 |
{ |
|
1195 | 611 |
int _errorNo; |
612 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1045 | 613 |
|
1195 | 614 |
_zstream->op_mode = e_opmode_inflate; |
615 |
_errorNo = inflateInit2( & _zstream->stream, -MAX_WBITS ); |
|
1045 | 616 |
|
1195 | 617 |
if( _errorNo == Z_OK ) |
618 |
RETURN( self ); |
|
1045 | 619 |
|
1195 | 620 |
_zstream->stream.avail_in = 0; |
621 |
errorNo = __MKSMALLINT( _errorNo ); |
|
1045 | 622 |
} |
623 |
%}. |
|
624 |
errorNo ifNil:[ self errorNotOpen ]. |
|
625 |
self zerror:errorNo. |
|
626 |
! |
|
1047 | 627 |
|
1059 | 628 |
zopen |
1052 | 629 |
"low level - opens the zip stream |
630 |
" |
|
1051 | 631 |
|outTotal| |
1045 | 632 |
|
1059 | 633 |
outTotal := outputBytes size. |
1045 | 634 |
%{ |
635 |
zstream_s * _zstream = (zstream_s *) malloc( sizeof(zstream_s) ); |
|
636 |
||
637 |
if( _zstream ) |
|
638 |
{ |
|
1195 | 639 |
OBJ _zobj = __MKEXTERNALADDRESS( _zstream ); |
640 |
OBJ _outObj = __INST( outputBytes ); |
|
641 |
OBJ _inpObj = __INST( inputBytes ); |
|
1045 | 642 |
|
1195 | 643 |
zmemzero( _zstream, sizeof(zstream_s) ); |
1045 | 644 |
|
1195 | 645 |
_zstream->in_ref = (Bytef *) __externalBytesAddress( _inpObj ); |
646 |
_zstream->stream.next_in = Z_NULL; |
|
647 |
_zstream->stream.avail_in = 0; |
|
648 |
_zstream->stream.total_in = 0; |
|
1045 | 649 |
|
1195 | 650 |
_zstream->out_total = __intVal( outTotal ); |
651 |
_zstream->out_ref = (Bytef *) __externalBytesAddress( _outObj ); |
|
652 |
_zstream->stream.next_out = _zstream->out_ref; |
|
653 |
_zstream->stream.avail_out = _zstream->out_total; |
|
654 |
_zstream->stream.total_out = 0; |
|
1045 | 655 |
|
1195 | 656 |
_zstream->stream.zalloc = (alloc_func)0; |
657 |
_zstream->stream.zfree = (free_func) 0; |
|
658 |
_zstream->stream.opaque = (voidpf) 0; |
|
1045 | 659 |
|
1195 | 660 |
_zstream->crc_32 = crc32( 0L, Z_NULL, 0 ); |
661 |
_zstream->op_mode = e_opmode_unspecified; |
|
662 |
_zstream->tail_size = 0; |
|
1045 | 663 |
|
1195 | 664 |
__INST (zstream) = _zobj; |
665 |
__STORE(self, _zobj); |
|
1045 | 666 |
} |
667 |
%}. |
|
668 |
! |
|
669 |
||
1059 | 670 |
zset_avail_in:count |
1570 | 671 |
"set the 'avail_in' and compute the crc" |
1059 | 672 |
%{ |
673 |
OBJ _zstreamObj = __INST( zstream ); |
|
1045 | 674 |
|
1059 | 675 |
if( (_zstreamObj != nil) && __isSmallInteger(count) ) |
676 |
{ |
|
1828 | 677 |
int _count; |
678 |
zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj ); |
|
1045 | 679 |
|
1828 | 680 |
if( (_count = __intVal( count )) > 0 ) |
681 |
{ |
|
682 |
Bytef * _in_ref = _zstream->in_ref; |
|
1045 | 683 |
|
1828 | 684 |
_zstream->stream.avail_in = _count; |
685 |
_zstream->stream.next_in = _in_ref; |
|
1045 | 686 |
|
1828 | 687 |
if( _zstream->op_mode == e_opmode_deflate ) |
688 |
_zstream->crc_32 = crc32( _zstream->crc_32, _in_ref, _count ); |
|
689 |
} else { |
|
690 |
_zstream->stream.avail_in = 0; |
|
691 |
_zstream->stream.next_in = Z_NULL; |
|
692 |
} |
|
693 |
RETURN( self ); |
|
1059 | 694 |
} |
695 |
%}. |
|
696 |
zstream ifNil:[ self errorNotOpen ]. |
|
1570 | 697 |
self invalidArgument. |
1045 | 698 |
! ! |
699 |
||
700 |
!ZipStream methodsFor:'startup & release'! |
|
701 |
||
1059 | 702 |
openWithMode:aMode on:aStream |
2006
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
703 |
"open stream and write or check gzip header" |
2019 | 704 |
|
1059 | 705 |
super openWithMode:aMode on:aStream. |
2019 | 706 |
|
1193 | 707 |
self isReadable ifTrue:[ |
2006
0ad76801137e
add instance creation methods to allow to open the ZipStream as
ab
parents:
1847
diff
changeset
|
708 |
"Check for the gzip magic id" |
2019 | 709 |
self readHeader |
710 |
] ifFalse:[ |
|
711 |
"write the gzip magic id" |
|
712 |
self writeHeader |
|
713 |
]. |
|
714 |
! |
|
1045 | 715 |
|
2019 | 716 |
readHeader |
717 |
"Check for the gzip magic id" |
|
718 |
|flags| |
|
1045 | 719 |
|
2019 | 720 |
GZ_MAGIC_ID do:[:b| |
721 |
onStream nextByte ~~ b ifTrue:[ self zerror:'version error' ] |
|
722 |
]. |
|
723 |
||
724 |
onStream nextByte ~~ Z_DEFLATED ifTrue:[ |
|
725 |
self zerror:'invalid method (not deflated)' |
|
726 |
]. |
|
1045 | 727 |
|
2019 | 728 |
flags := onStream nextByte. |
729 |
(flags bitAnd:HEAD_RESERVED) ~~ 0 ifTrue:[ |
|
730 |
self zerror:'wrong data format' |
|
731 |
]. |
|
1045 | 732 |
|
2019 | 733 |
"discard time, xflags and OS code" |
734 |
onStream skip:6. |
|
1045 | 735 |
|
2019 | 736 |
(flags bitAnd:HEAD_EXTRA_FIELD) ~~ 0 ifTrue:[|len| |
737 |
"skip the extra field" |
|
738 |
len := onStream nextByte + (onStream nextByte bitShift:8). |
|
739 |
len timesRepeat:[ onStream nextByte ]. |
|
740 |
]. |
|
1050 | 741 |
|
2019 | 742 |
(flags bitAnd:HEAD_ORIG_NAME) ~~ 0 ifTrue:[|b| |
743 |
"skip the original file name" |
|
744 |
[ (b := onStream nextByte) ~~ 0 ] whileTrue. |
|
745 |
]. |
|
746 |
||
747 |
(flags bitAnd:HEAD_CRC) ~~ 0 ifTrue:[ |
|
748 |
"skip the header crc" |
|
749 |
onStream skip:2. |
|
750 |
]. |
|
751 |
! |
|
1050 | 752 |
|
2019 | 753 |
writeHeader |
754 |
"write the gzip magic id" |
|
1059 | 755 |
|
2019 | 756 |
GZ_MAGIC_ID do:[:b| onStream nextPutByte:b ]. |
757 |
||
758 |
"write the method" |
|
759 |
onStream nextPutByte:Z_DEFLATED. |
|
1050 | 760 |
|
2019 | 761 |
"write the flags" |
762 |
onStream nextPutByte:0. |
|
763 |
||
764 |
"write time" |
|
765 |
4 timesRepeat:[ onStream nextPutByte:0 ]. |
|
1045 | 766 |
|
2019 | 767 |
"write xflags" |
768 |
onStream nextPutByte:0. |
|
1059 | 769 |
|
2019 | 770 |
"write OS code" |
771 |
onStream nextPutByte:HEAD_OS_CODE. |
|
1045 | 772 |
! ! |
1044 | 773 |
|
774 |
!ZipStream class methodsFor:'documentation'! |
|
775 |
||
776 |
version |
|
2178
f6f0d919aed2
Fix windows compilation bug in 1.31
Stefan Vogel <sv@exept.de>
parents:
2177
diff
changeset
|
777 |
^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.33 2009-06-30 19:05:10 stefan Exp $' |
1044 | 778 |
! ! |
1193 | 779 |
|
1047 | 780 |
ZipStream initialize! |