From c60ad4edbf1705ad60506fc4d9fa1ce0d7e828f6 Mon Sep 17 00:00:00 2001 From: Nazar Vovk Date: Fri, 2 Jun 2023 10:36:40 +0300 Subject: [PATCH] [native_dio_adapter] Fix `onReceiveProgress` callback. (#1841) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Part of #1835 ### New Pull Request Checklist - [x] I have read the [Documentation](https://pub.dev/documentation/dio/latest/) - [x] I have searched for a similar pull request in the [project](https://github.com/cfug/dio/pulls) and found none - [x] I have updated this branch with the latest `main` branch to avoid conflicts (via merge from master or rebase) - [x] I have added the required tests to prove the fix/feature I'm adding - [ ] I have updated the documentation (if necessary) - [ ] I have run the tests without failures - [x] I have updated the `CHANGELOG.md` in the corresponding package ### Additional context and info (if any) --------- Co-authored-by: Jonas Uekötter --- plugins/native_dio_adapter/CHANGELOG.md | 1 + .../lib/src/conversion_layer_adapter.dart | 2 +- .../test/conversion_layer_adapter_test.dart | 24 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/plugins/native_dio_adapter/CHANGELOG.md b/plugins/native_dio_adapter/CHANGELOG.md index 1a678d84e..ccd405491 100644 --- a/plugins/native_dio_adapter/CHANGELOG.md +++ b/plugins/native_dio_adapter/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Replace `DioError` with `DioException`. +- Fix `onReceiveProgress` callback. ## 0.1.0 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 df081f26b..a035f2c45 100644 --- a/plugins/native_dio_adapter/lib/src/conversion_layer_adapter.dart +++ b/plugins/native_dio_adapter/lib/src/conversion_layer_adapter.dart @@ -70,7 +70,7 @@ extension on StreamedResponse { ResponseBody toDioResponseBody() { final dioHeaders = headers.entries.map((e) => MapEntry(e.key, [e.value])); return ResponseBody( - Stream.fromFuture(stream.toBytes()), + stream.cast(), statusCode, headers: Map.fromEntries(dioHeaders), isRedirect: isRedirect, diff --git a/plugins/native_dio_adapter/test/conversion_layer_adapter_test.dart b/plugins/native_dio_adapter/test/conversion_layer_adapter_test.dart index a57bff61e..5de82452f 100644 --- a/plugins/native_dio_adapter/test/conversion_layer_adapter_test.dart +++ b/plugins/native_dio_adapter/test/conversion_layer_adapter_test.dart @@ -1,3 +1,5 @@ +import 'dart:typed_data'; + import 'package:dio/dio.dart'; import 'package:http/http.dart'; import 'package:native_dio_adapter/src/conversion_layer_adapter.dart'; @@ -36,4 +38,26 @@ void main() { expect(mock.request?.headers, {'foo': 'bar'}); }); + + test('download stream', () async { + final mock = ClientMock() + ..response = StreamedResponse( + Stream.fromIterable([ + Uint8List.fromList([10, 1]), + Uint8List.fromList([1, 4]), + Uint8List.fromList([5, 1]), + Uint8List.fromList([1, 1]), + Uint8List.fromList([2, 4]), + ]), + 200); + final cla = ConversionLayerAdapter(mock); + + final resp = await cla.fetch( + RequestOptions(path: ''), + null, + null, + ); + + expect(await resp.stream.length, 5); + }); }