From a08f62415e354f08dfcc9f0b5c68971123bc8902 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Thu, 22 Jun 2023 22:17:33 +0200 Subject: [PATCH] dynamite_runtime: more efficient decoding of responses --- .../dynamite/dynamite_runtime/lib/src/http_client.dart | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/dynamite/dynamite_runtime/lib/src/http_client.dart b/packages/dynamite/dynamite_runtime/lib/src/http_client.dart index 47877528..6d873624 100644 --- a/packages/dynamite/dynamite_runtime/lib/src/http_client.dart +++ b/packages/dynamite/dynamite_runtime/lib/src/http_client.dart @@ -8,14 +8,12 @@ export 'package:cookie_jar/cookie_jar.dart'; extension DynamiteHttpClientResponseBody on HttpClientResponse { Future get bodyBytes async { - final chunks = await toList(); - if (chunks.isEmpty) { - return Uint8List(0); - } - return Uint8List.fromList(chunks.reduce((final value, final element) => [...value, ...element])); + final data = await expand((final element) => element).toList(); + + return Uint8List.fromList(data); } - Future get body async => utf8.decode(await bodyBytes); + Future get body => transform(utf8.decoder).join(); } class DynamiteResponse {