OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #library('file_system_vm'); | 5 #library('file_system_vm'); |
6 #import('file_system.dart'); | 6 #import('file_system.dart'); |
7 | 7 |
8 /** File system implementation using the vm api's. */ | 8 /** File system implementation using the vm api's. */ |
9 class VMFileSystem implements FileSystem { | 9 class VMFileSystem implements FileSystem { |
10 void writeString(String outfile, String text) { | 10 void writeString(String outfile, String text) { |
11 var f = new File(outfile); | 11 var f = new File(outfile); |
12 var stream = f.openOutputStream(); | 12 var stream = f.openOutputStream(); |
13 stream.write(text.charCodes()); | 13 stream.write(text.charCodes()); |
14 stream.end(); | 14 stream.close(); |
15 } | 15 } |
16 | 16 |
17 String readAll(String filename) { | 17 String readAll(String filename) { |
18 var file = new File(filename); | 18 var file = new File(filename); |
19 file.openSync(); | 19 file.openSync(); |
20 var length = file.lengthSync(); | 20 var length = file.lengthSync(); |
21 var buffer = new List<int>(length); | 21 var buffer = new List<int>(length); |
22 var bytes = file.readListSync(buffer, 0, length); | 22 var bytes = file.readListSync(buffer, 0, length); |
23 file.closeSync(); | 23 file.closeSync(); |
24 return new String.fromCharCodes(buffer); | 24 return new String.fromCharCodes(buffer); |
25 } | 25 } |
26 | 26 |
27 bool fileExists(String filename) { | 27 bool fileExists(String filename) { |
28 return new File(filename).existsSync(); | 28 return new File(filename).existsSync(); |
29 } | 29 } |
30 } | 30 } |
OLD | NEW |