add a <limited-file-reader> word to open a limited stream from a file correctly
parent
f31c3f867a
commit
175b03c134
|
@ -104,8 +104,7 @@ ERROR: unimplemented-color-type image ;
|
||||||
} case ;
|
} case ;
|
||||||
|
|
||||||
: load-png ( path -- image )
|
: load-png ( path -- image )
|
||||||
[ binary <file-reader> ] [ file-info size>> ] bi
|
binary stream-throws <limited-file-reader> [
|
||||||
stream-throws <limited-stream> [
|
|
||||||
<png-image>
|
<png-image>
|
||||||
read-png-header
|
read-png-header
|
||||||
read-png-chunks
|
read-png-chunks
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
! Copyright (C) 2008 Slava Pestov.
|
! Copyright (C) 2008 Slava Pestov.
|
||||||
! Copyright (C) 2009 Doug Coleman.
|
! Copyright (C) 2009 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel math io io.encodings destructors accessors
|
USING: accessors byte-vectors combinators destructors fry io
|
||||||
sequences namespaces byte-vectors fry combinators ;
|
io.encodings io.files io.files.info kernel math namespaces
|
||||||
|
sequences ;
|
||||||
IN: io.streams.limited
|
IN: io.streams.limited
|
||||||
|
|
||||||
TUPLE: limited-stream stream count limit mode stack ;
|
TUPLE: limited-stream stream count limit mode stack ;
|
||||||
|
@ -16,6 +17,12 @@ SINGLETONS: stream-throws stream-eofs ;
|
||||||
swap >>stream
|
swap >>stream
|
||||||
0 >>count ;
|
0 >>count ;
|
||||||
|
|
||||||
|
: <limited-file-reader> ( path encoding mode -- stream' )
|
||||||
|
[
|
||||||
|
[ <file-reader> ]
|
||||||
|
[ drop file-info size>> ] 2bi
|
||||||
|
] dip <limited-stream> ;
|
||||||
|
|
||||||
GENERIC# limit 2 ( stream limit mode -- stream' )
|
GENERIC# limit 2 ( stream limit mode -- stream' )
|
||||||
|
|
||||||
M: decoder limit ( stream limit mode -- stream' )
|
M: decoder limit ( stream limit mode -- stream' )
|
||||||
|
|
Loading…
Reference in New Issue