--- a/ExternalStream.st Wed May 09 19:45:01 2018 +0200
+++ b/ExternalStream.st Wed May 09 20:09:43 2018 +0200
@@ -5604,7 +5604,7 @@
"return a collection of the elements up-to the end.
Return an empty collection, if the stream-end is already at the end."
- |chunkSize chunks sizes byteCount data offset|
+ |chunkSize chunksAndCounts byteCount data offset contentsSpecies|
"adding to a ByteArray produces quadratic time-space
behavior - therefore we allocate chunks, and concatenate them
@@ -5612,34 +5612,34 @@
chunkSize := 4096.
byteCount := 0.
+ contentsSpecies := self contentsSpecies.
+
[self atEnd] whileFalse:[
|chunk cnt|
- chunk := self contentsSpecies uninitializedNew:chunkSize.
+ chunk := contentsSpecies uninitializedNew:chunkSize.
cnt := self nextBytes:chunkSize into:chunk startingAt:1.
cnt ~~ 0 ifTrue:[
- chunks isNil ifTrue:[
+ chunksAndCounts isNil ifTrue:[
(cnt < chunkSize and:[self atEnd]) ifTrue:[
"all data is in a single chunk, so we are done"
^ chunk copyFrom:1 to:cnt.
].
- chunks := OrderedCollection new.
- sizes := OrderedCollection new.
+ chunksAndCounts := OrderedCollection new.
].
- chunks add:chunk.
- sizes add:cnt.
- byteCount := byteCount + cnt
+ chunksAndCounts add:chunk; add:cnt.
+ byteCount := byteCount + cnt.
]
].
"now, create one big array"
- data := self contentsSpecies uninitializedNew:byteCount.
+ data := contentsSpecies uninitializedNew:byteCount.
offset := 1.
- 1 to:chunks size do:[:index |
+ 1 to:chunksAndCounts size by:2 do:[:index |
|chunk cnt|
- chunk := chunks at:index.
- cnt := sizes at:index.
+ chunk := chunksAndCounts at:index.
+ cnt := chunksAndCounts at:index+1.
data replaceFrom:offset to:(offset + cnt - 1) with:chunk startingAt:1.
offset := offset + cnt
].
@@ -5649,10 +5649,13 @@
"
'/dev/null' asFilename readStream upToEnd
'/proc/self/stat' asFilename readStream upToEnd
+ 'librun.so' asFilename readStream binary upToEnd
self assert:('smalltalk.rc' asFilename readStream upToEnd size)
= ('smalltalk.rc' asFilename readStream size)
"
+
+ "Modified (format): / 09-05-2018 / 20:09:31 / stefan"
! !
!ExternalStream methodsFor:'rel5 protocol'!