]> gitweb.factorcode.org Git - factor.git/blob - basis/io/streams/throwing/throwing.factor
Remove stream-peek and stream-peek1, re-implement dns vocab to not need this abstraction
[factor.git] / basis / io / streams / throwing / throwing.factor
1 ! Copyright (C) 2010 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors destructors io kernel locals namespaces
4 sequences fry ;
5 IN: io.streams.throwing
6
7 ERROR: stream-exhausted n stream word ;
8
9 TUPLE: throws-on-eof-stream stream ;
10
11 C: <throws-on-eof-stream> throws-on-eof-stream
12
13 <PRIVATE
14
15 M: throws-on-eof-stream stream-element-type stream>> stream-element-type ;
16
17 M: throws-on-eof-stream dispose stream>> dispose ;
18
19 M:: throws-on-eof-stream stream-read1 ( stream -- obj )
20     stream stream>> stream-read1
21     [ 1 stream \ read1 stream-exhausted ] unless* ;
22
23 M:: throws-on-eof-stream stream-read ( n stream -- seq )
24     n stream stream>> stream-read
25     dup length n = [ n stream \ read stream-exhausted ] unless ;
26
27 M:: throws-on-eof-stream stream-read-partial ( n stream -- seq )
28     n stream stream>> stream-read-partial
29     [ n stream \ read-partial stream-exhausted ] unless* ;
30
31 M: throws-on-eof-stream stream-tell
32     stream>> stream-tell ;
33
34 M: throws-on-eof-stream stream-seek
35     stream>> stream-seek ;
36
37 M: throws-on-eof-stream stream-read-until
38     [ stream>> stream-read-until ]
39     [ '[ length _ \ read-until stream-exhausted ] unless* ] bi ;
40
41 PRIVATE>
42
43 : stream-throw-on-eof ( ..a stream quot: ( ..a stream' -- ..b ) -- ..b )
44     [ <throws-on-eof-stream> ] dip with-input-stream* ; inline
45
46 : throw-on-eof ( ..a quot: ( ..a -- ..b ) -- ..b )
47     [ input-stream get <throws-on-eof-stream> ] dip with-input-stream* ; inline