Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`:
Expand Down
2 changes: 1 addition & 1 deletion lib/src/bones_api_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
33 changes: 25 additions & 8 deletions lib/src/bones_api_utils_sink.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ class GZipSink extends ByteConversionSinkBuffered {
_gzipSink.add(chunk);
}

@override
void addSlice(List<int> 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();

Expand Down Expand Up @@ -135,18 +149,18 @@ class BytesSink extends BytesBuffer implements ByteConversionSinkBuffered {

@override
void addSlice(List<int> 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();
}
}

/// 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});
Expand Down Expand Up @@ -175,13 +189,16 @@ class BytesBuffer {

/// Adds [bytes] to buffer, resizing if needed.
void add(List<int> bytes) {
final chunkLength = bytes.length;
final requiredLength = _length + chunkLength;
addPart(bytes, 0, bytes.length);
}

void addPart(List<int> 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) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down