author | Claus Gittinger <cg@exept.de> |
Fri, 31 Jul 2009 13:16:42 +0200 | |
changeset 2190 | 6c3f9241753a |
parent 2005 | a6ef1083aa32 |
child 2191 | 7cb40c5e5511 |
permissions | -rw-r--r-- |
1308 | 1 |
" |
2 |
COPYRIGHT (c) 2002 by eXept Software AG |
|
2190 | 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' }" |
1059 | 13 |
|
14 |
Stream subclass:#CompressionStream |
|
1193 | 15 |
instanceVariableNames:'onStream hitEOF binary position readLimit mode inputBytes |
16 |
outputBytes zstream' |
|
17 |
classVariableNames:'BlockSize' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'System-Compress' |
|
1059 | 20 |
! |
21 |
||
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
22 |
!CompressionStream class methodsFor:'documentation'! |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
23 |
|
1308 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 2002 by eXept Software AG |
|
2190 | 27 |
All Rights Reserved |
1308 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
38 |
documentation |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
39 |
" |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
40 |
Abstract superclass of streams that compress or deconpress data |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
41 |
|
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
42 |
[author:] |
2190 | 43 |
Claus Atzkern |
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
44 |
|
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
45 |
[instance variables:] |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
46 |
|
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
47 |
[class variables:] |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
48 |
|
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
49 |
[see also:] |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
50 |
|
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
51 |
" |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
52 |
! ! |
1193 | 53 |
|
1059 | 54 |
!CompressionStream class methodsFor:'initialization'! |
55 |
||
56 |
initialize |
|
57 |
BlockSize := 6. |
|
58 |
! ! |
|
59 |
||
60 |
!CompressionStream class methodsFor:'instance creation'! |
|
61 |
||
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
62 |
readOpenOn:aStream |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
63 |
"open to read data from an compressed stream" |
1193 | 64 |
|
1059 | 65 |
^ self basicNew openWithMode:#readonly on:aStream |
66 |
! |
|
67 |
||
68 |
writeOpenOn:aStream |
|
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
69 |
"open to write data compressed to stream" |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
70 |
|
1059 | 71 |
^ self basicNew openWithMode:#writeonly on:aStream |
72 |
! ! |
|
73 |
||
74 |
!CompressionStream methodsFor:'accessing'! |
|
75 |
||
76 |
binary |
|
77 |
"switch to binary mode - default is text |
|
78 |
" |
|
79 |
binary := true. |
|
80 |
! |
|
81 |
||
82 |
text |
|
1193 | 83 |
"switch to text mode - default is text" |
84 |
||
1059 | 85 |
binary := false. |
86 |
! ! |
|
87 |
||
88 |
!CompressionStream methodsFor:'error handling'! |
|
89 |
||
90 |
errorNotOpen |
|
1193 | 91 |
"report an error, that the stream has not been opened" |
92 |
||
1059 | 93 |
self zerror:'not open'. |
94 |
! |
|
95 |
||
96 |
errorReadOnly |
|
1193 | 97 |
"report an error, that the stream is a readOnly stream" |
98 |
||
1059 | 99 |
self zerror:'is readonly' |
100 |
! |
|
101 |
||
102 |
errorWriteOnly |
|
1193 | 103 |
"report an error, that the stream is a writeOnly stream" |
104 |
||
1059 | 105 |
self zerror:'is writeonly' |
106 |
! |
|
107 |
||
108 |
invalidArgument |
|
1193 | 109 |
"called if a method is invoked with invalid parameters" |
110 |
||
1059 | 111 |
self zerror:'invalid arguments'. |
112 |
! |
|
113 |
||
1481 | 114 |
pastEndRead |
1059 | 115 |
self zerror:'end of stream'. |
1782 | 116 |
^ nil |
117 |
||
118 |
"Modified: / 18-11-2006 / 15:37:08 / cg" |
|
1059 | 119 |
! |
120 |
||
121 |
zerror:anError |
|
122 |
|error| |
|
123 |
||
124 |
zstream isNil ifTrue:[ |
|
2190 | 125 |
error := 'not open'. |
1059 | 126 |
] ifFalse:[ |
2190 | 127 |
anError isNumber ifTrue:[ |
128 |
anError == 1 ifTrue:[ error := 'stream at end' ] |
|
129 |
ifFalse:[anError == -1 ifTrue:[ error := 'processing error: ', anError printString ] |
|
130 |
ifFalse:[anError == -2 ifTrue:[ error := 'processing error' ] |
|
131 |
ifFalse:[anError == -3 ifTrue:[ error := 'input data are corrupted' ] |
|
132 |
ifFalse:[anError == -4 ifTrue:[ error := 'not enough memory' ] |
|
133 |
ifFalse:[anError == -5 ifTrue:[ error := 'not enough memory in the output stream' ] |
|
134 |
ifFalse:[anError == -6 ifTrue:[ error := 'version error' ] |
|
135 |
ifFalse:[ |
|
136 |
error := 'compressing error: ', anError printString |
|
137 |
]]]]]]]. |
|
138 |
] ifFalse:[ |
|
139 |
error := anError printString |
|
140 |
]. |
|
1059 | 141 |
]. |
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
142 |
StreamError raiseErrorString:(self class name , ': ', error). |
1059 | 143 |
! ! |
144 |
||
145 |
!CompressionStream methodsFor:'finalization'! |
|
146 |
||
147 |
executor |
|
2190 | 148 |
"redefined to return a lightweight copy |
1193 | 149 |
- all we need is the memory handle" |
150 |
||
2190 | 151 |
^ self class basicNew finalizeCopy:zstream. |
1059 | 152 |
! |
153 |
||
154 |
finalize |
|
1061 | 155 |
"the compressin-stream was garbage collected; |
1193 | 156 |
close the underlying zip-stream" |
157 |
||
1061 | 158 |
self closeZStream. |
1059 | 159 |
! |
160 |
||
161 |
finalizeCopy:aZStream |
|
1193 | 162 |
"used for finalization to close the underlying zip-stream" |
163 |
||
1059 | 164 |
zstream := aZStream. |
165 |
! ! |
|
166 |
||
167 |
!CompressionStream methodsFor:'low level'! |
|
168 |
||
2190 | 169 |
z_nextAvailableInto:aCollection startingAt:offset maxCount:maxCount |
1079 | 170 |
"read the next available bytes into a collection, a string or byteArray; |
1193 | 171 |
returns the size read" |
172 |
||
1079 | 173 |
|start count avail| |
174 |
||
175 |
avail := readLimit - position. |
|
176 |
avail > 0 ifFalse:[^ 0]. |
|
177 |
||
178 |
count := aCollection size - offset + 1. |
|
179 |
||
2190 | 180 |
count < 0 ifTrue:[ |
181 |
self zerror:'invalid arguments' |
|
182 |
]. |
|
183 |
count == 0 ifTrue:[ |
|
1195 | 184 |
^ 0 |
1079 | 185 |
]. |
2190 | 186 |
|
187 |
count := avail min:count. |
|
188 |
maxCount notNil ifTrue:[ count := count min:maxCount ]. |
|
189 |
||
190 |
start := position. |
|
1079 | 191 |
position := position + count. |
192 |
||
193 |
%{ unsigned char * _dstPt; |
|
194 |
||
195 |
if( __isBytes(aCollection) ) { |
|
1195 | 196 |
_dstPt = (unsigned char *) (__ByteArrayInstPtr(aCollection)->ba_element); |
1079 | 197 |
} else if (__isString(aCollection)) { |
1195 | 198 |
_dstPt = (unsigned char *) (__stringVal( aCollection)); |
1079 | 199 |
} else |
1195 | 200 |
_dstPt = (unsigned char *) 0; |
1079 | 201 |
|
202 |
if( _dstPt ) |
|
203 |
{ |
|
1195 | 204 |
int _loop, _count, _offset; |
205 |
unsigned char * _srcPt; |
|
206 |
OBJ _srcObj = __INST( outputBytes ); |
|
1079 | 207 |
|
1195 | 208 |
_offset = __intVal( offset ); |
209 |
_dstPt = _dstPt + _offset - 1; |
|
1079 | 210 |
|
1195 | 211 |
_srcPt = (unsigned char *) __externalBytesAddress( _srcObj ); |
212 |
_srcPt += __intVal( start ); |
|
213 |
_count = __intVal( count ); |
|
1079 | 214 |
|
1195 | 215 |
for( _loop = 0; _loop < _count; ++_loop ) |
216 |
* _dstPt++ = * _srcPt++; |
|
1079 | 217 |
|
1195 | 218 |
RETURN(__MKSMALLINT(_count)); |
1079 | 219 |
} |
220 |
%}. |
|
221 |
||
222 |
^ self zerror:'invalid argument' |
|
223 |
! |
|
224 |
||
2190 | 225 |
z_nextAvailableInto:aCollection startingAt:offset |
226 |
^ self z_nextAvailableInto:aCollection startingAt:offset maxCount:nil |
|
227 |
! |
|
228 |
||
1193 | 229 |
zclose |
230 |
"low level close of the zip stream" |
|
231 |
||
232 |
^ self subclassResponsibility |
|
233 |
! |
|
234 |
||
235 |
zdeflate |
|
236 |
"low level - deflate |
|
237 |
returns false if the deflate operation is finished otherwise true" |
|
238 |
||
239 |
^ self subclassResponsibility |
|
240 |
! |
|
241 |
||
242 |
zdeflateInit |
|
243 |
"low level - deflateInit |
|
244 |
initialize the deflate mode, write header" |
|
245 |
||
246 |
^ self subclassResponsibility |
|
247 |
! |
|
248 |
||
249 |
zget_avail_out |
|
250 |
"low level - get the number of available out bytes" |
|
251 |
||
252 |
^ self subclassResponsibility |
|
253 |
! |
|
254 |
||
255 |
zinflate |
|
256 |
"low level - inflate |
|
257 |
returns nil if at uncompress is finished, or the number of |
|
258 |
available bytes in the output-buffer" |
|
259 |
||
260 |
^ self subclassResponsibility |
|
261 |
! |
|
262 |
||
263 |
zinflateInit |
|
264 |
"low level - inflateInit |
|
265 |
initialize the inflate mode, read and check header" |
|
266 |
||
267 |
^ self subclassResponsibility |
|
268 |
! |
|
269 |
||
1059 | 270 |
zopen |
271 |
"low level - opens the zip stream |
|
1193 | 272 |
create the resources" |
273 |
||
1059 | 274 |
^ self subclassResponsibility |
275 |
! |
|
276 |
||
277 |
zset_avail_in:count |
|
1193 | 278 |
"set the 'avail_in' and compute the crc" |
279 |
||
1059 | 280 |
^ self subclassResponsibility |
281 |
! ! |
|
282 |
||
283 |
!CompressionStream methodsFor:'private'! |
|
284 |
||
1061 | 285 |
closeZStream |
1193 | 286 |
"close the zip-stream" |
287 |
||
1061 | 288 |
onStream := mode := nil. |
289 |
hitEOF := true. |
|
290 |
||
291 |
zstream ifNotNil:[ |
|
1195 | 292 |
self unregisterForFinalization. |
293 |
self zclose. |
|
294 |
zstream := nil. |
|
1061 | 295 |
]. |
296 |
! |
|
297 |
||
1081 | 298 |
contentsSpecies |
1193 | 299 |
"return the kind of object to be returned by sub-collection builders" |
300 |
||
301 |
binary == true ifTrue:[^ ByteArray]. |
|
302 |
^ String |
|
1081 | 303 |
! |
304 |
||
1059 | 305 |
onStreamPutBytes:count from:data |
1193 | 306 |
"write compressed data to the (output) stream" |
307 |
||
1059 | 308 |
onStream nextPutBytes:count from:data startingAt:1 |
309 |
! ! |
|
310 |
||
311 |
!CompressionStream methodsFor:'queries'! |
|
312 |
||
313 |
atEnd |
|
1193 | 314 |
"return true if the end of the compressed input stream has been reached" |
315 |
||
1829 | 316 |
^ self canReadWithoutBlocking not |
1059 | 317 |
! |
318 |
||
1062 | 319 |
canReadWithoutBlocking |
320 |
"returns true if data are available for reading; |
|
321 |
false if the stream is at end. |
|
1193 | 322 |
updates the readLimit and position" |
323 |
||
1829 | 324 |
|n| |
325 |
||
1062 | 326 |
mode == #readonly ifFalse:[ |
2190 | 327 |
self errorWriteOnly |
1062 | 328 |
]. |
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
329 |
hitEOF == true ifTrue:[^ false]. |
1062 | 330 |
|
331 |
position >= readLimit ifTrue:[ |
|
2190 | 332 |
[(readLimit := self zinflate) == 0] whileTrue:[ |
333 |
n := onStream nextBytes:(inputBytes size) into:inputBytes startingAt:1. |
|
1829 | 334 |
|
2190 | 335 |
n == 0 ifTrue:[ |
336 |
hitEOF := true. |
|
337 |
^ false |
|
338 |
]. |
|
339 |
self zset_avail_in:n. |
|
340 |
]. |
|
341 |
readLimit isNil ifTrue:[ |
|
342 |
hitEOF := true. |
|
343 |
^ false |
|
344 |
]. |
|
345 |
position := 0. |
|
1062 | 346 |
]. |
347 |
^ true |
|
348 |
! |
|
349 |
||
1059 | 350 |
isBinary |
351 |
"return true, if the stream is in binary (as opposed to text-) mode. |
|
1193 | 352 |
The default when created is false" |
353 |
||
1059 | 354 |
^ binary |
355 |
! |
|
356 |
||
357 |
isOpen |
|
1193 | 358 |
"return true, if this stream is open" |
359 |
||
1059 | 360 |
^ onStream notNil |
361 |
! |
|
362 |
||
1193 | 363 |
isReadable |
364 |
"return true, if this stream can be read from" |
|
365 |
||
1059 | 366 |
^ mode == #readonly |
367 |
! |
|
368 |
||
1193 | 369 |
isWritable |
370 |
"return true, if this stream can be written to" |
|
371 |
||
1059 | 372 |
^ mode == #writeonly |
373 |
! ! |
|
374 |
||
375 |
!CompressionStream methodsFor:'reading'! |
|
376 |
||
377 |
contents |
|
1193 | 378 |
"return the entire contents of and close the stream" |
379 |
||
1081 | 380 |
|species stream bfsize buffer count| |
1059 | 381 |
|
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
382 |
mode == #readonly ifFalse:[ |
2190 | 383 |
self errorWriteOnly |
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
384 |
]. |
1062 | 385 |
bfsize := outputBytes size. |
1059 | 386 |
|
1081 | 387 |
species := self contentsSpecies. |
388 |
buffer := species new:bfsize. |
|
1428
c9f7ec7d0c84
testcases extracted into spearate class
Claus Gittinger <cg@exept.de>
parents:
1308
diff
changeset
|
389 |
stream := WriteStream on:(species new:bfsize). |
1079 | 390 |
|
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
391 |
[self canReadWithoutBlocking] whileTrue:[ |
2190 | 392 |
count := self z_nextAvailableInto:buffer startingAt:1. |
1079 | 393 |
|
2190 | 394 |
count == bfsize ifTrue:[ |
395 |
stream nextPutAll:buffer. |
|
396 |
] ifFalse:[ |
|
397 |
count > 0 ifTrue:[ |
|
398 |
stream nextPutAll:buffer startingAt:1 to:count. |
|
399 |
] |
|
400 |
]. |
|
1059 | 401 |
]. |
1062 | 402 |
self close. |
1193 | 403 |
^ stream contents |
1059 | 404 |
! |
405 |
||
406 |
next |
|
407 |
"return the next element, a character or byte (textmode) |
|
1193 | 408 |
return nil, if there are no more elements" |
409 |
||
1059 | 410 |
|byte| |
411 |
||
1062 | 412 |
self canReadWithoutBlocking ifFalse:[ |
1195 | 413 |
"there is no more element; the stream is at end" |
414 |
^ nil |
|
1059 | 415 |
]. |
416 |
position := position + 1. |
|
417 |
byte := outputBytes at:position. |
|
418 |
||
419 |
binary ifTrue:[^ byte ]. |
|
1193 | 420 |
^ Character value:byte |
1082 | 421 |
! |
422 |
||
423 |
next:n |
|
424 |
"return the next count elements of the stream as a collection. |
|
1193 | 425 |
Redefined to return a String or ByteArray and for optimization" |
426 |
||
1082 | 427 |
|data count offset species| |
428 |
||
429 |
species := self contentsSpecies. |
|
430 |
||
431 |
self canReadWithoutBlocking ifFalse:[ |
|
1195 | 432 |
^ species new |
1082 | 433 |
]. |
434 |
data := species new:n. |
|
435 |
offset := 1. |
|
436 |
||
1193 | 437 |
[self canReadWithoutBlocking] whileTrue:[ |
1195 | 438 |
count := self z_nextAvailableInto:data startingAt:offset. |
439 |
offset := count + offset. |
|
440 |
offset > n ifTrue:[^ data] |
|
1082 | 441 |
]. |
442 |
^ data copyFrom:1 to:(offset - 1) |
|
443 |
! |
|
444 |
||
2190 | 445 |
skip:count |
1082 | 446 |
"skip count objects, return the receiver |
1193 | 447 |
redefined for optimization" |
448 |
||
1082 | 449 |
|n avail| |
450 |
||
451 |
n := count. |
|
452 |
||
1193 | 453 |
n <= 0 ifTrue:[ |
2190 | 454 |
n ~~ 0 ifTrue:[ |
455 |
"dont know how to unread ..." |
|
456 |
PositionError raiseRequest |
|
457 |
]. |
|
458 |
^ self |
|
1083 | 459 |
]. |
460 |
||
1193 | 461 |
[self canReadWithoutBlocking] whileTrue:[ |
2190 | 462 |
avail := readLimit - position. |
1082 | 463 |
|
2190 | 464 |
avail >= n ifTrue:[ |
465 |
position := position + n. |
|
466 |
^ self |
|
467 |
]. |
|
468 |
position := readLimit := 0. "/ reset input |
|
469 |
n := n - avail. |
|
1082 | 470 |
]. |
1059 | 471 |
! ! |
472 |
||
473 |
!CompressionStream methodsFor:'startup & release'! |
|
474 |
||
475 |
close |
|
1193 | 476 |
"close the zip-stream" |
477 |
||
1059 | 478 |
hitEOF := true. |
1193 | 479 |
zstream notNil ifTrue:[ |
1195 | 480 |
self flush. |
481 |
self closeZStream. |
|
1059 | 482 |
]. |
483 |
! |
|
484 |
||
485 |
openWithMode:aMode on:aStream |
|
1061 | 486 |
"open the zip-stream on a stream |
2005
a6ef1083aa32
add streamOpenWithMode:on: method to allow to redefine the
ab
parents:
1829
diff
changeset
|
487 |
can be reimplemented to do some additional stuff (e.g. gzip header) like |
a6ef1083aa32
add streamOpenWithMode:on: method to allow to redefine the
ab
parents:
1829
diff
changeset
|
488 |
in the ZipStream |
a6ef1083aa32
add streamOpenWithMode:on: method to allow to redefine the
ab
parents:
1829
diff
changeset
|
489 |
" |
a6ef1083aa32
add streamOpenWithMode:on: method to allow to redefine the
ab
parents:
1829
diff
changeset
|
490 |
^ self streamOpenWithMode:aMode on:aStream. |
a6ef1083aa32
add streamOpenWithMode:on: method to allow to redefine the
ab
parents:
1829
diff
changeset
|
491 |
! |
a6ef1083aa32
add streamOpenWithMode:on: method to allow to redefine the
ab
parents:
1829
diff
changeset
|
492 |
|
a6ef1083aa32
add streamOpenWithMode:on: method to allow to redefine the
ab
parents:
1829
diff
changeset
|
493 |
streamOpenWithMode:aMode on:aStream |
a6ef1083aa32
add streamOpenWithMode:on: method to allow to redefine the
ab
parents:
1829
diff
changeset
|
494 |
"open the compression stream on a stream |
2190 | 495 |
#readonly uncompress the data derived from the read-stream, aStream |
496 |
#writeonly compress the data and write to the write-stream, aStream |
|
1061 | 497 |
" |
1059 | 498 |
|
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
499 |
aStream isNil ifTrue:[ |
2190 | 500 |
^ self errorNotOpen |
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
501 |
]. |
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
502 |
|
2190 | 503 |
onStream := aStream. |
1059 | 504 |
mode := aMode. |
1829 | 505 |
outputBytes := ExternalBytes unprotectedNew:16384. |
506 |
inputBytes := ExternalBytes unprotectedNew:16384. |
|
1059 | 507 |
readLimit := position := 0. |
508 |
binary := false. |
|
509 |
||
510 |
self zopen. |
|
511 |
self registerForFinalization. |
|
512 |
||
513 |
hitEOF := false. |
|
514 |
||
515 |
aMode == #readonly ifTrue:[ |
|
2190 | 516 |
self zinflateInit. |
1059 | 517 |
] ifFalse:[ |
2190 | 518 |
self zdeflateInit |
1059 | 519 |
]. |
520 |
! ! |
|
521 |
||
522 |
!CompressionStream methodsFor:'writing'! |
|
523 |
||
1062 | 524 |
contents:contents |
1193 | 525 |
"write the entire contents to and close the stream" |
526 |
||
527 |
contents do:[:c| self nextPut:c]. |
|
1062 | 528 |
self close. |
529 |
! |
|
530 |
||
1059 | 531 |
flush |
1193 | 532 |
"flush the input and output buffer" |
533 |
||
1829 | 534 |
|continue availOut| |
1059 | 535 |
|
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
536 |
self isWritable ifFalse:[^ self]. |
1059 | 537 |
self zset_avail_in:position. |
538 |
||
539 |
position := 0. |
|
540 |
||
1829 | 541 |
[ continue := self zdeflate. |
2190 | 542 |
availOut := self zget_avail_out. |
1197
c86e858c2893
Documentation. Does not work yet.
Stefan Vogel <sv@exept.de>
parents:
1195
diff
changeset
|
543 |
|
2190 | 544 |
availOut > 0 ifTrue:[ |
545 |
self onStreamPutBytes:availOut from:outputBytes |
|
546 |
]. |
|
1829 | 547 |
|
1827 | 548 |
] doWhile:[ continue == true ]. |
1059 | 549 |
! |
550 |
||
1193 | 551 |
nextPut:aByteOrCharacter |
552 |
"write the argument, aByteOrCharacter" |
|
1059 | 553 |
|
1193 | 554 |
position == inputBytes size ifTrue:[self flush]. |
555 |
position := position + 1. |
|
556 |
inputBytes at:position put:aByteOrCharacter asInteger. |
|
1829 | 557 |
! |
558 |
||
559 |
nextPutAll:aCollection |
|
560 |
|limit| |
|
561 |
||
562 |
limit := inputBytes size. |
|
563 |
||
564 |
aCollection do:[:aByteOrCharacter| |
|
2190 | 565 |
position == limit ifTrue:[self flush]. |
566 |
position := position + 1. |
|
567 |
inputBytes at:position put:aByteOrCharacter asInteger. |
|
1829 | 568 |
]. |
569 |
^ aCollection |
|
1193 | 570 |
! ! |
1059 | 571 |
|
1193 | 572 |
!CompressionStream class methodsFor:'documentation'! |
1059 | 573 |
|
1193 | 574 |
version |
2190 | 575 |
^ '$Header: /cvs/stx/stx/libbasic2/CompressionStream.st,v 1.23 2009-07-31 11:16:42 cg Exp $' |
1059 | 576 |
! ! |
577 |
||
578 |
CompressionStream initialize! |