1 /**
2  * Streams interface
3  */
4 module river.core.stream;
5 
6 /** 
7  * Defines a stream which can be read fro
8  * and written to
9  */
10 public interface Stream
11 {
12     /** 
13      * Reads bytes from the stream into the provided array
14      * and returns without any further waiting, at most the
15      * number of bytes read will be the length of the provided
16      * array, at minimum a single byte
17      *
18      * Params:
19      *   toArray = the buffer to read into
20      * Returns: the number of bytes read
21      */
22     public ulong read(byte[] toArray);
23 
24     /** 
25      * Reads bytes from the stream into the provided array
26      * until the array is fully-filled
27      *
28      * Params:
29      *   toArray = the buffer to read into
30      * Returns: the number of bytes read
31      */
32     public ulong readFully(byte[] toArray);
33 
34     /** 
35      * Writes bytes to the stream from the provided array
36      * and returns without any further waiting, at most the
37      * number of bytes written will be the length of the provided
38      * array, at minimum a single byte
39      *
40      * Params:
41      *   fromArray = the buffer to write from
42      * Returns: the number of bytes written
43      */
44     public ulong write(byte[] fromArray);
45 
46     /** 
47      * Writes bytes to the stream from the provided array
48      * until the array has been fully written
49      *
50      * Params:
51      *   fromArray = the buffer to write from
52      * Returns: the number of bytes written
53      */
54     public ulong writeFully(byte[] fromArray);
55 
56     /** 
57      * Closes the stream
58      */
59     public void close();
60 }