From 9a0eea56ae421d2e2a0461ac06aff83c841881e2 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Tue, 1 Aug 2023 00:11:03 +0200 Subject: [PATCH] perf(dynamite_runtime): Increase response body reading speed --- .../dynamite/dynamite_runtime/lib/src/http_client.dart | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/dynamite/dynamite_runtime/lib/src/http_client.dart b/packages/dynamite/dynamite_runtime/lib/src/http_client.dart index b1b5c9b1..53141502 100644 --- a/packages/dynamite/dynamite_runtime/lib/src/http_client.dart +++ b/packages/dynamite/dynamite_runtime/lib/src/http_client.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:convert'; import 'dart:typed_data'; @@ -8,9 +9,11 @@ export 'package:cookie_jar/cookie_jar.dart'; extension DynamiteHttpClientResponseBody on HttpClientResponse { Future get bodyBytes async { - final data = await expand((final element) => element).toList(); + final buffer = BytesBuilder(); - return Uint8List.fromList(data); + await forEach(buffer.add); + + return buffer.toBytes(); } Future get body => transform(utf8.decoder).join();