Prepare for upcoming change to File.openRead()

An upcoming change to the Dart SDK will change the signature
of `File.openRead()` from returning `Stream<List<int>>` to
returning `Stream<Uint8List>`.

This forwards-compatible change prepares for that SDK breaking
change by casting the Stream to `List<int>` before transforming
it.

https://github.com/dart-lang/sdk/issues/36900
This commit is contained in:
Todd Volkert 2019-06-25 12:59:00 -07:00
parent cc23c2a97e
commit e3c291d913
2 changed files with 9 additions and 4 deletions

View file

@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:typed_data';
import 'package:angel_framework/angel_framework.dart';
import 'package:file/file.dart';
import 'package:http_parser/http_parser.dart';
@ -284,7 +285,7 @@ class VirtualDirectory {
statusCode: 416, message: '`Range` header may not be empty.');
} else if (header.items.length == 1) {
var item = header.items[0];
Stream<List<int>> stream;
Stream<Uint8List> stream;
int len = 0, total = totalFileSize;
if (item.start == -1) {
@ -311,7 +312,7 @@ class VirtualDirectory {
res.statusCode = 206;
res.headers['content-length'] = len.toString();
res.headers['content-range'] = 'bytes ' + item.toContentRange(total);
await stream.pipe(res);
await stream.cast<List<int>>().pipe(res);
return false;
} else {
var transformer = RangeHeaderTransformer(
@ -324,7 +325,11 @@ class VirtualDirectory {
transformer.computeContentLength(totalFileSize).toString();
res.contentType = MediaType(
'multipart', 'byteranges', {'boundary': transformer.boundary});
await file.openRead().transform(transformer).pipe(res);
await file
.openRead()
.cast<List<int>>()
.transform(transformer)
.pipe(res);
return false;
}
}

View file

@ -4,7 +4,7 @@ environment:
sdk: ">=2.0.0 <3.0.0"
homepage: https://github.com/angel-dart/static
author: Tobe O <thosakwe@gmail.com>
version: 2.1.3+1
version: 2.1.3+2
dependencies:
angel_framework: ^2.0.0-rc.0
convert: ^2.0.0