ExternalStream.st
changeset 21337 f229bd8f95d3
parent 21253 20f8058333cd
child 21362 985836810acb
--- a/ExternalStream.st	Wed Feb 01 21:12:03 2017 +0100
+++ b/ExternalStream.st	Thu Feb 02 11:23:11 2017 +0100
@@ -20,7 +20,7 @@
 		InvalidModeSignal OpenErrorSignal StreamNotOpenSignal
 		InvalidOperationSignal DefaultEOLMode ReadMode ReadWriteMode
 		WriteMode AppendMode CreateReadWriteMode StreamIOErrorSignal
-		FileOpenTrace MaxNonTenurableExecutors'
+		FileOpenTrace MaxNonTenurableExecutors DefaultCopyBufferSize'
 	poolDictionaries:''
 	category:'Streams-External'
 !
@@ -1860,6 +1860,47 @@
     ^ StreamNotOpenError
 ! !
 
+!ExternalStream class methodsFor:'defaults'!
+
+bufferSizeForBulkFileCopy
+    "return the size of buffer used when copying big files/buld data from one stream to another.
+     Due to a bug on older Windows systems, the default used
+     is chosen very conservatively, as the copy used to fail with big buffers.
+     However, modern Windows systems seem to not suffer from that bug,
+     and bigger buffer sizes will dramatically increase the performance of 
+     copies to/from network drives.
+     Setting DefaultCopyBufferSize allows for fine tuning, 
+     in case you run into performance problems, or network buffer failures.
+     When nil, a somewhat conservative compromise is used."
+
+    DefaultCopyBufferSize notNil ifTrue:[^ DefaultCopyBufferSize].
+    
+    OperatingSystem isMSDOSlike ifTrue:[
+        OperatingSystem isWin7Like ifTrue:[
+            ^ 64*1024
+        ] ifFalse:[    
+            "/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ?
+            ^ 1 * 1024.
+        ].
+    ].
+    ^ 32 * 1024.
+!
+
+defaultCopyBufferSize:anInteger
+    "allows changing the size of buffer used when copying big
+     files/buld data from one stream to another.
+     Due to a bug on older Windows systems, the default used in copyToEndInto:
+     is chosen very conservatively, as the copy used to fail with big buffers.
+     However, modern Windows systems seem to not suffer from that bug,
+     and bigger buffer sizes will dramatically increase the performance of 
+     copies to/from network drives.
+     This method allows for fine tuning, in case you run into performance problems,
+     or network buffer failures.
+     When nil, a somewhat conservative compromise is used."
+     
+    ^ DefaultCopyBufferSize
+! !
+
 !ExternalStream class methodsFor:'error handling'!
 
 errorReporter
@@ -2982,16 +3023,7 @@
      Same functionality as copyToEnd:, but reversed arg and receiver
      (useful in a cascade message of the writeStream)"
 
-    |bufferSize|
-
-    OperatingSystem isMSDOSlike ifTrue:[
-	"/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ?
-	bufferSize := 1 * 1024.
-    ] ifFalse:[
-	bufferSize := 8 * 1024.
-    ].
-
-    ^ inStream copyToEndInto:self bufferSize:bufferSize
+    ^ inStream copyToEndInto:self bufferSize:(self class bufferSizeForBulkFileCopy)
 
     "
      |in out|
@@ -3006,19 +3038,7 @@
 copyToEndInto:outStream
     "copy the data into another stream."
 
-    |bufferSize|
-
-    (self isFileStream and:[outStream isFileStream]) ifTrue:[
-	bufferSize := 8192 * 8.     "/ 64k buffer size
-    ] ifFalse:[
-	OperatingSystem isMSDOSlike ifTrue:[
-	    "/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ?
-	    bufferSize := 1 * 1024.
-	] ifFalse:[
-	    bufferSize := 8 * 1024.
-	].
-    ].
-    ^ self copyToEndInto:outStream bufferSize:bufferSize
+    ^ self copyToEndInto:outStream bufferSize:(self class bufferSizeForBulkFileCopy)
 
     "
      |in out|