1 /**
2   Simple streams for use with iopipe
3 Copyright: Copyright Steven Schveighoffer 2011-.
4 License:   Boost License 1.0. (See accompanying file LICENSE_1_0.txt or copy
5 at http://www.boost.org/LICENSE_1_0.txt)
6 Authors:   Steven Schveighoffer
7  */
8 module iopipe.stream;
9 
10 version(Have_io)
11 {
12     import std.io;
13 
14     version(Posix)
15     {
16         /// Deprecated: use std.io directly
17         deprecated alias IODev = IOObject!(File);
18 
19         /**
20          * Construct an input stream based on the file descriptor
21          *
22          * params:
23          * fd = The file descriptor to wrap
24          *
25          * Deprecated: Use https://code.dlang.org/io for low-level device i/o
26          */
27         deprecated("use std.io")
28             auto openDev(int fd)
29             {
30                 return ioObject(File(fd));
31             }
32 
33         /**
34          * Open a file by name.
35          *
36          * Deprecated: Use https://code.dlang.org/io for low-level device i/o
37          */
38         deprecated("use std.io")
39             auto openDev(in char[] name, Mode mode = Mode.read | Mode.binary)
40             {
41                 return ioObject(File(name, mode));
42             }
43     }
44 }
45 
46 
47 /**
48  * A source that reads uninitialized data.
49  */
50 struct NullDev
51 {
52     /**
53      * read the data. Always succeeds.
54      */
55     size_t read(T)(T buf) const
56     {
57         // null data doesn't matter
58         return buf.length;
59     }
60 }
61 
62 /// Common instance of NullDev to use anywhere needed.
63 immutable NullDev nullDev;
64 
65 /**
66  * A source stream that always reads zeros, no matter what the data type is.
67  */
68 struct ZeroDev
69 {
70     size_t read(T)(T buf) const
71     {
72         // zero data
73         buf[] = 0;
74         return buf.length;
75     }
76 }
77 
78 /// Common instance of ZeroDev to use anywhere needed.
79 immutable ZeroDev zeroDev;