Update File.openRead to return Stream<Uint8List>
Bug: https://github.com/dart-lang/sdk/issues/36900
Change-Id: Ib2e417f4baa0048e2d4c2156c250d0cf454fdf87
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/104523
Commit-Queue: Todd Volkert <tvolkert@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
diff --git a/DEPS b/DEPS
index 0f6660d..7868be2 100644
--- a/DEPS
+++ b/DEPS
@@ -85,7 +85,7 @@
"fixnum_tag": "0.10.9",
"glob_tag": "1.1.7",
"html_tag" : "0.14.0+1",
- "http_io_rev": "773f4bc73ef572e2c37e879b065c3b406d75e8fd",
+ "http_io_rev": "0b05781c273a040ef521b5f7771dbc0356305872",
"http_multi_server_tag" : "2.0.5",
"http_parser_tag" : "3.1.3",
"http_retry_tag": "0.1.1",
diff --git a/pkg/analysis_server/benchmark/integration/main.dart b/pkg/analysis_server/benchmark/integration/main.dart
index a1be95e..f9b7421 100644
--- a/pkg/analysis_server/benchmark/integration/main.dart
+++ b/pkg/analysis_server/benchmark/integration/main.dart
@@ -121,6 +121,7 @@
}
logger.log(Level.INFO, 'tmpSrcDir: ${args.tmpSrcDirPath}');
return inputRaw
+ .cast<List<int>>()
.transform(systemEncoding.decoder)
.transform(new LineSplitter())
.transform(new InputConverter(args.tmpSrcDirPath, args.srcPathMap));
diff --git a/pkg/front_end/lib/src/fasta/parser/parser_main.dart b/pkg/front_end/lib/src/fasta/parser/parser_main.dart
index a282842..0079797 100644
--- a/pkg/front_end/lib/src/fasta/parser/parser_main.dart
+++ b/pkg/front_end/lib/src/fasta/parser/parser_main.dart
@@ -36,6 +36,7 @@
Uri uri = Uri.base.resolve(argument.substring(1));
await for (String file in new File.fromUri(uri)
.openRead()
+ .cast<List<int>>()
.transform(utf8.decoder)
.transform(const LineSplitter())) {
outLine(uri.resolve(file));
diff --git a/pkg/test_runner/lib/src/multitest.dart b/pkg/test_runner/lib/src/multitest.dart
index 94567f8..903cc16 100644
--- a/pkg/test_runner/lib/src/multitest.dart
+++ b/pkg/test_runner/lib/src/multitest.dart
@@ -195,7 +195,7 @@
// want to copy the permissions, so we create the copy by writing.
final source = File(sourceDir.join(importPath).toNativePath()).openRead();
final target = File(targetDir.join(importPath).toNativePath()).openWrite();
- futureCopies.add(source.pipe(target));
+ futureCopies.add(source.cast<List<int>>().pipe(target));
}
// Wait until all imports are copied before scheduling test cases.
diff --git a/pkg/test_runner/lib/src/testing_servers.dart b/pkg/test_runner/lib/src/testing_servers.dart
index 03f4cf5..06a1fc5 100644
--- a/pkg/test_runner/lib/src/testing_servers.dart
+++ b/pkg/test_runner/lib/src/testing_servers.dart
@@ -373,7 +373,7 @@
response.headers.set('Content-Type', 'text/xml');
}
response.headers.removeAll("X-Frame-Options");
- file.openRead().pipe(response).catchError((e) {
+ file.openRead().cast<List<int>>().pipe(response).catchError((e) {
DebugLogger.warning(
'HttpServer: error while closing the response stream', e);
});
diff --git a/pkg/testing/lib/src/test_dart/status_file_parser.dart b/pkg/testing/lib/src/test_dart/status_file_parser.dart
index c756341..60c39f8 100644
--- a/pkg/testing/lib/src/test_dart/status_file_parser.dart
+++ b/pkg/testing/lib/src/test_dart/status_file_parser.dart
@@ -82,8 +82,11 @@
throw new Exception('Cannot find test status file $path');
}
int lineNumber = 0;
- Stream<String> lines =
- file.openRead().transform(utf8.decoder).transform(new LineSplitter());
+ Stream<String> lines = file
+ .openRead()
+ .cast<List<int>>()
+ .transform(utf8.decoder)
+ .transform(new LineSplitter());
Section currentSection = new Section.always(statusFile, -1);
sections.add(currentSection);
diff --git a/pkg/vm/bin/run_binary_size_analysis.dart b/pkg/vm/bin/run_binary_size_analysis.dart
index 4a63676..4c4c9cf 100644
--- a/pkg/vm/bin/run_binary_size_analysis.dart
+++ b/pkg/vm/bin/run_binary_size_analysis.dart
@@ -39,6 +39,7 @@
// a tree.
final symbols = await input
.openRead()
+ .cast<List<int>>()
.transform(utf8.decoder)
.transform(json.decoder)
.first;
diff --git a/runtime/tests/vm/dart/v8_snapshot_profile_writer_test.dart b/runtime/tests/vm/dart/v8_snapshot_profile_writer_test.dart
index fa99a62..e3393a3 100644
--- a/runtime/tests/vm/dart/v8_snapshot_profile_writer_test.dart
+++ b/runtime/tests/vm/dart/v8_snapshot_profile_writer_test.dart
@@ -113,6 +113,7 @@
await for (String line in File(rawObjectFieldsPath)
.openRead()
+ .cast<List<int>>()
.transform(utf8.decoder)
.transform(LineSplitter())) {
Match match = matchComplete(fieldEntry, line);
@@ -133,6 +134,7 @@
bool hasMissingFields = false;
await for (String line in File(rawObjectPath)
.openRead()
+ .cast<List<int>>()
.transform(utf8.decoder)
.transform(LineSplitter())) {
Match match = matchComplete(classStart, line);
diff --git a/sdk/lib/io/file.dart b/sdk/lib/io/file.dart
index 861ce47..768ba51 100644
--- a/sdk/lib/io/file.dart
+++ b/sdk/lib/io/file.dart
@@ -483,7 +483,7 @@
* must be read to completion or the subscription on the stream must
* be cancelled.
*/
- Stream<List<int>> openRead([int start, int end]);
+ Stream<Uint8List> openRead([int start, int end]);
/**
* Creates a new independent [IOSink] for the file. The
diff --git a/sdk/lib/io/file_impl.dart b/sdk/lib/io/file_impl.dart
index 68d8b1b..66a4134 100644
--- a/sdk/lib/io/file_impl.dart
+++ b/sdk/lib/io/file_impl.dart
@@ -7,9 +7,9 @@
// Read the file in blocks of size 64k.
const int _blockSize = 64 * 1024;
-class _FileStream extends Stream<List<int>> {
+class _FileStream extends Stream<Uint8List> {
// Stream controller.
- StreamController<List<int>> _controller;
+ StreamController<Uint8List> _controller;
// Information about the underlying file.
String _path;
@@ -33,7 +33,7 @@
_FileStream.forStdin() : _position = 0;
- StreamSubscription<List<int>> listen(void onData(List<int> event),
+ StreamSubscription<Uint8List> listen(void onData(Uint8List event),
{Function onError, void onDone(), bool cancelOnError}) {
_setupController();
return _controller.stream.listen(onData,
@@ -41,7 +41,7 @@
}
void _setupController() {
- _controller = new StreamController<List<int>>(
+ _controller = new StreamController<Uint8List>(
sync: true,
onListen: _start,
onResume: _readBlock,
@@ -498,7 +498,7 @@
return new _RandomAccessFile(id, "");
}
- Stream<List<int>> openRead([int start, int end]) {
+ Stream<Uint8List> openRead([int start, int end]) {
return new _FileStream(path, start, end);
}
diff --git a/tests/standalone_2/http_launch_test.dart b/tests/standalone_2/http_launch_test.dart
index cb97f84..59f93c5 100644
--- a/tests/standalone_2/http_launch_test.dart
+++ b/tests/standalone_2/http_launch_test.dart
@@ -41,7 +41,7 @@
final File file = new File(requestPath.toFilePath());
file.exists().then((bool found) {
if (found) {
- file.openRead().pipe(request.response).catchError((e) {
+ file.openRead().cast<List<int>>().pipe(request.response).catchError((e) {
_sendNotFound(request.response);
});
} else {
diff --git a/tests/standalone_2/io/file_input_stream_test.dart b/tests/standalone_2/io/file_input_stream_test.dart
index 4d48549..68c272d 100644
--- a/tests/standalone_2/io/file_input_stream_test.dart
+++ b/tests/standalone_2/io/file_input_stream_test.dart
@@ -22,8 +22,11 @@
// File contains "Hello Dart\nwassup!\n"
File file = new File(fileName);
int linesRead = 0;
- var lineStream =
- file.openRead().transform(utf8.decoder).transform(new LineSplitter());
+ var lineStream = file
+ .openRead()
+ .cast<List<int>>()
+ .transform(utf8.decoder)
+ .transform(new LineSplitter());
lineStream.listen((line) {
linesRead++;
if (linesRead == 1) {
@@ -213,8 +216,11 @@
// File contains 10 lines.
File file = new File(fileName);
Expect.equals(length, file.lengthSync());
- var lineStream =
- file.openRead().transform(utf8.decoder).transform(new LineSplitter());
+ var lineStream = file
+ .openRead()
+ .cast<List<int>>()
+ .transform(utf8.decoder)
+ .transform(new LineSplitter());
int lineCount = 0;
lineStream.listen((line) {
lineCount++;
diff --git a/tests/standalone_2/io/file_stream_test.dart b/tests/standalone_2/io/file_stream_test.dart
index f5e5503..2d3577e 100644
--- a/tests/standalone_2/io/file_stream_test.dart
+++ b/tests/standalone_2/io/file_stream_test.dart
@@ -12,7 +12,11 @@
asyncStart();
Directory.systemTemp.createTemp('dart_file_stream').then((d) {
var file = new File("${d.path}/file");
- new File(Platform.executable).openRead().pipe(file.openWrite()).then((_) {
+ new File(Platform.executable)
+ .openRead()
+ .cast<List<int>>()
+ .pipe(file.openWrite())
+ .then((_) {
var subscription;
subscription = file.openRead().listen((data) {
subscription.pause();
@@ -39,7 +43,11 @@
asyncStart();
Directory.systemTemp.createTemp('dart_file_stream').then((d) {
var file = new File("${d.path}/file");
- new File(Platform.executable).openRead().pipe(file.openWrite()).then((_) {
+ new File(Platform.executable)
+ .openRead()
+ .cast<List<int>>()
+ .pipe(file.openWrite())
+ .then((_) {
// isEmpty will cancel the stream after first data event.
file.openRead().isEmpty.then((empty) {
Expect.isFalse(empty);
diff --git a/tests/standalone_2/io/file_test.dart b/tests/standalone_2/io/file_test.dart
index 74f57f7..8f18060 100644
--- a/tests/standalone_2/io/file_test.dart
+++ b/tests/standalone_2/io/file_test.dart
@@ -209,7 +209,7 @@
var input = file.openRead();
var output = outputFile.openWrite();
Completer done = new Completer();
- input.pipe(output).then((_) {
+ input.cast<List<int>>().pipe(output).then((_) {
var copy = outputFile.openRead();
int position = 0;
copy.listen((d) {
diff --git a/tests/standalone_2/io/http_server_early_client_close2_test.dart b/tests/standalone_2/io/http_server_early_client_close2_test.dart
index 80bc51c..1a84dfd 100644
--- a/tests/standalone_2/io/http_server_early_client_close2_test.dart
+++ b/tests/standalone_2/io/http_server_early_client_close2_test.dart
@@ -18,6 +18,7 @@
String name = Platform.script.toFilePath();
new File(name)
.openRead()
+ .cast<List<int>>()
.pipe(request.response)
.catchError((e) {/* ignore */});
});
diff --git a/tests/standalone_2/io/http_server_early_client_close_test.dart b/tests/standalone_2/io/http_server_early_client_close_test.dart
index 4cacde0..59841f0 100644
--- a/tests/standalone_2/io/http_server_early_client_close_test.dart
+++ b/tests/standalone_2/io/http_server_early_client_close_test.dart
@@ -111,6 +111,7 @@
String name = Platform.script.toFilePath();
new File(name)
.openRead()
+ .cast<List<int>>()
.pipe(request.response)
.catchError((e) {/* ignore */});
});
diff --git a/tests/standalone_2/io/http_server_response_test.dart b/tests/standalone_2/io/http_server_response_test.dart
index baa729b..2f2e657 100644
--- a/tests/standalone_2/io/http_server_response_test.dart
+++ b/tests/standalone_2/io/http_server_response_test.dart
@@ -67,6 +67,7 @@
testServerRequest((server, request) {
new File("__nonexistent_file_")
.openRead()
+ .cast<List<int>>()
.pipe(request.response)
.catchError((e) {
server.close();
@@ -122,6 +123,7 @@
testServerRequest((server, request) {
new File("__nonexistent_file_")
.openRead()
+ .cast<List<int>>()
.pipe(request.response)
.catchError((e) {
server.close();
diff --git a/tests/standalone_2/io/https_server_test.dart b/tests/standalone_2/io/https_server_test.dart
index ad3cc51..fe151bc 100644
--- a/tests/standalone_2/io/https_server_test.dart
+++ b/tests/standalone_2/io/https_server_test.dart
@@ -69,6 +69,7 @@
String name = Platform.script.toFilePath();
new File(name)
.openRead()
+ .cast<List<int>>()
.pipe(request.response)
.catchError((e) {/* ignore */});
});
diff --git a/tests/standalone_2/io/pipe_server_test.dart b/tests/standalone_2/io/pipe_server_test.dart
index a9a3975..0b30e2e 100644
--- a/tests/standalone_2/io/pipe_server_test.dart
+++ b/tests/standalone_2/io/pipe_server_test.dart
@@ -45,7 +45,7 @@
void connectHandler() {
String srcFileName = getDataFilename("readline_test1.dat");
Stream fileInput = new File(srcFileName).openRead();
- fileInput.pipe(_socket).then((_) {
+ fileInput.cast<List<int>>().pipe(_socket).then((_) {
var tempDir = Directory.systemTemp.createTempSync('dart_pipe_server');
var dstFileName = tempDir.path + "/readline_test1.dat";
var dstFile = new File(dstFileName);
diff --git a/tests/standalone_2/io/stream_pipe_test.dart b/tests/standalone_2/io/stream_pipe_test.dart
index 9f4067c..de11c0a 100644
--- a/tests/standalone_2/io/stream_pipe_test.dart
+++ b/tests/standalone_2/io/stream_pipe_test.dart
@@ -67,7 +67,7 @@
String dstFileName = tempDir.path + "/readline_test1.dat";
new File(dstFileName).createSync();
var output = new File(dstFileName).openWrite();
- srcStream.pipe(output).then((_) {
+ srcStream.cast<List<int>>().pipe(output).then((_) {
bool result = compareFileContent(srcFileName, dstFileName);
new File(dstFileName).deleteSync();
tempDir.deleteSync();
@@ -92,7 +92,7 @@
var dstFile = new File(dstFileName);
dstFile.createSync();
var output = dstFile.openWrite();
- output.addStream(srcStream).then((_) {
+ output.addStream(srcStream.cast<List<int>>()).then((_) {
output.add([32]);
output.close();
output.done.then((_) {
@@ -131,9 +131,9 @@
var dstFile = new File(dstFileName);
dstFile.createSync();
var output = dstFile.openWrite();
- output.addStream(srcStream).then((_) {
+ output.addStream(srcStream.cast<List<int>>()).then((_) {
var srcStream2 = srcFile.openRead();
- output.addStream(srcStream2).then((_) {
+ output.addStream(srcStream2.cast<List<int>>()).then((_) {
output.close();
output.done.then((_) {
var src = srcFile.openSync();
diff --git a/tools/bots/results.dart b/tools/bots/results.dart
index 1848db5..c42d828 100644
--- a/tools/bots/results.dart
+++ b/tools/bots/results.dart
@@ -120,6 +120,7 @@
final results = <Map<String, dynamic>>[];
final lines = new File(path)
.openRead()
+ .cast<List<int>>()
.transform(utf8.decoder)
.transform(new LineSplitter());
await for (final line in lines) {
diff --git a/tools/dart2js/class_generator/class_generator.dart b/tools/dart2js/class_generator/class_generator.dart
index 55bcdad..50af327 100644
--- a/tools/dart2js/class_generator/class_generator.dart
+++ b/tools/dart2js/class_generator/class_generator.dart
@@ -140,7 +140,7 @@
File measuring = new File("${dir.path}/measuring.js");
IOSink sink = measuring.openWrite();
sink.writeln("var start = new Date();");
- await sink.addStream(new File(fileName).openRead());
+ await sink.addStream(new File(fileName).openRead().cast<List<int>>());
sink.writeln("print(new Date() - start)");
String command;
List<String> args;
diff --git a/tools/dart2js/sourceMapViewer/bin/source_map_viewer.dart b/tools/dart2js/sourceMapViewer/bin/source_map_viewer.dart
index b97460c..51b958c 100644
--- a/tools/dart2js/sourceMapViewer/bin/source_map_viewer.dart
+++ b/tools/dart2js/sourceMapViewer/bin/source_map_viewer.dart
@@ -47,7 +47,11 @@
}
Uri uri = sourceMapFile.resolve(path);
- new File.fromUri(uri).openRead().pipe(request.response).catchError((e) {
+ new File.fromUri(uri)
+ .openRead()
+ .cast<List<int>>()
+ .pipe(request.response)
+ .catchError((e) {
print("Error: $e");
request.response.close();
});