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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library console;
6
7 import 'dart:async';
8 import 'dart:io';
9 import 'dart:utf';
10 import 'package:polymer/src/file_system.dart';
11
12 /** File system implementation for console VM (i.e. no browser). */
13 class ConsoleFileSystem implements FileSystem {
14
15 /** Pending futures for file write requests. */
16 final _pending = <String, Future>{};
17
18 Future flush() => Future.wait(_pending.values.toList());
19
20 void writeString(String path, String text) {
21 if(!_pending.containsKey(path)) {
22 _pending[path] = new File(path).open(mode: FileMode.WRITE)
23 .then((file) => file.writeString(text))
24 .then((file) => file.close())
25 .whenComplete(() { _pending.remove(path); });
26 }
27 }
28
29 // TODO(jmesserly): even better would be to pass the RandomAccessFile directly
30 // to html5lib. This will require a further restructuring of FileSystem.
31 // Probably it just needs "readHtml" and "readText" methods.
32 Future<List<int>> readTextOrBytes(String path) {
33 return new File(path).open().then(
34 (file) => file.length().then((length) {
35 // TODO(jmesserly): is this guaranteed to read all of the bytes?
36 var buffer = new List<int>(length);
37 return file.readInto(buffer, 0, length)
38 .then((_) => file.close())
39 .then((_) => buffer);
40 }));
41 }
42
43 // TODO(jmesserly): do we support any encoding other than UTF-8 for Dart?
44 Future<String> readText(String path) {
45 return readTextOrBytes(path).then(decodeUtf8);
46 }
47 }
OLDNEW
« 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