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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:utf'; 8 import 'dart:utf';
9 import 'file_system.dart'; 9 import 'file_system.dart';
10 10
11 /** File system implementation using the vm api's. */ 11 /** File system implementation using the vm api's. */
12 class VMFileSystem implements FileSystem { 12 class VMFileSystem implements FileSystem {
13
14 /** Pending futures for file write requests. */
15 List<Future> _pending = <Future>[];
16
17 Future flush() {
18 return Futures.wait(_pending).transform((_) {
19 // Some new work might be pending that was only queued up after the call
20 // to flush so we cannot simply clear the future list.
21 _pending = _pending.filter((f) => !f.hasValue);
22 return null;
23 });
24 }
25
13 void writeString(String path, String text) { 26 void writeString(String path, String text) {
27 // TODO(jacobr): the following async code mysterously leads to sporadic
28 // data corruption in the Dart VM. We need to create a reliable repro and
29 // file a bug with the VM team.
30 /*
31 _pending.add(new File(path).open(FileMode.WRITE).chain(
32 (file) => file.writeString(text).chain((_) => file.close())));
33 */
14 var file = new File(path).openSync(FileMode.WRITE); 34 var file = new File(path).openSync(FileMode.WRITE);
15 file.writeStringSync(text); 35 file.writeStringSync(text);
16 file.closeSync(); 36 file.closeSync();
17 } 37 }
18 38
19 String readAll(String filename) { 39 Future<String> readAll(String filename) {
20 var file = (new File(filename)).openSync(); 40 return new File(filename).open().chain((file) =>
21 var length = file.lengthSync(); 41 file.length().chain((int length) {
22 var buffer = new List<int>(length); 42 var buffer = new List<int>(length);
23 var bytes = file.readListSync(buffer, 0, length); 43
24 file.closeSync(); 44 return file.readList(buffer, 0, length).transform((length) {
25 return new String.fromCharCodes(new Utf8Decoder(buffer).decodeRest()); 45 file.close();
46 // TODO(jmesserly): support all html5 encodings not just UTF8.
47 return new String.fromCharCodes(new Utf8Decoder(buffer).decodeRest());
48 });
49 }));
26 } 50 }
27 51
28 void createDirectory(String path, [bool recursive = false]) { 52 void createDirectory(String path, [bool recursive = false]) {
29 // TODO(rnystrom): Implement. 53 // TODO(rnystrom): Implement.
30 throw 'createDirectory() is not implemented by VMFileSystem yet.'; 54 throw 'createDirectory() is not implemented by VMFileSystem yet.';
31 } 55 }
32 56
33 void removeDirectory(String path, [bool recursive = false]) { 57 void removeDirectory(String path, [bool recursive = false]) {
34 // TODO(rnystrom): Implement. 58 // TODO(rnystrom): Implement.
35 throw 'removeDirectory() is not implemented by VMFileSystem yet.'; 59 throw 'removeDirectory() is not implemented by VMFileSystem yet.';
36 } 60 }
37 } 61 }
OLDNEW
« 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