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 ;
9 C: <zero-stream> zero-stream
11 M: zero-stream stream-element-type drop +byte+ ;
13 M: zero-stream stream-read-unsafe
14 drop over head-slice [ drop 0 ] map! drop ;
16 M: zero-stream stream-read1 drop 0 ;
18 M: zero-stream stream-read-partial-unsafe stream-read-unsafe ;
20 M: zero-stream dispose drop ;
22 INSTANCE: zero-stream input-stream
26 : (zero-file) ( n path -- )
28 [ 1 - seek-absolute seek-output 0 write1 ] with-file-writer ;
32 ERROR: invalid-file-size n path ;
34 : zero-file ( n path -- )
36 { [ over 0 < ] [ throw-invalid-file-size ] }
37 { [ over 0 = ] [ nip touch-file ] }