https://github.com/medz/block
A flexible and efficient binary data block handling library for Dart.
https://github.com/medz/block
binary blob block data streams
Last synced: 4 months ago
JSON representation
A flexible and efficient binary data block handling library for Dart.
- Host: GitHub
- URL: https://github.com/medz/block
- Owner: medz
- License: mit
- Created: 2025-03-02T16:02:54.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-15T16:47:07.000Z (about 1 year ago)
- Last Synced: 2025-05-03T23:49:49.819Z (about 1 year ago)
- Topics: binary, blob, block, data, streams
- Language: Dart
- Homepage: https://pub.dev/packages/block
- Size: 205 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# block
[](https://pub.dev/packages/block)
[](https://github.com/medz/block/actions/workflows/test.yml)
`block` provides a Blob-style immutable binary data API for Dart.
## Design
- One minimal, Blob-compatible API surface.
- `web`: wraps native browser `Blob` via [`package:web`](https://pub.dev/packages/web).
- `io`: keeps small byte-only blocks in memory and lazily materializes larger/composed blocks to temp files (finalizer cleanup).
- `Block` parts are resolved lazily for `io` composed blocks: bytes are fetched/materialized on first read (`arrayBuffer`/`text`).
- `slice()` strategy on `io`:
- `<= 64KB`: copy to a new temp file
- `> 64KB`: share backing file with offset/length view
## Installation
```bash
dart pub add block
```
## API
```dart
import 'package:block/block.dart';
Future main() async {
final block = Block([
'hello ',
'world',
], type: 'text/plain');
final size = block.size;
final type = block.type;
final bytes = await block.arrayBuffer();
final text = await block.text();
final slice = block.slice(0, 5);
await for (final chunk in block.stream(chunkSize: 1024)) {
// handle chunk
}
}
```
Supported constructor part types:
- `String`
- `Uint8List`
- `ByteData`
- `Block`
Additional web-only part types:
- `web.Blob`
- `web.File`
## Breaking Reset in 1.0.0
This release intentionally removes the previous memory/cache/dedup framework APIs and keeps only the Blob-style core contract.
## License
BSD-style. See [LICENSE](LICENSE).