Skip to content

Commit

Permalink
[native_dio_adapter] Fix onReceiveProgress callback. (cfug#1841)
Browse files Browse the repository at this point in the history
<!-- Write down your pull request descriptions. -->

Part of cfug#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)

<!-- Provide more context and info about the PR. -->

---------

Co-authored-by: Jonas Uekötter <[email protected]>
  • Loading branch information
Vovcharaa and ueman authored Jun 2, 2023
1 parent 1883bab commit c60ad4e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions plugins/native_dio_adapter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Replace `DioError` with `DioException`.
- Fix `onReceiveProgress` callback.

## 0.1.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uint8List>(),
statusCode,
headers: Map.fromEntries(dioHeaders),
isRedirect: isRedirect,
Expand Down
24 changes: 24 additions & 0 deletions plugins/native_dio_adapter/test/conversion_layer_adapter_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -36,4 +38,26 @@ void main() {

expect(mock.request?.headers, {'foo': 'bar'});
});

test('download stream', () async {
final mock = ClientMock()
..response = StreamedResponse(
Stream.fromIterable(<Uint8List>[
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);
});
}

0 comments on commit c60ad4e

Please sign in to comment.