anObject readStream
anObject writeStream
Collection streamContents: [:stream | ... ]
(Read/Write)Stream on: aCollection
next
upTo: anObject
upToEnd
nextPut: anElement
nextPutAll: aCollection
next
, upTo: anObject
, upToEnd
| strean |
stream := #($a $b $c $d $e $f) readStream.
stream next.
> $a
stream upTo: $d.
> #($b $c)
stream position.
> 4
stream upToEnd
> #($e $f)
nexPut:
, nextPutAll:
stream := (Array new: 6) writeStream.
stream nextPut: 1.
stream contents.
> #(1)
stream nextPutAll: #(4 8 2 6 7).
stream contents.
> #(1 4 8 2 6 7)
stream := 'hello.txt' asFileReference writeStream.
stream nextPutAll: 'Hello Pharo!'.
stream close.
stream := 'hello.txt' asFileReference readStream.
stream next.
> $H
stream upToEnd.
> 'ello Pharo!'
stream close
When you want to create a collection by writing to a stream:
stream := OrderedCollection new writeStream.
stream nextPut: 1.
stream contents
is equivalent to
OrderedCollection
streamContents: [:stream | stream nextPut: 1]
Both scripts return a collection with number 1 inside.
/