aboutsummaryrefslogtreecommitdiff
path: root/lib/services/common/output_buffer.dart
diff options
context:
space:
mode:
authormirror <mirror@localhost>2026-11-22 08:41:00 +0900
committermirror <mirror@localhost>2026-11-22 08:41:00 +0900
commit449d8b74bd6d9dae98a07254cdfad677b920e7b0 (patch)
treec131c3528c4d517f56e19b854a7453fedb097d40 /lib/services/common/output_buffer.dart
downloadaves-src-master.tar.gz
aves-src-master.zip
snapshot of aves v1.13.12 (secrets removed: android/app/google-services.json)HEADv1.13.12master
Diffstat (limited to 'lib/services/common/output_buffer.dart')
-rw-r--r--lib/services/common/output_buffer.dart36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/services/common/output_buffer.dart b/lib/services/common/output_buffer.dart
new file mode 100644
index 0000000..e64f046
--- /dev/null
+++ b/lib/services/common/output_buffer.dart
@@ -0,0 +1,36 @@
+import 'dart:convert';
+import 'dart:typed_data';
+
+// adapted from Flutter `_OutputBuffer` in `/foundation/consolidate_response.dart`
+class OutputBuffer extends ByteConversionSinkBase {
+ List<List<int>>? _chunks = <List<int>>[];
+ int _contentLength = 0;
+ Uint8List? _bytes;
+
+ @override
+ void add(List<int> chunk) {
+ assert(_bytes == null);
+ _chunks!.add(chunk);
+ _contentLength += chunk.length;
+ }
+
+ @override
+ void close() {
+ if (_bytes != null) {
+ // We've already been closed; this is a no-op
+ return;
+ }
+ _bytes = Uint8List(_contentLength);
+ int offset = 0;
+ for (final List<int> chunk in _chunks!) {
+ _bytes!.setRange(offset, offset + chunk.length, chunk);
+ offset += chunk.length;
+ }
+ _chunks = null;
+ }
+
+ Uint8List get bytes {
+ assert(_bytes != null);
+ return _bytes!;
+ }
+}