Changeset 64
- Timestamp:
- 06/04/06 17:19:45 (2 years ago)
- Files:
-
- trunk/tango/io/File.d (modified) (2 diffs)
- trunk/tango/io/UnicodeFile.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tango/io/File.d
r7 r64 93 93 void[] read () 94 94 { 95 ubyte[] content; 95 auto conduit = new FileConduit (this); 96 scope (exit) 97 conduit.close(); 96 98 97 auto conduit = new FileConduit (this); 98 try { 99 content = new ubyte[cast(int) conduit.length]; 99 auto content = new ubyte[cast(int) conduit.length]; 100 100 101 // read the entire file into memory and return it 102 if (conduit.read (content) != content.length) 103 throw new IOException ("eof whilst reading"); 104 } finally { 105 conduit.close (); 106 } 101 // read the entire file into memory and return it 102 if (conduit.read (content) != content.length) 103 throw new IOException ("eof whilst reading"); 104 107 105 return content; 108 106 } … … 139 137 { 140 138 auto conduit = new FileConduit (this, style); 141 try { 142 conduit.flush (content); 143 } finally { 144 conduit.close (); 145 } 139 scope (exit) 140 conduit.close(); 141 142 conduit.flush (content); 146 143 return this; 147 144 } trunk/tango/io/UnicodeFile.d
r50 r64 40 40 41 41 public import tango.io.FilePath; 42 42 43 public import tango.convert.Unicode; 43 44 … … 186 187 { 187 188 auto conduit = new FileConduit (this); 188 189 try { 190 // allocate enough space for the entire file 191 auto content = new ubyte [conduit.length]; 192 193 //read the content 194 if (conduit.read (content) != content.length) 195 throw new IOException ("unexpected eof"); 196 197 return unicode.decode (content); 198 } finally { 199 conduit.close(); 200 } 189 scope (exit) 190 conduit.close(); 191 192 // allocate enough space for the entire file 193 auto content = new ubyte [conduit.length]; 194 195 //read the content 196 if (conduit.read (content) != content.length) 197 throw new IOException ("unexpected eof"); 198 199 return unicode.decode (content); 201 200 } 202 201 … … 238 237 private final UnicodeFileT write (T[] content, FileStyle.Bits style, bool bom) 239 238 { 240 // convert to external representation 239 // convert to external representation (may throw an exeption) 241 240 void[] converted = unicode.encode (content); 242 241 243 242 // open file after conversion ~ in case of exceptions 244 auto FileConduit conduit = new FileConduit (this, style); 245 246 try { 247 if (bom) 248 conduit.flush (unicode.getSignature); 249 250 // and write 251 conduit.flush (converted); 252 } finally { 253 conduit.close(); 254 } 243 auto conduit = new FileConduit (this, style); 244 scope (exit) 245 conduit.close(); 246 247 if (bom) 248 conduit.flush (unicode.getSignature); 249 250 // and write 251 conduit.flush (converted); 255 252 return this; 256 253 }












