io.streams.peek: Peek streams can break on file input. Fixes #1317.
parent
e72ad0c4f7
commit
aeb03fff38
|
@ -129,3 +129,22 @@ IN: io.streams.peek.tests
|
|||
] { } make
|
||||
] with-destructors
|
||||
] unit-test
|
||||
|
||||
! Issue #1317
|
||||
{ "Red" } [
|
||||
"resource:license.txt" binary [
|
||||
input-stream [ <peek-stream> ] change
|
||||
peek1 drop
|
||||
3 read >string
|
||||
] with-file-reader
|
||||
] unit-test
|
||||
|
||||
{ "ist" } [
|
||||
"resource:license.txt" binary [
|
||||
input-stream [ <peek-stream> ] change
|
||||
peek1 drop
|
||||
3 read drop
|
||||
2 peek drop
|
||||
3 read >string
|
||||
] with-file-reader
|
||||
] unit-test
|
||||
|
|
|
@ -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 <reversed> 0 buf copy
|
||||
0 peeked shorten
|
||||
n #peeked - :> n'
|
||||
buf #peeked tail-slice :> buf'
|
||||
stream stream>> input-port? [
|
||||
#peeked buf <displaced-alien>
|
||||
] [
|
||||
buf #peeked tail-slice
|
||||
] if :> buf'
|
||||
n' buf' stream stream-read-unsafe #peeked +
|
||||
] if
|
||||
] if ;
|
||||
|
|
Loading…
Reference in New Issue