Skip to content

Commit

Permalink
commons: Support streaming media from Stream<Uint8List> (#637)
Browse files Browse the repository at this point in the history
Fixes #636
  • Loading branch information
kevmoo authored Jul 3, 2024
1 parent f5dceee commit 1771405
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
3 changes: 2 additions & 1 deletion discoveryapis_commons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 1.0.7-wip
## 1.0.7

- Require Dart 3.4 or later.
- Support streaming media from `Stream<Uint8List>`.

## 1.0.6

Expand Down
4 changes: 1 addition & 3 deletions discoveryapis_commons/lib/src/multipart_media_uploader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ class MultipartMediaUploader {
Future.microtask(() async {
try {
await bodyController.addStream(
_uploadMedia.stream
.transform(_base64Encoder)
.transform(ascii.encoder),
_base64Encoder.bind(_uploadMedia.stream).transform(ascii.encoder),
);
bodyController.add(ascii.encode(bodyTail));
} catch (e, stack) {
Expand Down
2 changes: 1 addition & 1 deletion discoveryapis_commons/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: _discoveryapis_commons
version: 1.0.7-wip
version: 1.0.7
description: Library for use by client APIs generated from Discovery Documents.
repository: https://github.com/google/googleapis.dart/tree/master/discoveryapis_commons

Expand Down
7 changes: 4 additions & 3 deletions discoveryapis_commons/test/discoveryapis_commons_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'dart:async';
import 'dart:convert' hide Base64Encoder;
import 'dart:convert';
import 'dart:typed_data';

import 'package:_discoveryapis_commons/src/api_requester.dart';
import 'package:_discoveryapis_commons/src/multipart_media_uploader.dart';
Expand Down Expand Up @@ -405,10 +406,10 @@ void main() {
// Tests for media uploads

group('media-upload', () {
Stream<List<int>> streamFromByteArrays(List<List<int>> byteArrays) {
final controller = StreamController<List<int>>();
Stream<Uint8List> streamFromByteArrays(List<List<int>> byteArrays) {
final controller = StreamController<Uint8List>();
for (var array in byteArrays) {
controller.add(array);
controller.add(Uint8List.fromList(array));
}
controller.close();
return controller.stream;
Expand Down

0 comments on commit 1771405

Please sign in to comment.