--- a/CompressionStream.st Thu Aug 15 11:57:46 2002 +0200
+++ b/CompressionStream.st Thu Aug 22 09:25:12 2002 +0200
@@ -235,6 +235,59 @@
^ self subclassResponsibility
!
+z_nextAvailableInto:aCollection startingAt:offset
+ "read the next available bytes into a collection, a string or byteArray;
+ returns the size read
+ "
+ |start count avail|
+
+ avail := readLimit - position.
+ avail > 0 ifFalse:[^ 0].
+
+ count := aCollection size - offset + 1.
+
+ count > 0 ifFalse:[
+ count < 0 ifTrue:[
+ self zerror:'invalid arguments'
+ ].
+ ^ 0
+ ].
+ count := avail min:count.
+ start := position.
+ position := position + count.
+
+%{ unsigned char * _dstPt;
+
+ if( __isBytes(aCollection) ) {
+ _dstPt = (unsigned char *) (__ByteArrayInstPtr(aCollection)->ba_element);
+ } else if (__isString(aCollection)) {
+ _dstPt = (unsigned char *) (__stringVal( aCollection));
+ } else
+ _dstPt = (unsigned char *) 0;
+
+ if( _dstPt )
+ {
+ int _loop, _count, _offset;
+ unsigned char * _srcPt;
+ OBJ _srcObj = __INST( outputBytes );
+
+ _offset = __intVal( offset );
+ _dstPt = _dstPt + _offset - 1;
+
+ _srcPt = (unsigned char *) __externalBytesAddress( _srcObj );
+ _srcPt += __intVal( start );
+ _count = __intVal( count );
+
+ for( _loop = 0; _loop < _count; ++_loop )
+ * _dstPt++ = * _srcPt++;
+
+ RETURN(__MKSMALLINT(_count));
+ }
+%}.
+
+ ^ self zerror:'invalid argument'
+!
+
zopen
"low level - opens the zip stream
create the resources ...
@@ -337,27 +390,30 @@
"return the entire contents of the stream;
after reading the stream is closed.
"
- |stream bfsize|
+ |stream bfsize buffer count|
mode == #readonly ifFalse:[ self errorReadOnly ].
-
- binary ifTrue:[ stream := ByteArray new:1024 ]
- ifFalse:[ stream := String new:1024 ].
-
- stream := stream writeStream.
bfsize := outputBytes size.
- [ self canReadWithoutBlocking ] whileTrue:[ |data|
- readLimit == bfsize ifTrue:[
- data := outputBytes.
+ binary ifTrue:[
+ stream := ByteArray new:bfsize.
+ buffer := ByteArray new:bfsize.
+ ] ifFalse:[
+ stream := String new:bfsize.
+ buffer := String new:bfsize.
+ ].
+ stream := stream writeStream.
+
+ [ self canReadWithoutBlocking ] whileTrue:[
+ count := self z_nextAvailableInto:buffer startingAt:1.
+
+ count == bfsize ifTrue:[
+ stream nextPutAll:buffer.
] ifFalse:[
- data := outputBytes copyFrom:1 to:readLimit.
+ count > 0 ifTrue:[
+ stream nextPutAll:(buffer copyFrom:1 to:count)
+ ]
].
- binary ifFalse:[
- data := data asString
- ].
- stream nextPutAll:data.
- position := readLimit := 0. "reset input data"
].
self close.
^ stream contents