[Cuis-dev] learning about streams
Mark Volkmann
r.mark.volkmann at gmail.com
Sun Sep 22 08:59:12 PDT 2024
Consider this simple example:
coll := OrderedCollection newFrom: #('apple' 'banana' 'cherry').
stream := ReadWriteStream on: coll.
stream next print.
I expected this to print apple in the Transcript (and it does if I use a
ReadStream), but it prints nil. The reason is that the on: method of
WriteStream, which is the superclass of ReadWriteStream, does this to set
readLimit:
on: aCollection
super on: aCollection thatCanBeModified.
readLimit := 0.
writeLimit := aCollection size
The superclass PositionableStream on: method sets readLimit to the size of
the collection (3 in this case), but here readLimit is changed to zero. Why
does it do that? This seems to prevent a ReadWriteStream from reading.
I got some clues from the class command for ReadWriteStream which says the
following:
Instances are created on: aCollection, which is considered to be empty or
filled with nil. Any contents will be ovewriten, and are not available for
reading.
Instances can also be create with: aCollection. In this case, new contents
will be added after this initial stuff. Reading them is only possible if
position: is set appropriately (for instance aReadWriteStream position: 1).
Side note: There are two typos in the class comment. "overwriten" should be
"overwritten" and "be create" should be "be created".
When I add "stream position: 1" I get "Error: Attempt to set the position
of a PositionableStream out of bounds".
--
R. Mark Volkmann
Object Computing, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240922/7ead410d/attachment.htm>
More information about the Cuis-dev
mailing list