Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

File.d

Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003         @file File.d
00004         
00005         Copyright (c) 2004 Kris Bell
00006         
00007         This software is provided 'as-is', without any express or implied
00008         warranty. In no event will the authors be held liable for damages
00009         of any kind arising from the use of this software.
00010         
00011         Permission is hereby granted to anyone to use this software for any 
00012         purpose, including commercial applications, and to alter it and/or 
00013         redistribute it freely, subject to the following restrictions:
00014         
00015         1. The origin of this software must not be misrepresented; you must 
00016            not claim that you wrote the original software. If you use this 
00017            software in a product, an acknowledgment within documentation of 
00018            said product would be appreciated but is not required.
00019 
00020         2. Altered source versions must be plainly marked as such, and must 
00021            not be misrepresented as being the original software.
00022 
00023         3. This notice may not be removed or altered from any distribution
00024            of the source.
00025 
00026         4. Derivative works are permitted, but they must carry this notice
00027            in full and credit the original source.
00028 
00029 
00030                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00031 
00032 
00033         @version        Initial version; March 2005      
00034 
00035         @author         Kris
00036 
00037 *******************************************************************************/
00038 
00039 module mango.io.File;
00040 
00041 private import  mango.io.FileStyle, 
00042                 mango.io.FileProxy,
00043                 mango.io.Exception,
00044                 mango.io.FileConduit;
00045 
00046 /*******************************************************************************
00047 
00048         A wrapper atop of FileConduit to expose a simpler API. This one
00049         return the entire file content as a void[], and sets the content
00050         to reflect a given void[].
00051 
00052         Method read() returns the current content of the file, whilst write()
00053         sets the file content, and file length, to the provided array. Method
00054         append() adds content to the tail of the file.
00055 
00056         Methods to inspect the file system, check the status of a file or
00057         directory, and other facilities are made available via the FileProxy
00058         superclass.
00059 
00060 *******************************************************************************/
00061 
00062 class File : FileProxy
00063 {
00064         /***********************************************************************
00065         
00066                 Construct a File from a text string
00067 
00068         ***********************************************************************/
00069 
00070         this (char[] path)
00071         {
00072                 super (path);
00073         }
00074 
00075         /***********************************************************************
00076         
00077                 Construct a File from the provided FilePath
00078 
00079         ***********************************************************************/
00080                                   
00081         this (FilePath path)
00082         {
00083                 super (path);
00084         }
00085 
00086         /***********************************************************************
00087 
00088                 Return the content of the file.
00089 
00090         ***********************************************************************/
00091 
00092         void[] read ()
00093         {
00094                 auto FileConduit conduit = new FileConduit (this);  
00095                 ubyte[] content = new ubyte[conduit.length];
00096 
00097                 // read the entire file into memory and return it
00098                 if (conduit.read (content) != content.length)
00099                     throw new IOException ("eof whilst reading");
00100 
00101                 return content;
00102         }
00103 
00104         /***********************************************************************
00105 
00106                 Set the file content and length to reflect the given array.
00107 
00108         ***********************************************************************/
00109 
00110         File write (void[] content)
00111         {
00112                 return write (content, FileStyle.WriteTruncate);  
00113         }
00114 
00115         /***********************************************************************
00116 
00117                 Append content to the file.
00118 
00119         ***********************************************************************/
00120 
00121         File append (void[] content)
00122         {
00123                 return write (content, FileStyle.WriteAppending);  
00124         }
00125 
00126         /***********************************************************************
00127 
00128                 Set the file content and length to reflect the given array.
00129 
00130         ***********************************************************************/
00131 
00132         private File write (void[] content, FileStyle style)
00133         {
00134                 auto FileConduit conduit = new FileConduit (this, style);  
00135                 conduit.write (content);
00136                 return this;
00137         }
00138 }

Generated on Fri May 27 18:11:55 2005 for Mango by  doxygen 1.4.0