From 12a53bbdc0528b55b945f10e42f1446048f09608 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 6 Mar 2009 17:34:21 -0600 Subject: [PATCH] add seeking to byte-array streams --- basis/io/streams/byte-array/byte-array.factor | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/basis/io/streams/byte-array/byte-array.factor b/basis/io/streams/byte-array/byte-array.factor index b877e97cf1..16160cd42d 100644 --- a/basis/io/streams/byte-array/byte-array.factor +++ b/basis/io/streams/byte-array/byte-array.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: byte-arrays byte-vectors kernel io.encodings io.streams.string sequences io namespaces io.encodings.private accessors sequences.private -io.streams.sequence destructors ; +io.streams.sequence destructors math combinators ; IN: io.streams.byte-array : ( encoding -- stream ) @@ -20,6 +20,14 @@ M: byte-reader stream-read1 sequence-read1 ; M: byte-reader stream-read-until sequence-read-until ; M: byte-reader dispose drop ; +M: byte-reader stream-seek ( n seek-type stream -- ) + swap { + { seek-absolute [ (>>i) ] } + { seek-relative [ [ + ] change-i drop ] } + { seek-end [ dup underlying>> length >>i [ + ] change-i drop ] } + [ bad-seek-type ] + } case ; + : ( byte-array encoding -- stream ) [ B{ } like 0 byte-reader boa ] dip ;