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 ;
|
||||
|
||||
: load-png ( path -- image )
|
||||
[ binary <file-reader> ] [ file-info size>> ] bi
|
||||
stream-throws <limited-stream> [
|
||||
binary stream-throws <limited-file-reader> [
|
||||
<png-image>
|
||||
read-png-header
|
||||
read-png-chunks
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! Copyright (C) 2009 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: kernel math io io.encodings destructors accessors
|
||||
sequences namespaces byte-vectors fry combinators ;
|
||||
USING: accessors byte-vectors combinators destructors fry io
|
||||
io.encodings io.files io.files.info kernel math namespaces
|
||||
sequences ;
|
||||
IN: io.streams.limited
|
||||
|
||||
TUPLE: limited-stream stream count limit mode stack ;
|
||||
|
@ -16,6 +17,12 @@ SINGLETONS: stream-throws stream-eofs ;
|
|||
swap >>stream
|
||||
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' )
|
||||
|
||||
M: decoder limit ( stream limit mode -- stream' )
|
||||
|
|
Loading…
Reference in New Issue