block
block provides a Blob-style immutable binary data API for Dart.
Design
- One minimal, Blob-compatible API surface.
web: wraps native browserBlobviapackage:web.io: stores block data in temp files and uses finalizers for cleanup.Blockparts are resolved lazily: bytes are fetched/materialized on first read (arrayBuffer/text/stream).slice()strategy onio:<= 64KB: copy to a new temp file> 64KB: share backing file with offset/length view
Installation
dart pub add block
API
import 'package:block/block.dart';
Future<void> 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:
StringUint8ListByteDataBlock
Additional web-only part types:
web.Blobweb.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.