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 moduleocean.io.device.BitBucket;
21 22 importocean.meta.types.Qualifiers;
23 24 importocean.io.device.Conduit;
25 26 version (unittest) importocean.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 classBitBucket : Conduit38 {
39 overrideistringtoString () {return"<bitbucket>";}
40 41 overridesize_tbufferSize () { return0;}
42 43 overridesize_tread (void[] dst) { returnEof; }
44 45 overridesize_twrite (const(void)[] src) { returnsrc.length; }
46 47 overridevoiddetach () { }
48 }
49 50 unittest51 {
52 autoa=newBitBucket;
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 }