From 8bf54bc7470b1af15909f465e97ea44a0b34a9b2 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Sun, 26 Nov 2023 10:52:24 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Check=20`Uint8List`=20befo?= =?UTF-8?q?re=20doing=20byte=20conversions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dio/lib/src/adapters/browser_adapter.dart | 4 +++- .../native_dio_adapter/lib/src/conversion_layer_adapter.dart | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dio/lib/src/adapters/browser_adapter.dart b/dio/lib/src/adapters/browser_adapter.dart index cae27d089..b388e42ec 100644 --- a/dio/lib/src/adapters/browser_adapter.dart +++ b/dio/lib/src/adapters/browser_adapter.dart @@ -278,7 +278,9 @@ class BrowserHttpClientAdapter implements HttpClientAdapter { } final completer = Completer(); final sink = ByteConversionSink.withCallback( - (bytes) => completer.complete(Uint8List.fromList(bytes)), + (bytes) => completer.complete( + bytes is Uint8List ? bytes : Uint8List.fromList(bytes), + ), ); requestStream.listen( sink.add, diff --git a/plugins/native_dio_adapter/lib/src/conversion_layer_adapter.dart b/plugins/native_dio_adapter/lib/src/conversion_layer_adapter.dart index 0e1904f0b..c153ae8fd 100644 --- a/plugins/native_dio_adapter/lib/src/conversion_layer_adapter.dart +++ b/plugins/native_dio_adapter/lib/src/conversion_layer_adapter.dart @@ -56,7 +56,9 @@ class ConversionLayerAdapter implements HttpClientAdapter { if (requestStream != null) { final completer = Completer(); final sink = ByteConversionSink.withCallback( - (bytes) => completer.complete(Uint8List.fromList(bytes)), + (bytes) => completer.complete( + bytes is Uint8List ? bytes : Uint8List.fromList(bytes), + ), ); requestStream.listen( sink.add,