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