| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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('dart:io'); | 6 #import('dart:io'); |
| 7 #import('file_system.dart'); | 7 #import('file_system.dart'); |
| 8 #import('dart:utf8'); | 8 #import('dart:utf'); |
| 9 | 9 |
| 10 /** File system implementation using the vm api's. */ | 10 /** File system implementation using the vm api's. */ |
| 11 class VMFileSystem implements FileSystem { | 11 class VMFileSystem implements FileSystem { |
| 12 void writeString(String path, String text) { | 12 void writeString(String path, String text) { |
| 13 var file = new File(path).openSync(FileMode.WRITE); | 13 var file = new File(path).openSync(FileMode.WRITE); |
| 14 file.writeStringSync(text); | 14 file.writeStringSync(text); |
| 15 file.closeSync(); | 15 file.closeSync(); |
| 16 } | 16 } |
| 17 | 17 |
| 18 String readAll(String filename) { | 18 String readAll(String filename) { |
| 19 var file = (new File(filename)).openSync(); | 19 var file = (new File(filename)).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(Utf8Decoder.decodeUtf8(buffer)); | 24 return new String.fromCharCodes(new Utf8Decoder(buffer).decodeRest()); |
| 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 |
| 31 void createDirectory(String path, [bool recursive = false]) { | 31 void createDirectory(String path, [bool recursive = false]) { |
| 32 // TODO(rnystrom): Implement. | 32 // TODO(rnystrom): Implement. |
| 33 throw 'createDirectory() is not implemented by VMFileSystem yet.'; | 33 throw 'createDirectory() is not implemented by VMFileSystem yet.'; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void removeDirectory(String path, [bool recursive = false]) { | 36 void removeDirectory(String path, [bool recursive = false]) { |
| 37 // TODO(rnystrom): Implement. | 37 // TODO(rnystrom): Implement. |
| 38 throw 'removeDirectory() is not implemented by VMFileSystem yet.'; | 38 throw 'removeDirectory() is not implemented by VMFileSystem yet.'; |
| 39 } | 39 } |
| 40 } | 40 } |
| OLD | NEW |