PositionableStream.st
changeset 22003 1a4affe1e22c
parent 21136 fc36f8c599ce
child 22204 189b58c6ed87
--- a/PositionableStream.st	Thu Jul 13 12:19:01 2017 +0200
+++ b/PositionableStream.st	Thu Jul 13 12:32:29 2017 +0200
@@ -836,6 +836,28 @@
     ^ peekObject
 !
 
+peek:n
+    "look ahead n elements and return them after positioning pack to the 
+     position we had before"
+
+    |posBefore peekObjects|
+
+    posBefore := self position.
+    peekObjects := self next:n.
+    self position:posBefore.
+    ^ peekObjects
+
+    "
+     |s|
+
+     s := '1234567890' readStream.
+     s peek:4.
+     s next:5.
+    "
+
+    "Created: / 13-07-2017 / 12:32:03 / cg"
+!
+
 upToAll:aCollection
     "read until a subcollection consisisting of the elements in aCollection is encountered.
      Return everything read excluding the elements in aCollection.