1 /******************************************************************************* 2 3 copyright: Copyright (c) 2007 Kris Bell. All rights reserved 4 5 license: BSD style: $(LICENSE) 6 7 version: Initial release: Nov 2007 8 9 author: Kris 10 11 *******************************************************************************/ 12 13 module tango.io.stream.DataFile; 14 15 private import tango.io.device.File; 16 17 private import tango.io.stream.Data; 18 19 /******************************************************************************* 20 21 Composes a seekable file with buffered binary input. A seek causes 22 the input buffer to be cleared. 23 24 *******************************************************************************/ 25 26 class DataFileInput : DataInput 27 { 28 private File conduit; 29 30 /*********************************************************************** 31 32 Compose a FileStream. 33 34 ***********************************************************************/ 35 36 this (char[] path, File.Style style = File.ReadExisting) 37 { 38 this (new File (path, style)); 39 } 40 41 /*********************************************************************** 42 43 Wrap a File instance. 44 45 ***********************************************************************/ 46 47 this (File file) 48 { 49 super (conduit = file); 50 } 51 52 /*********************************************************************** 53 54 Return the underlying conduit. 55 56 ***********************************************************************/ 57 58 final File file () 59 { 60 return conduit; 61 } 62 } 63 64 65 /******************************************************************************* 66 67 Composes a seekable file with buffered binary output. A seek causes 68 the output buffer to be flushed first. 69 70 *******************************************************************************/ 71 72 class DataFileOutput : DataOutput 73 { 74 private File conduit; 75 76 /*********************************************************************** 77 78 Compose a FileStream. 79 80 ***********************************************************************/ 81 82 this (char[] path, File.Style style = File.WriteCreate) 83 { 84 this (new File (path, style)); 85 } 86 87 /*********************************************************************** 88 89 Wrap a FileConduit instance. 90 91 ***********************************************************************/ 92 93 this (File file) 94 { 95 super (conduit = file); 96 } 97 98 /*********************************************************************** 99 100 Return the underlying conduit. 101 102 ***********************************************************************/ 103 104 final File file () 105 { 106 return conduit; 107 } 108 } 109 110 debug (DataFile) 111 { 112 import tango.io.Stdout; 113 114 void main() 115 { 116 auto myFile = new DataFileOutput("Hello.txt"); 117 myFile.write("some text"); 118 myFile.flush; 119 Stdout.formatln ("{}:{}", myFile.file.position, myFile.seek(myFile.Anchor.Current)); 120 } 121 }