--- a/Stream.st Sat May 25 11:19:20 2019 +0200
+++ b/Stream.st Sat May 25 23:48:20 2019 +0200
@@ -223,6 +223,7 @@
! !
+
!Stream methodsFor:'Compatibility-Dolphin'!
display:someObject
@@ -408,6 +409,15 @@
"Created: / 13-03-2019 / 16:50:04 / Stefan Vogel"
"Modified (comment): / 13-03-2019 / 23:21:13 / Stefan Vogel"
+!
+
+bufferSizeForNormalCopy
+ "return the default buffer size used when copying files
+ from one stream to another, and no bufferSize is given."
+
+ ^ 8 * 1024
+
+ "Created: / 25-05-2019 / 16:49:23 / Claus Gittinger"
! !
!Stream methodsFor:'emphasis'!
@@ -3719,21 +3729,26 @@
"Modified: / 14-03-2019 / 00:22:39 / Claus Gittinger"
!
-copy:numberOfElementsOrNil into:aWriteStream bufferSize:bufferSizeArg
+copy:numberOfElementsOrNil into:aWriteStream bufferSize:bufferSizeOrNil
"read from the receiver, and write numberOfElementsOrNil elements to outStream, a WriteStream.
Return the number of elements which have been transferred.
- If numberOfElementsOrNil is nil, copy until the end of myself."
+ If numberOfElementsOrNil is nil, copy until the end of myself.
+ If bufferSizeOrNil is not nil, data is transferred in chunks of that size,
+ otherwise a default (bufferSizeForNormalCopy) is used."
|bufferSpecies bufferSize elementsLeft buffer countWritten freeBuffer|
+ bufferSize := bufferSizeOrNil notNil
+ ifTrue:[bufferSizeOrNil]
+ ifFalse:[self bufferSizeForNormalCopy].
+
countWritten := 0.
numberOfElementsOrNil isNil ifTrue:[
"read to end..."
elementsLeft := -1.
- bufferSize := bufferSizeArg.
] ifFalse:[
elementsLeft := numberOfElementsOrNil.
- bufferSize := bufferSizeArg min:numberOfElementsOrNil.
+ bufferSize := bufferSize min:numberOfElementsOrNil.
].
bufferSpecies := self contentsSpecies.
@@ -3795,8 +3810,8 @@
s contents
"
- "Modified: / 13-03-2019 / 12:00:46 / Claus Gittinger"
"Modified (comment): / 13-03-2019 / 17:03:20 / Stefan Vogel"
+ "Modified (comment): / 25-05-2019 / 16:52:51 / Claus Gittinger"
!
copyToEndFrom:inStream
@@ -3840,11 +3855,13 @@
"Modified: / 14-03-2019 / 00:22:44 / Claus Gittinger"
!
-copyToEndInto:outStream bufferSize:bufferSize
+copyToEndInto:outStream bufferSize:bufferSizeOrNil
"read from the receiver, and write all elements up to the end to outStream, aWriteStream.
- Return the number of elements which have been transferred"
-
- ^ self copy:nil into:outStream bufferSize:bufferSize
+ Return the number of elements which have been transferred.
+ If bufferSizeOrNil is not nil, data is transferred in chunks of that size,
+ otherwise a default (bufferSizeForNormalCopy) is used."
+
+ ^ self copy:nil into:outStream bufferSize:bufferSizeOrNil
"
'hello world' readStream copyToEndInto:'/tmp/mist' asFilename writeStream.
@@ -3859,6 +3876,7 @@
"Modified: / 13-03-2019 / 11:54:17 / Claus Gittinger"
"Modified (comment): / 13-03-2019 / 17:02:51 / Stefan Vogel"
+ "Modified (comment): / 25-05-2019 / 16:53:35 / Claus Gittinger"
! !
!Stream methodsFor:'testing'!