write method
Future<void>
write(
- String key,
- Uint8List bytes, [
- WriteOptions options = const WriteOptions()
override
Write bytes. Convenience wrapper over writeStream.
Implementation
@override
Future<void> write(
String key,
Uint8List bytes, [
WriteOptions options = const WriteOptions(),
]) async {
checkNotDisposed();
final previous = await _readManifest(key);
// No manifest can still mean orphaned chunks from a failed first
// write — they'd share generation 0 with this write, and a shorter
// object would leave their tail behind forever. Chunks are written
// sequentially, so any such orphans include chunk 0: one point
// lookup gates the sweep instead of a prefix scan on every fresh
// write.
if (previous == null && await _backing.exists(chunkKeyFor(key, 0, 0))) {
await _backing.deletePrefix('$key$generationPrefix');
}
final generation = (previous?.generation ?? -1) + 1;
final chunkCount = await _writeChunksFromBytes(key, generation, bytes);
await _writeManifest(
key,
generation: generation,
chunkCount: chunkCount,
totalSize: bytes.length,
contentType: options.contentType,
metadata: options.metadata,
);
await _deleteGeneration(key, previous);
}