]> gitweb.factorcode.org Git - factor.git/blob - basis/io/streams/null/null.factor
191c8dce9177d998e9d1b75ab6cdc565c2ddc939
[factor.git] / basis / io / streams / null / null.factor
1 ! Copyright (C) 2007 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 IN: io.streams.null
4 USING: kernel io io.timeouts io.streams.duplex destructors ;
5
6 TUPLE: null-stream ;
7
8 M: null-stream dispose drop ;
9 M: null-stream set-timeout 2drop ;
10
11 TUPLE: null-reader < null-stream ;
12
13 M: null-reader stream-readln drop f ;
14 M: null-reader stream-read1 drop f ;
15 M: null-reader stream-read-until 2drop f f ;
16 M: null-reader stream-read 2drop f ;
17
18 TUPLE: null-writer < null-stream ;
19
20 M: null-writer stream-write1 2drop ;
21 M: null-writer stream-write 2drop ;
22 M: null-writer stream-nl drop ;
23 M: null-writer stream-flush drop ;
24 M: null-writer stream-format 3drop ;
25 M: null-writer make-span-stream nip ;
26 M: null-writer make-block-stream nip ;
27 M: null-writer make-cell-stream nip ;
28 M: null-writer stream-write-table 3drop ;
29
30 : with-null-reader ( quot -- )
31     T{ null-reader } swap with-input-stream* ; inline
32
33 : with-null-writer ( quot -- )
34     T{ null-writer } swap with-output-stream* ; inline
35
36 : with-null-stream ( quot -- )
37     T{ duplex-stream f T{ null-reader } T{ null-writer } }
38     swap with-stream* ; inline