Skip to content

Commit

Permalink
Avoid eager copying with BytesBuilder (dart-archive/async#186)
Browse files Browse the repository at this point in the history
The previous implementation of `collectBytes` would return a `Uint8List`
where the `lengthInBytes` and `buffer.lengthInBytes` matched. This
property isn't an intended guarantee, however since some callers may
rely on it for correct behavior it is safer to retain it. Use `copy: false`
so that the buffer used in `takeBytes` has the same length as the data.
  • Loading branch information
natebosch authored Jul 1, 2021
1 parent 3b6ab88 commit b1b2cfa
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkgs/async/lib/src/byte_collector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CancelableOperation<Uint8List> collectBytesCancelable(
/// so it can cancel the operation.
T _collectBytes<T>(Stream<List<int>> source,
T Function(StreamSubscription<List<int>>, Future<Uint8List>) result) {
var bytes = BytesBuilder();
var bytes = BytesBuilder(copy: false);
var completer = Completer<Uint8List>.sync();
var subscription =
source.listen(bytes.add, onError: completer.completeError, onDone: () {
Expand Down

0 comments on commit b1b2cfa

Please sign in to comment.