From 8193eac211905cf33ae1f514022fdbd843836be5 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Thu, 1 Jul 2021 14:13:30 -0700 Subject: [PATCH] Avoid eager copying with BytesBuilder (#186) 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. --- lib/src/byte_collector.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/byte_collector.dart b/lib/src/byte_collector.dart index a7a5435..0c93761 100644 --- a/lib/src/byte_collector.dart +++ b/lib/src/byte_collector.dart @@ -42,7 +42,7 @@ CancelableOperation collectBytesCancelable( /// so it can cancel the operation. T _collectBytes(Stream> source, T Function(StreamSubscription>, Future) result) { - var bytes = BytesBuilder(); + var bytes = BytesBuilder(copy: false); var completer = Completer.sync(); var subscription = source.listen(bytes.add, onError: completer.completeError, onDone: () {