Chromium Code Reviews| 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 outfile, String text) { | 12 void writeString(String outfile, String text) { |
| 13 var f = new File(outfile); | 13 var f = new File(outfile); |
| 14 var stream = f.openOutputStreamSync(); | 14 var stream = f.openOutputStreamSync(); |
| 15 stream.write(text.charCodes()); | 15 stream.write(text.charCodes()); |
| 16 stream.close(); | 16 stream.close(); |
| 17 } | 17 } |
| 18 | 18 |
| 19 String readAll(String filename) { | 19 String readAll(String filename) { |
| 20 var file = (new File(filename)).openSync(); | 20 var file = (new File(filename)).openSync(); |
| 21 var length = file.lengthSync(); | 21 var length = file.lengthSync(); |
| 22 var buffer = new List<int>(length); | 22 var buffer = new List<int>(length); |
| 23 var bytes = file.readListSync(buffer, 0, length); | 23 var bytes = file.readListSync(buffer, 0, length); |
| 24 file.closeSync(); | 24 file.closeSync(); |
| 25 return new String.fromCharCodes(Utf8Decoder.decodeUtf8(buffer)); | 25 return decodeUtf8(buffer); |
|
ahe
2012/02/29 13:23:02
Please keep the explicit call to new String.fromCh
dgrove
2012/03/02 12:34:30
decodeUtf8 returns a String, while string.fromChar
ahe
2012/03/05 12:55:53
Doesn't this work:
return new String.fromCharCode
dgrove
2012/03/05 13:35:13
Done.
| |
| 26 } | 26 } |
| 27 | 27 |
| 28 bool fileExists(String filename) { | 28 bool fileExists(String filename) { |
| 29 return new File(filename).existsSync(); | 29 return new File(filename).existsSync(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void createDirectory(String path, [bool recursive = false]) { | 32 void createDirectory(String path, [bool recursive = false]) { |
| 33 // TODO(rnystrom): Implement. | 33 // TODO(rnystrom): Implement. |
| 34 throw 'createDirectory() is not implemented by VMFileSystem yet.'; | 34 throw 'createDirectory() is not implemented by VMFileSystem yet.'; |
| 35 } | 35 } |
| 36 | 36 |
| 37 void removeDirectory(String path, [bool recursive = false]) { | 37 void removeDirectory(String path, [bool recursive = false]) { |
| 38 // TODO(rnystrom): Implement. | 38 // TODO(rnystrom): Implement. |
| 39 throw 'removeDirectory() is not implemented by VMFileSystem yet.'; | 39 throw 'removeDirectory() is not implemented by VMFileSystem yet.'; |
| 40 } | 40 } |
| 41 } | 41 } |
| OLD | NEW |