From 4c2cbb56f69e9d2ba1ccf4fbed7a64f4e78c02a0 Mon Sep 17 00:00:00 2001 From: Moritz Date: Wed, 25 Mar 2026 11:06:59 +0100 Subject: [PATCH 1/2] Use BytesBuilder --- CHANGELOG.md | 4 ++++ lib/src/gzip_io.dart | 8 ++++---- lib/src/gzip_mock.dart | 4 ++-- lib/src/gzip_web.dart | 19 +++++++++++-------- pubspec.yaml | 6 +++--- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10ba0bf..d7e0bd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.0 + +- Return `Uint8List` and use `BytesBuilder` on the web [#3](https://github.com/mosuem/gzip/issues/3). + ## 1.0.0 - Upgrade SDK version and make WASM-ready. diff --git a/lib/src/gzip_io.dart b/lib/src/gzip_io.dart index a374d33..b06238b 100644 --- a/lib/src/gzip_io.dart +++ b/lib/src/gzip_io.dart @@ -6,9 +6,9 @@ import 'dart:io'; import 'dart:typed_data'; class GZip { - Future> compress(Uint8List data) async => - gzip.encoder.convert(data); + Future compress(Uint8List data) async => + gzip.encoder.convert(data) as Uint8List; - Future> decompress(Uint8List data) async => - gzip.decoder.convert(data); + Future decompress(Uint8List data) async => + gzip.decoder.convert(data) as Uint8List; } diff --git a/lib/src/gzip_mock.dart b/lib/src/gzip_mock.dart index 314138c..0cf2fec 100644 --- a/lib/src/gzip_mock.dart +++ b/lib/src/gzip_mock.dart @@ -11,10 +11,10 @@ import 'dart:typed_data'; /// browsers. class GZip { /// Compress the [data] using gzip compression. - Future> compress(Uint8List data) async => + Future compress(Uint8List data) async => throw UnimplementedError(); /// Decode the gzip-compressed [data]. - Future> decompress(Uint8List data) async => + Future decompress(Uint8List data) async => throw UnimplementedError(); } diff --git a/lib/src/gzip_web.dart b/lib/src/gzip_web.dart index 250dad4..43a9bad 100644 --- a/lib/src/gzip_web.dart +++ b/lib/src/gzip_web.dart @@ -8,7 +8,7 @@ import 'dart:typed_data'; import 'package:web/web.dart'; class GZip { - Future> compress(Uint8List data) async { + Future compress(Uint8List data) async { final compressionStream = CompressionStream('gzip'); final reader = _blob(data) @@ -24,7 +24,7 @@ class GZip { return await _readUntilDone(reader); } - Future> decompress(Uint8List data) async { + Future decompress(Uint8List data) async { final decompressionStream = DecompressionStream('gzip'); final reader = _blob(data) @@ -40,18 +40,21 @@ class GZip { return await _readUntilDone(reader); } - Future> _readUntilDone(ReadableStreamDefaultReader reader) async { - final values = []; + Future _readUntilDone(ReadableStreamDefaultReader reader) async { + final builder = BytesBuilder(copy: false); + var isDone = false; while (!isDone) { final readChunk = await reader.read().toDart; - if (readChunk.value != null) { - final value = readChunk.value as JSUint8Array; - values.addAll(value.toDart); + final uint8Array = readChunk.value as JSUint8Array?; + + if (uint8Array != null) { + builder.add(uint8Array.toDart); } isDone = readChunk.done; } - return values; + + return builder.takeBytes(); } Blob _blob(Uint8List data) => diff --git a/pubspec.yaml b/pubspec.yaml index 3ff80e2..1eb6067 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,14 +1,14 @@ name: gzip description: A lightweight package for gzip compression. -version: 1.0.0 +version: 1.1.0 repository: https://github.com/mosuem/gzip environment: sdk: ^3.9.0 dependencies: - web: ^1.1.0 + web: ^1.1.1 dev_dependencies: dart_flutter_team_lints: ^3.5.2 - test: ^1.24.0 + test: ^1.31.0 From 4af410e3814c030b269e2b9553f9d57be36d0cb8 Mon Sep 17 00:00:00 2001 From: Moritz Date: Wed, 25 Mar 2026 11:08:49 +0100 Subject: [PATCH 2/2] add desc --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7e0bd5..415b490 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## 1.1.0 -- Return `Uint8List` and use `BytesBuilder` on the web [#3](https://github.com/mosuem/gzip/issues/3). +- Return `Uint8List` and use `BytesBuilder` on the web, fixing [#3](https://github.com/mosuem/gzip/issues/3). ## 1.0.0