1 /*******************************************************************************
2 
3         A Conduit that ignores all that is written to it
4 
5         Copyright:
6             Copyright (c) 2008. Fawzi Mohamed
7             Some parts copyright (c) 2009-2016 dunnhumby Germany GmbH.
8             All rights reserved.
9 
10         License:
11             Tango Dual License: 3-Clause BSD License / Academic Free License v3.0.
12             See LICENSE_TANGO.txt for details.
13 
14         Version: Initial release: July 2008
15 
16         Authors: Fawzi Mohamed
17 
18 *******************************************************************************/
19 
20 module ocean.io.device.BitBucket;
21 
22 import ocean.meta.types.Qualifiers;
23 
24 import ocean.io.device.Conduit;
25 
26 version (unittest) import ocean.core.Test;
27 
28 /*******************************************************************************
29 
30         A Conduit that ignores all that is written to it and returns Eof
31         when read from. Note that write() returns the length of what was
32         handed to it, acting as a pure bit-bucket. Returning zero or Eof
33         instead would not be appropriate in this context.
34 
35 *******************************************************************************/
36 
37 class BitBucket : Conduit
38 {
39         override istring toString () {return "<bitbucket>";}
40 
41         override size_t bufferSize () { return 0;}
42 
43         override size_t read (void[] dst) { return Eof; }
44 
45         override size_t write (const(void)[] src) { return src.length; }
46 
47         override void detach () { }
48 }
49 
50 unittest
51 {
52     auto a=new BitBucket;
53     a.write("bla");
54     a.flush();
55     a.detach();
56     a.write("b"); // at the moment it works, disallow?
57     uint[4] b=0;
58     a.read(b);
59     foreach (el;b)
60         test(el==0);
61 }