d1f780df0b
also gets the tests running Changes to scripts: * pkg/pkg.gyp: add 'third_party' to list of folders to search * tools/publish_pkg.py: update copyright year * tools/publish_all_pkgs.py: also include pkg/third_party Changes to html5lib: * pubspec.yaml -- removed versions * README.md -- removed some historical notes * added html5lib.status * test/browser -- rename browser_tests to browser_test so test framework finds it * test/parser_test.dart, test/parser_feature_test.dart -- moved dart:io test into parser_test so parser_feature_test can work in browser * test/support.dart -- now finds the data folder relative to entry point script * test/support.dart -- rename "pathos" import to "path" Not changed: * ./test/run.sh still works for testing, in addition to ./tools/test.dart R=dgrove@google.com, ricow@google.com, sigmund@google.com Review URL: https://codereview.chromium.org//22375011 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@26152 260f80e4-7a28-3924-810f-c04153c831b5
47 lines
1.4 KiB
Dart
47 lines
1.4 KiB
Dart
/**
|
|
* This library adds `dart:io` support to the HTML5 parser. Call
|
|
* [initDartIOSupport] before calling the [parse] methods and they will accept
|
|
* a [RandomAccessFile] as input, in addition to the other input types.
|
|
*/
|
|
library parser_console;
|
|
|
|
import 'dart:io';
|
|
import 'parser.dart';
|
|
import 'src/inputstream.dart' as inputstream;
|
|
|
|
/**
|
|
* Adds support to the [HtmlParser] for running on a console VM. In particular
|
|
* this means it will be able to handle `dart:io` and [RandomAccessFile]s as
|
|
* input to the various [parse] methods.
|
|
*/
|
|
void useConsole() {
|
|
inputstream.consoleSupport = new _ConsoleSupport();
|
|
}
|
|
|
|
class _ConsoleSupport extends inputstream.ConsoleSupport {
|
|
List<int> bytesFromFile(source) {
|
|
if (source is! RandomAccessFile) return null;
|
|
return readAllBytesFromFile(source);
|
|
}
|
|
}
|
|
|
|
// TODO(jmesserly): this should be `RandomAccessFile.readAllBytes`.
|
|
/** Synchronously reads all bytes from the [file]. */
|
|
List<int> readAllBytesFromFile(RandomAccessFile file) {
|
|
int length = file.lengthSync();
|
|
var bytes = new List<int>(length);
|
|
|
|
int bytesRead = 0;
|
|
while (bytesRead < length) {
|
|
int read = file.readIntoSync(bytes, bytesRead, length - bytesRead);
|
|
if (read <= 0) {
|
|
// This could happen if, for example, the file was resized while
|
|
// we're reading. Just shrink the bytes array and move on.
|
|
bytes = bytes.sublist(0, bytesRead);
|
|
break;
|
|
}
|
|
bytesRead += read;
|
|
}
|
|
return bytes;
|
|
}
|