From 8fd756e97e5737e4cf9ec0616b5ded0c7ec5b7ba Mon Sep 17 00:00:00 2001 From: gmpassos Date: Thu, 22 Jan 2026 18:04:23 -0300 Subject: [PATCH] v1.9.24 - `GZipSink`: - Added override for `addSlice` to handle partial chunk addition and update `_inputLength` accordingly. - Optimized `addSlice` to call `_gzipSink.close()` when `isLast` is true and full chunk is added. - `BytesSink`: - Updated `addSlice` to use new `addPart` method for partial chunk addition. - `BytesBuffer`: - Added `addPart` method to add a slice of bytes from a given offset and length, resizing buffer if needed. - Refactored `add` method to delegate to `addPart`. - Improved buffer range setting to support offset and length parameters in `addPart`. --- CHANGELOG.md | 14 +++++++++++++ lib/src/bones_api_base.dart | 2 +- lib/src/bones_api_utils_sink.dart | 33 +++++++++++++++++++++++-------- pubspec.yaml | 2 +- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24405a7..013187b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## 1.9.24 + +- `GZipSink`: + - Added override for `addSlice` to handle partial chunk addition and update `_inputLength` accordingly. + - Optimized `addSlice` to call `_gzipSink.close()` when `isLast` is true and full chunk is added. + +- `BytesSink`: + - Updated `addSlice` to use new `addPart` method for partial chunk addition. + +- `BytesBuffer`: + - Added `addPart` method to add a slice of bytes from a given offset and length, resizing buffer if needed. + - Refactored `add` method to delegate to `addPart`. + - Improved buffer range setting to support offset and length parameters in `addPart`. + ## 1.9.23 - `DBPostgreSQLAdapter`: diff --git a/lib/src/bones_api_base.dart b/lib/src/bones_api_base.dart index f2049bd..073a95e 100644 --- a/lib/src/bones_api_base.dart +++ b/lib/src/bones_api_base.dart @@ -48,7 +48,7 @@ typedef APILogger = /// Bones API Library class. class BonesAPI { // ignore: constant_identifier_names - static const String VERSION = '1.9.23'; + static const String VERSION = '1.9.24'; static bool _boot = false; diff --git a/lib/src/bones_api_utils_sink.dart b/lib/src/bones_api_utils_sink.dart index 04aae42..5aea1a7 100644 --- a/lib/src/bones_api_utils_sink.dart +++ b/lib/src/bones_api_utils_sink.dart @@ -107,6 +107,20 @@ class GZipSink extends ByteConversionSinkBuffered { _gzipSink.add(chunk); } + @override + void addSlice(List chunk, int start, int end, bool isLast) { + final chunkLength = chunk.length; + if (start != 0 || end != chunkLength) { + var length = end - start; + _inputLength += length; + _gzipSink.addSlice(chunk, start, end, isLast); + } else { + _inputLength += chunkLength; + _gzipSink.add(chunk); + if (isLast) _gzipSink.close(); + } + } + @override void close() => _gzipSink.close(); @@ -135,10 +149,8 @@ class BytesSink extends BytesBuffer implements ByteConversionSinkBuffered { @override void addSlice(List chunk, int start, int end, bool isLast) { - if (start != 0 || end != chunk.length) { - chunk = chunk.sublist(start, end); - } - add(chunk); + var length = end - start; + addPart(chunk, start, length); if (isLast) close(); } } @@ -146,7 +158,9 @@ class BytesSink extends BytesBuffer implements ByteConversionSinkBuffered { /// Base class for sinks with tracking and reset support. abstract class ByteConversionSinkBuffered extends ByteConversionSink { int get length; + int get capacity; + int get inputLength; Uint8List toBytes({bool copy = false}); @@ -175,13 +189,16 @@ class BytesBuffer { /// Adds [bytes] to buffer, resizing if needed. void add(List bytes) { - final chunkLength = bytes.length; - final requiredLength = _length + chunkLength; + addPart(bytes, 0, bytes.length); + } + + void addPart(List bytes, int offset, int length) { + final requiredLength = _length + length; if (requiredLength > _buffer.length) { _increaseCapacity(requiredLength); } - _buffer.setRange(_length, _length + chunkLength, bytes); - _length += chunkLength; + _buffer.setRange(_length, _length + length, bytes, offset); + _length += length; } void _increaseCapacity(int requiredLength) { diff --git a/pubspec.yaml b/pubspec.yaml index 19b1218..f7e632a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: bones_api description: Bones_API - A powerful API backend framework for Dart. It comes with a built-in HTTP Server, route handler, entity handler, SQL translator, and DB adapters. -version: 1.9.23 +version: 1.9.24 homepage: https://github.com/Colossus-Services/bones_api environment: