#copyToEndInto:bufferSize:
authorStefan Vogel <sv@exept.de>
Sun, 09 May 2004 22:45:54 +0200
changeset 8338 a399729a3c69
parent 8337 1168b3ff3cdc
child 8339 b6c3643af40f
#copyToEndInto:bufferSize: Handle partial writes
Stream.st
--- a/Stream.st	Sun May 09 22:43:21 2004 +0200
+++ b/Stream.st	Sun May 09 22:45:54 2004 +0200
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
 	      All Rights Reserved
@@ -1617,7 +1615,7 @@
     "read from the receiver, and write all data up to the end to another stream.
      Return the number of bytes which have been transferred"
 
-    |buffer bytesWritten readCount count|
+    |buffer bytesWritten readCount writeCount count|
 
     bytesWritten := 0.
     buffer := self contentsSpecies new:bufferSize.
@@ -1625,11 +1623,20 @@
     [self atEnd] whileFalse:[ 
         readCount := self nextAvailableBytes:bufferSize into:buffer startingAt:1.
         readCount > 0 ifTrue:[
-            count := outStream nextPutBytes:readCount from:buffer startingAt:1.
-            count = readCount ifFalse:[
-                self error:'short write count' mayProceed:true.
-            ].
-            bytesWritten := bytesWritten + count.
+            writeCount := 0.
+            [
+                count := outStream nextPutBytes:readCount-writeCount
+                                    from:buffer 
+                                    startingAt:writeCount+1.
+                bytesWritten := bytesWritten + count.
+                writeCount := writeCount + count.
+                writeCount < readCount ifTrue:[
+                    outStream writeWait.
+                    true.
+                ] ifFalse:[
+                    false
+                ].
+            ] whileTrue.
         ].
     ].
     ^ bytesWritten
@@ -2722,7 +2729,7 @@
 !Stream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.127 2004-04-12 11:40:47 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.128 2004-05-09 20:45:54 stefan Exp $'
 ! !
 
 Stream initialize!