+next:into:startingAt:
authorClaus Gittinger <cg@exept.de>
Fri, 31 Jul 2009 13:22:02 +0200
changeset 2191 7cb40c5e5511
parent 2190 6c3f9241753a
child 2192 aa40ad91e77a
+next:into:startingAt:
CompressionStream.st
--- a/CompressionStream.st	Fri Jul 31 13:16:42 2009 +0200
+++ b/CompressionStream.st	Fri Jul 31 13:22:02 2009 +0200
@@ -166,6 +166,10 @@
 
 !CompressionStream methodsFor:'low level'!
 
+z_nextAvailableInto:aCollection startingAt:offset
+    ^ self z_nextAvailableInto:aCollection startingAt:offset maxCount:nil
+!
+
 z_nextAvailableInto:aCollection startingAt:offset maxCount:maxCount
     "read the next available bytes into a collection, a string or byteArray;
      returns the size read"
@@ -222,10 +226,6 @@
     ^ self zerror:'invalid argument'
 !
 
-z_nextAvailableInto:aCollection startingAt:offset
-    ^ self z_nextAvailableInto:aCollection startingAt:offset maxCount:nil
-!
-
 zclose
     "low level close of the zip stream"
 
@@ -442,6 +442,27 @@
     ^ data copyFrom:1 to:(offset - 1)
 !
 
+next:n into:aBuffer startingAt:startIndex
+    "read the next n elements of the stream into aBuffer.
+     Return the number of bytes read."
+
+    |data count remaining offset|
+
+    self canReadWithoutBlocking ifFalse:[
+        ^ 0
+    ].
+    offset := startIndex.
+    remaining := n.
+
+    [self canReadWithoutBlocking] whileTrue:[
+        count  := self z_nextAvailableInto:data startingAt:offset maxCount:remaining.
+        offset := count + offset.
+        remaining := remaining - count.
+        remaining == 0 ifTrue:[^ n]
+    ].
+    ^ n - remaining
+!
+
 skip:count
     "skip count objects, return the receiver
      redefined for optimization"
@@ -572,7 +593,7 @@
 !CompressionStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/CompressionStream.st,v 1.23 2009-07-31 11:16:42 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/CompressionStream.st,v 1.24 2009-07-31 11:22:02 cg Exp $'
 ! !
 
 CompressionStream initialize!