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

Unified Diff: pkg/polymer/lib/src/file_system/console.dart

Issue 23224003: move polymer.dart into dart svn (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add --deploy to todomvc sample Created 7 years, 4 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 | « pkg/polymer/lib/src/file_system.dart ('k') | pkg/polymer/lib/src/files.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/polymer/lib/src/file_system/console.dart
diff --git a/pkg/polymer/lib/src/file_system/console.dart b/pkg/polymer/lib/src/file_system/console.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6776745b2fe96334b4f05512f7ca32f9e528a98d
--- /dev/null
+++ b/pkg/polymer/lib/src/file_system/console.dart
@@ -0,0 +1,47 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library console;
+
+import 'dart:async';
+import 'dart:io';
+import 'dart:utf';
+import 'package:polymer/src/file_system.dart';
+
+/** File system implementation for console VM (i.e. no browser). */
+class ConsoleFileSystem implements FileSystem {
+
+ /** Pending futures for file write requests. */
+ final _pending = <String, Future>{};
+
+ Future flush() => Future.wait(_pending.values.toList());
+
+ void writeString(String path, String text) {
+ if(!_pending.containsKey(path)) {
+ _pending[path] = new File(path).open(mode: FileMode.WRITE)
+ .then((file) => file.writeString(text))
+ .then((file) => file.close())
+ .whenComplete(() { _pending.remove(path); });
+ }
+ }
+
+ // TODO(jmesserly): even better would be to pass the RandomAccessFile directly
+ // to html5lib. This will require a further restructuring of FileSystem.
+ // Probably it just needs "readHtml" and "readText" methods.
+ Future<List<int>> readTextOrBytes(String path) {
+ return new File(path).open().then(
+ (file) => file.length().then((length) {
+ // TODO(jmesserly): is this guaranteed to read all of the bytes?
+ var buffer = new List<int>(length);
+ return file.readInto(buffer, 0, length)
+ .then((_) => file.close())
+ .then((_) => buffer);
+ }));
+ }
+
+ // TODO(jmesserly): do we support any encoding other than UTF-8 for Dart?
+ Future<String> readText(String path) {
+ return readTextOrBytes(path).then(decodeUtf8);
+ }
+}
« no previous file with comments | « pkg/polymer/lib/src/file_system.dart ('k') | pkg/polymer/lib/src/files.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698