mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 12:57:42 +00:00
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>
This commit is contained in:
parent
c92af46433
commit
ddfde57069
2
DEPS
2
DEPS
|
@ -85,7 +85,7 @@ vars = {
|
|||
"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",
|
||||
|
|
|
@ -121,6 +121,7 @@ Stream<Operation> openInput(PerfArgs args) {
|
|||
}
|
||||
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));
|
||||
|
|
|
@ -36,6 +36,7 @@ mainEntryPoint(List<String> arguments) async {
|
|||
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));
|
||||
|
|
|
@ -195,7 +195,7 @@ Future<List<TestFile>> splitMultitest(
|
|||
// 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.
|
||||
|
|
|
@ -373,7 +373,7 @@ class TestingServers {
|
|||
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);
|
||||
});
|
||||
|
|
|
@ -82,8 +82,11 @@ void ReadConfigurationInto(Path path, List<Section> sections, void onDone()) {
|
|||
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);
|
||||
|
|
|
@ -39,6 +39,7 @@ $ google-chrome <output-directory>/index.html
|
|||
// a tree.
|
||||
final symbols = await input
|
||||
.openRead()
|
||||
.cast<List<int>>()
|
||||
.transform(utf8.decoder)
|
||||
.transform(json.decoder)
|
||||
.first;
|
||||
|
|
|
@ -113,6 +113,7 @@ testMacros(String sdkRoot) async {
|
|||
|
||||
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 @@ testMacros(String sdkRoot) async {
|
|||
bool hasMissingFields = false;
|
||||
await for (String line in File(rawObjectPath)
|
||||
.openRead()
|
||||
.cast<List<int>>()
|
||||
.transform(utf8.decoder)
|
||||
.transform(LineSplitter())) {
|
||||
Match match = matchComplete(classStart, line);
|
||||
|
|
|
@ -483,7 +483,7 @@ abstract class File implements FileSystemEntity {
|
|||
* 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
|
||||
|
|
|
@ -7,9 +7,9 @@ part of dart.io;
|
|||
// 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 @@ class _FileStream extends Stream<List<int>> {
|
|||
|
||||
_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 @@ class _FileStream extends Stream<List<int>> {
|
|||
}
|
||||
|
||||
void _setupController() {
|
||||
_controller = new StreamController<List<int>>(
|
||||
_controller = new StreamController<Uint8List>(
|
||||
sync: true,
|
||||
onListen: _start,
|
||||
onResume: _readBlock,
|
||||
|
@ -498,7 +498,7 @@ class _File extends FileSystemEntity implements File {
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ handleRequest(HttpRequest request) {
|
|||
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 {
|
||||
|
|
|
@ -22,8 +22,11 @@ void testStringLineSplitter() {
|
|||
// 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 @@ void testStringLineSplitterEnding(String name, int length) {
|
|||
// 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++;
|
||||
|
|
|
@ -12,7 +12,11 @@ void testPauseResumeCancelStream() {
|
|||
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 @@ void testStreamIsEmpty() {
|
|||
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);
|
||||
|
|
|
@ -209,7 +209,7 @@ class FileTest {
|
|||
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) {
|
||||
|
|
|
@ -18,6 +18,7 @@ main() {
|
|||
String name = Platform.script.toFilePath();
|
||||
new File(name)
|
||||
.openRead()
|
||||
.cast<List<int>>()
|
||||
.pipe(request.response)
|
||||
.catchError((e) {/* ignore */});
|
||||
});
|
||||
|
|
|
@ -111,6 +111,7 @@ testEarlyClose2() {
|
|||
String name = Platform.script.toFilePath();
|
||||
new File(name)
|
||||
.openRead()
|
||||
.cast<List<int>>()
|
||||
.pipe(request.response)
|
||||
.catchError((e) {/* ignore */});
|
||||
});
|
||||
|
|
|
@ -67,6 +67,7 @@ void testResponseDone() {
|
|||
testServerRequest((server, request) {
|
||||
new File("__nonexistent_file_")
|
||||
.openRead()
|
||||
.cast<List<int>>()
|
||||
.pipe(request.response)
|
||||
.catchError((e) {
|
||||
server.close();
|
||||
|
@ -122,6 +123,7 @@ void testResponseAddStream() {
|
|||
testServerRequest((server, request) {
|
||||
new File("__nonexistent_file_")
|
||||
.openRead()
|
||||
.cast<List<int>>()
|
||||
.pipe(request.response)
|
||||
.catchError((e) {
|
||||
server.close();
|
||||
|
|
|
@ -69,6 +69,7 @@ void testEarlyClientClose() {
|
|||
String name = Platform.script.toFilePath();
|
||||
new File(name)
|
||||
.openRead()
|
||||
.cast<List<int>>()
|
||||
.pipe(request.response)
|
||||
.catchError((e) {/* ignore */});
|
||||
});
|
||||
|
|
|
@ -45,7 +45,7 @@ class PipeServerGame {
|
|||
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);
|
||||
|
|
|
@ -67,7 +67,7 @@ testFileToFilePipe1() {
|
|||
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 @@ testFileToFilePipe2() {
|
|||
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 @@ testFileToFilePipe3() {
|
|||
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();
|
||||
|
|
|
@ -120,6 +120,7 @@ Future<List<Map<String, dynamic>>> loadResults(String path) async {
|
|||
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) {
|
||||
|
|
|
@ -140,7 +140,7 @@ abstract class ClassGenerator {
|
|||
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;
|
||||
|
|
|
@ -47,7 +47,11 @@ void handleFile(HttpRequest request) {
|
|||
}
|
||||
|
||||
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();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue