diff --git a/extra/io/streams/peek/peek-tests.factor b/extra/io/streams/peek/peek-tests.factor index f35714d75a..d860086f27 100644 --- a/extra/io/streams/peek/peek-tests.factor +++ b/extra/io/streams/peek/peek-tests.factor @@ -129,3 +129,22 @@ IN: io.streams.peek.tests ] { } make ] with-destructors ] unit-test + +! Issue #1317 +{ "Red" } [ + "resource:license.txt" binary [ + input-stream [ ] change + peek1 drop + 3 read >string + ] with-file-reader +] unit-test + +{ "ist" } [ + "resource:license.txt" binary [ + input-stream [ ] change + peek1 drop + 3 read drop + 2 peek drop + 3 read >string + ] with-file-reader +] unit-test diff --git a/extra/io/streams/peek/peek.factor b/extra/io/streams/peek/peek.factor index 06897f3333..bb24c7f472 100644 --- a/extra/io/streams/peek/peek.factor +++ b/extra/io/streams/peek/peek.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2011 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors combinators combinators.short-circuit -destructors io io.private kernel locals math namespaces +USING: accessors alien combinators combinators.short-circuit +destructors io io.ports io.private kernel locals math namespaces sequences vectors ; IN: io.streams.peek @@ -49,7 +49,11 @@ M:: peek-stream stream-read-unsafe ( n buf stream -- count ) peeked 0 buf copy 0 peeked shorten n #peeked - :> n' - buf #peeked tail-slice :> buf' + stream stream>> input-port? [ + #peeked buf + ] [ + buf #peeked tail-slice + ] if :> buf' n' buf' stream stream-read-unsafe #peeked + ] if ] if ;