Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Avoid eager copying with BytesBuilder (#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 b8850b3 commit 8193eac
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion 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 8193eac

Please sign in to comment.