From 3434b4cf59e01835d8bea5eb655bab5d530ca964 Mon Sep 17 00:00:00 2001 From: Jonathan Rezende Date: Wed, 9 Oct 2019 15:59:52 -0300 Subject: [PATCH] Uint8List update --- lib/src/parse_body.dart | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/src/parse_body.dart b/lib/src/parse_body.dart index 00dcf663..8fdb94b9 100644 --- a/lib/src/parse_body.dart +++ b/lib/src/parse_body.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'dart:io'; +import 'dart:typed_data'; import 'package:dart2_constant/convert.dart'; import 'package:http_parser/http_parser.dart'; @@ -32,11 +33,11 @@ Future parseBody(HttpRequest request, /// /// Use [storeOriginalBuffer] to add the original request bytes to the result. Future parseBodyFromStream( - Stream> data, MediaType contentType, Uri requestUri, + Stream data, MediaType contentType, Uri requestUri, {bool storeOriginalBuffer: false}) async { var result = new _BodyParseResultImpl(); - Future> getBytes() { + Future getBytes() { return data .fold(new BytesBuilder(copy: false), (a, b) => a..add(b)) .then((b) => b.takeBytes()); @@ -48,19 +49,20 @@ Future parseBodyFromStream( result.originalBuffer = bytes; return utf8.decode(bytes); }); - } else - return data.transform(utf8.decoder).join(); + } else { + return utf8.decoder.bind(data).join(); + } } try { if (contentType != null) { if (contentType.type == 'multipart' && contentType.parameters.containsKey('boundary')) { - Stream> stream; + Stream stream; if (storeOriginalBuffer) { var bytes = result.originalBuffer = await getBytes(); - var ctrl = new StreamController>() + var ctrl = new StreamController() ..add(bytes) ..close(); stream = ctrl.stream; @@ -68,9 +70,8 @@ Future parseBodyFromStream( stream = data; } - var parts = stream - .transform(new MimeMultipartTransformer( - contentType.parameters['boundary'])) + var parts = MimeMultipartTransformer( + contentType.parameters['boundary']).bind(stream) .map((part) => HttpMultipartFormData.parse(part, defaultEncoding: utf8));