OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 // TODO(terry): Investigate common library for file I/O shared between frog and
tools. |
| 6 |
| 7 #library('file_system_vm'); |
| 8 #import('dart:io'); |
| 9 #import('file_system.dart'); |
| 10 #import('dart:utf'); |
| 11 |
| 12 /** File system implementation using the vm api's. */ |
| 13 class VMFileSystem implements FileSystem { |
| 14 void writeString(String path, String text) { |
| 15 var file = new File(path).openSync(FileMode.WRITE); |
| 16 file.writeStringSync(text); |
| 17 file.closeSync(); |
| 18 } |
| 19 |
| 20 String readAll(String filename) { |
| 21 var file = (new File(filename)).openSync(); |
| 22 var length = file.lengthSync(); |
| 23 var buffer = new List<int>(length); |
| 24 var bytes = file.readListSync(buffer, 0, length); |
| 25 file.closeSync(); |
| 26 return new String.fromCharCodes(new Utf8Decoder(buffer).decodeRest()); |
| 27 } |
| 28 |
| 29 bool fileExists(String filename) { |
| 30 return new File(filename).existsSync(); |
| 31 } |
| 32 |
| 33 void createDirectory(String path, [bool recursive = false]) { |
| 34 // TODO(rnystrom): Implement. |
| 35 throw 'createDirectory() is not implemented by VMFileSystem yet.'; |
| 36 } |
| 37 |
| 38 void removeDirectory(String path, [bool recursive = false]) { |
| 39 // TODO(rnystrom): Implement. |
| 40 throw 'removeDirectory() is not implemented by VMFileSystem yet.'; |
| 41 } |
| 42 } |
OLD | NEW |