2010-07-09 14:30:57 -04:00
|
|
|
! Copyright (C) 2010 Doug Coleman.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: accessors destructors io kernel locals namespaces
|
2010-07-09 17:26:01 -04:00
|
|
|
sequences fry ;
|
2010-07-09 14:30:57 -04:00
|
|
|
IN: io.streams.throwing
|
|
|
|
|
|
|
|
ERROR: stream-exhausted n stream word ;
|
|
|
|
|
|
|
|
<PRIVATE
|
|
|
|
|
|
|
|
TUPLE: throws-on-eof stream ;
|
|
|
|
|
|
|
|
C: <throws-on-eof> throws-on-eof
|
|
|
|
|
|
|
|
M: throws-on-eof stream-element-type stream>> stream-element-type ;
|
|
|
|
|
|
|
|
M: throws-on-eof dispose stream>> dispose ;
|
|
|
|
|
|
|
|
M:: throws-on-eof stream-read1 ( stream -- obj )
|
|
|
|
stream stream>> stream-read1
|
|
|
|
[ 1 stream \ read1 stream-exhausted ] unless* ;
|
|
|
|
|
|
|
|
M:: throws-on-eof stream-read ( n stream -- seq )
|
|
|
|
n stream stream>> stream-read
|
|
|
|
dup length n = [ n stream \ read stream-exhausted ] unless ;
|
|
|
|
|
|
|
|
M:: throws-on-eof stream-read-partial ( n stream -- seq )
|
|
|
|
n stream stream>> stream-read-partial
|
|
|
|
[ n stream \ read-partial stream-exhausted ] unless* ;
|
|
|
|
|
2010-07-09 17:08:54 -04:00
|
|
|
M: throws-on-eof stream-tell
|
|
|
|
stream>> stream-tell ;
|
|
|
|
|
|
|
|
M: throws-on-eof stream-seek
|
|
|
|
stream>> stream-seek ;
|
|
|
|
|
2010-07-09 17:26:01 -04:00
|
|
|
M: throws-on-eof stream-read-until
|
|
|
|
[ stream>> stream-read-until ]
|
|
|
|
[ '[ length _ \ read-until stream-exhausted ] unless* ] bi ;
|
|
|
|
|
2010-07-09 14:30:57 -04:00
|
|
|
PRIVATE>
|
|
|
|
|
|
|
|
: throws-on-eof ( stream quot -- )
|
|
|
|
[ <throws-on-eof> ] dip with-input-stream ; inline
|
|
|
|
|
|
|
|
: input-throws-on-eof ( quot -- )
|
|
|
|
[ input-stream get <throws-on-eof> ] dip with-input-stream ; inline
|