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

Side by Side Diff: html/lib/parser_console.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 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 | « html/lib/parser.dart ('k') | html/lib/src/char_encodings.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 /// This library adds `dart:io` support to the HTML5 parser. Call
2 /// [initDartIOSupport] before calling the [parse] methods and they will accept
3 /// a [RandomAccessFile] as input, in addition to the other input types.
4 library parser_console;
5
6 import 'dart:io';
7 import 'parser.dart';
8 import 'src/inputstream.dart' as inputstream;
9
10 /// Adds support to the [HtmlParser] for running on a console VM. In particular
11 /// this means it will be able to handle `dart:io` and [RandomAccessFile]s as
12 /// input to the various [parse] methods.
13 void useConsole() {
14 inputstream.consoleSupport = new _ConsoleSupport();
15 }
16
17 class _ConsoleSupport extends inputstream.ConsoleSupport {
18 List<int> bytesFromFile(source) {
19 if (source is! RandomAccessFile) return null;
20 return readAllBytesFromFile(source);
21 }
22 }
23
24 // TODO(jmesserly): this should be `RandomAccessFile.readAllBytes`.
25 /// Synchronously reads all bytes from the [file].
26 List<int> readAllBytesFromFile(RandomAccessFile file) {
27 int length = file.lengthSync();
28 var bytes = new List<int>(length);
29
30 int bytesRead = 0;
31 while (bytesRead < length) {
32 int read = file.readIntoSync(bytes, bytesRead, length - bytesRead);
33 if (read <= 0) {
34 // This could happen if, for example, the file was resized while
35 // we're reading. Just shrink the bytes array and move on.
36 bytes = bytes.sublist(0, bytesRead);
37 break;
38 }
39 bytesRead += read;
40 }
41 return bytes;
42 }
OLDNEW
« no previous file with comments | « html/lib/parser.dart ('k') | html/lib/src/char_encodings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698