]> gitweb.factorcode.org Git - factor.git/blob - extra/io/streams/zeros/zeros.factor
change ERROR: words from throw-foo back to foo.
[factor.git] / extra / io / streams / zeros / zeros.factor
1 ! Copyright (C) 2010 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: combinators destructors io io.directories
4 io.encodings.binary io.files kernel math sequences ;
5 IN: io.streams.zeros
6
7 TUPLE: zero-stream ;
8
9 C: <zero-stream> zero-stream
10
11 M: zero-stream stream-element-type drop +byte+ ;
12
13 M: zero-stream stream-read-unsafe
14     drop over head-slice [ drop 0 ] map! drop ;
15
16 M: zero-stream stream-read1 drop 0 ;
17
18 M: zero-stream stream-read-partial-unsafe stream-read-unsafe ;
19
20 M: zero-stream dispose drop ;
21
22 INSTANCE: zero-stream input-stream
23
24 <PRIVATE
25
26 : (zero-file) ( n path -- )
27     binary
28     [ 1 - seek-absolute seek-output 0 write1 ] with-file-writer ;
29
30 PRIVATE>
31
32 ERROR: invalid-file-size n path ;
33
34 : zero-file ( n path -- )
35     {
36         { [ over 0 < ] [ invalid-file-size ] }
37         { [ over 0 = ] [ nip touch-file ] }
38         [ (zero-file) ]
39     } cond ;