Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Unified Diff: lib/src/template/file_system_vm.dart

Issue 11092092: Support compiling templates in the browser. Base URL: git@github.com:dart-lang/dart-web-components.git@master
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/template/file_system_memory.dart ('k') | lib/src/template/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/template/file_system_vm.dart
diff --git a/lib/src/template/file_system_vm.dart b/lib/src/template/file_system_vm.dart
index bc1ab676549314d4327dba8df9cce03dd7848c56..32d005e4745a6cf3a540e548ece69c279e73691b 100644
--- a/lib/src/template/file_system_vm.dart
+++ b/lib/src/template/file_system_vm.dart
@@ -10,19 +10,43 @@ import 'file_system.dart';
/** File system implementation using the vm api's. */
class VMFileSystem implements FileSystem {
+
+ /** Pending futures for file write requests. */
+ List<Future> _pending = <Future>[];
+
+ Future flush() {
+ return Futures.wait(_pending).transform((_) {
+ // Some new work might be pending that was only queued up after the call
+ // to flush so we cannot simply clear the future list.
+ _pending = _pending.filter((f) => !f.hasValue);
+ return null;
+ });
+ }
+
void writeString(String path, String text) {
+ // TODO(jacobr): the following async code mysterously leads to sporadic
+ // data corruption in the Dart VM. We need to create a reliable repro and
+ // file a bug with the VM team.
+ /*
+ _pending.add(new File(path).open(FileMode.WRITE).chain(
+ (file) => file.writeString(text).chain((_) => file.close())));
+ */
var file = new File(path).openSync(FileMode.WRITE);
file.writeStringSync(text);
file.closeSync();
}
- String readAll(String filename) {
- var file = (new File(filename)).openSync();
- var length = file.lengthSync();
- var buffer = new List<int>(length);
- var bytes = file.readListSync(buffer, 0, length);
- file.closeSync();
- return new String.fromCharCodes(new Utf8Decoder(buffer).decodeRest());
+ Future<String> readAll(String filename) {
+ return new File(filename).open().chain((file) =>
+ file.length().chain((int length) {
+ var buffer = new List<int>(length);
+
+ return file.readList(buffer, 0, length).transform((length) {
+ file.close();
+ // TODO(jmesserly): support all html5 encodings not just UTF8.
+ return new String.fromCharCodes(new Utf8Decoder(buffer).decodeRest());
+ });
+ }));
}
void createDirectory(String path, [bool recursive = false]) {
« no previous file with comments | « lib/src/template/file_system_memory.dart ('k') | lib/src/template/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698