Skip to content

Commit 1cddf48

Browse files
committed
Add next:into:startingAt: and readInto:startingAt:count: to readable streams
fixes #177
1 parent 8c5e990 commit 1cddf48

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
reading
2+
next: n into: aCollection startingAt: startIndex
3+
"Read n objects into the given collection.
4+
Return aCollection or a partial copy if less than n elements have been read."
5+
6+
| count |
7+
count := self readInto: aCollection startingAt: startIndex count: n.
8+
count = n
9+
ifTrue:[ ^aCollection ]
10+
ifFalse:[ ^aCollection copyFrom: 1 to: startIndex + count - 1 ]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
reading
2+
readInto: aCollection startingAt: startIndex count: n
3+
"Read n objects into the given collection.
4+
Return number of elements that have been read."
5+
| obj |
6+
0 to: n - 1 do: [:i |
7+
obj := self next ifNil: [ ^i ].
8+
aCollection at: startIndex + i put: obj].
9+
^n

src/FS-AnsiStreams.package/TReadableStream.trait/methodProperties.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
"instance" : {
55
"collectionSpecies" : "jr 3/7/2017 16:49",
66
"do:" : "jr 6/7/2017 12:49",
7+
"next:into:startingAt:" : "jr 10/13/2018 23:09",
78
"nextLine" : "jr 6/7/2017 12:55",
89
"nextMatchFor:" : "jr 6/7/2017 12:57",
910
"peekFor:" : "jr 6/7/2017 13:05",
11+
"readInto:startingAt:count:" : "jr 10/13/2018 23:08",
1012
"skip:" : "jr 6/7/2017 13:09",
1113
"skipTo:" : "jr 6/7/2017 12:58",
1214
"upTo:" : "jr 6/7/2017 13:14",

0 commit comments

Comments
 (0)