1 /******************************************************************************* 2 3 A Conduit that ignores all that is written to it 4 5 copyright: Copyright (c) 2008. Fawzi Mohamed 6 7 license: BSD style: $(LICENSE) 8 9 version: Initial release: July 2008 10 11 author: Fawzi Mohamed 12 13 *******************************************************************************/ 14 15 module tango.io.device.BitBucket; 16 17 private import tango.io.device.Conduit; 18 19 /******************************************************************************* 20 21 A Conduit that ignores all that is written to it and returns Eof 22 when read from. Note that write() returns the length of what was 23 handed to it, acting as a pure bit-bucket. Returning zero or Eof 24 instead would not be appropriate in this context. 25 26 *******************************************************************************/ 27 28 class BitBucket : Conduit 29 { 30 override string toString () {return "<bitbucket>";} 31 32 override const size_t bufferSize () { return 0;} 33 34 override size_t read (void[] dst) { return Eof; } 35 36 override size_t write (const(void)[] src) { return src.length; } 37 38 override void detach () { } 39 } 40 41 42 43 debug(UnitTest) 44 { 45 unittest{ 46 auto a=new BitBucket; 47 a.write("bla"); 48 a.flush(); 49 a.detach(); 50 a.write("b"); // at the moment it works, disallow? 51 uint[4] b=0; 52 a.read(b); 53 foreach (el;b) 54 assert(el==0); 55 } 56 }