Merge pull request #237 from tvolkert/bytes

Prepare for upcoming Dart SDK breaking change
This commit is contained in:
Tobe Osakwe 2019-07-08 20:16:09 -04:00 committed by GitHub
commit 4be830e17a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 10 deletions

View file

@ -1,3 +1,7 @@
# 2.0.4
* Prepare for Dart SDK change to `Stream<List<int>>` that are now
`Stream<Uint8List>`.
# 2.0.3 # 2.0.3
* Patch up a bug caused by an upstream change to Dart's stream semantics. * Patch up a bug caused by an upstream change to Dart's stream semantics.
See more: https://github.com/angel-dart/angel/issues/106#issuecomment-499564485 See more: https://github.com/angel-dart/angel/issues/106#issuecomment-499564485

View file

@ -234,7 +234,7 @@ abstract class RequestContext<RawRequest> {
_uploadedFiles = []; _uploadedFiles = [];
var parsed = _bodyObject = var parsed = _bodyObject =
await body.transform(encoding.decoder).join().then(json.decode); await encoding.decoder.bind(body).join().then(json.decode);
if (parsed is Map) { if (parsed is Map) {
_bodyFields = Map<String, dynamic>.from(parsed); _bodyFields = Map<String, dynamic>.from(parsed);
@ -244,8 +244,8 @@ abstract class RequestContext<RawRequest> {
} else if (contentType.type == 'application' && } else if (contentType.type == 'application' &&
contentType.subtype == 'x-www-form-urlencoded') { contentType.subtype == 'x-www-form-urlencoded') {
_uploadedFiles = []; _uploadedFiles = [];
var parsed = await body var parsed = await encoding.decoder
.transform(encoding.decoder) .bind(body)
.join() .join()
.then((s) => Uri.splitQueryString(s, encoding: encoding)); .then((s) => Uri.splitQueryString(s, encoding: encoding));
_bodyFields = Map<String, dynamic>.from(parsed); _bodyFields = Map<String, dynamic>.from(parsed);
@ -254,7 +254,7 @@ abstract class RequestContext<RawRequest> {
contentType.parameters.containsKey('boundary')) { contentType.parameters.containsKey('boundary')) {
var boundary = contentType.parameters['boundary']; var boundary = contentType.parameters['boundary'];
var transformer = MimeMultipartTransformer(boundary); var transformer = MimeMultipartTransformer(boundary);
var parts = body.transform(transformer).map((part) => var parts = transformer.bind(body).map((part) =>
HttpMultipartFormData.parse(part, defaultEncoding: encoding)); HttpMultipartFormData.parse(part, defaultEncoding: encoding));
_bodyFields = {}; _bodyFields = {};
_uploadedFiles = []; _uploadedFiles = [];
@ -334,6 +334,6 @@ class UploadedFile {
/// Reads the contents of the file as [String], using the given [encoding]. /// Reads the contents of the file as [String], using the given [encoding].
Future<String> readAsString({Encoding encoding = utf8}) { Future<String> readAsString({Encoding encoding = utf8}) {
return data.transform(encoding.decoder).join(); return encoding.decoder.bind(data).join();
} }
} }

View file

@ -4,6 +4,7 @@ import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:convert' as c show json; import 'dart:convert' as c show json;
import 'dart:io' show BytesBuilder, Cookie; import 'dart:io' show BytesBuilder, Cookie;
import 'dart:typed_data';
import 'package:angel_route/angel_route.dart'; import 'package:angel_route/angel_route.dart';
import 'package:file/file.dart'; import 'package:file/file.dart';
@ -148,7 +149,7 @@ abstract class ResponseContext<RawResponse>
headers['content-length'] = file.lengthSync().toString(); headers['content-length'] = file.lengthSync().toString();
if (!isBuffered) { if (!isBuffered) {
await file.openRead().pipe(this); await file.openRead().cast<List<int>>().pipe(this);
} else { } else {
buffer.add(file.readAsBytesSync()); buffer.add(file.readAsBytesSync());
await close(); await close();
@ -320,7 +321,9 @@ abstract class ResponseContext<RawResponse>
: MediaType.parse(mimeType); : MediaType.parse(mimeType);
if (correspondingRequest.method != 'HEAD') { if (correspondingRequest.method != 'HEAD') {
return this.addStream(file.openRead()).then((_) => this.close()); return this
.addStream(file.openRead().cast<List<int>>())
.then((_) => this.close());
} }
} }
@ -432,12 +435,12 @@ class _LockableBytesBuilderImpl implements LockableBytesBuilder {
int get length => _buf.length; int get length => _buf.length;
@override @override
List<int> takeBytes() { Uint8List takeBytes() {
return _buf.takeBytes(); return _buf.takeBytes();
} }
@override @override
List<int> toBytes() { Uint8List toBytes() {
return _buf.toBytes(); return _buf.toBytes();
} }
} }

View file

@ -1,5 +1,5 @@
name: angel_framework name: angel_framework
version: 2.0.3 version: 2.0.4
description: A high-powered HTTP server with dependency injection, routing and much more. description: A high-powered HTTP server with dependency injection, routing and much more.
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_framework homepage: https://github.com/angel-dart/angel_framework