USING: accessors destructors io kernel locals namespaces sequences ; IN: io.streams.throwing TUPLE: throws-on-eof stream ; : ( stream -- stream' ) throws-on-eof new swap >>stream ; inline : with-throws-on-eof ( stream quot -- ) [ ] dip with-input-stream ; inline : with-input-throws-on-eof ( quot -- ) [ input-stream get ] dip with-input-stream ; inline : input-throws-on-eof ( -- ) input-stream get [ ] change ; inline GENERIC: silent-on-eof ( stream -- stream' ) M: throws-on-eof silent-on-eof stream>> ; M: object silent-on-eof ; : input-silent-on-eof ( -- ) input-stream [ silent-on-eof ] change ; M: throws-on-eof stream-element-type stream>> stream-element-type ; M: throws-on-eof dispose stream>> dispose ; ERROR: stream-exhausted-read1 stream ; ERROR: stream-exhausted-read returned n stream ; ERROR: stream-exhausted-read-partial n stream ; ERROR: stream-exhausted-contents stream ; M:: throws-on-eof stream-read1 ( stream -- obj ) stream stream>> stream-read1 [ stream stream-exhausted-read1 ] unless* ; M:: throws-on-eof stream-read ( n stream -- seq ) n stream stream>> stream-read dup length n = [ n stream stream-exhausted-read ] unless ; M:: throws-on-eof stream-read-partial ( n stream -- seq ) n stream stream>> stream-read-partial [ n stream stream-exhausted-read-partial ] unless* ; M:: throws-on-eof stream-contents ( stream -- seq ) stream stream>> stream-contents [ stream stream-exhausted-contents ] when-empty ;