read method
Read entire contents as bytes. Convenience wrapper over readStream.
Implementation
@override
Future<Uint8List> read(String key) async {
checkNotDisposed();
final raw = await _inner.read(key);
if (!_encryptor.isEncrypted(raw)) return raw;
final encKey = await _keyResolver?.resolveKey(key);
// The object is encrypted but no key resolved. Returning the ciphertext
// here would hand a caller raw encrypted bytes as if they were plaintext —
// a silent data-integrity hole. Fail loudly instead.
if (encKey == null) throw EncryptionKeyMissingError(key);
// A streaming write leaves a provisional header (originalSize == 0); the
// true size lives in the sidecar. decryptBytes trusts only the header, so
// for provisional headers decrypt via the streaming path — it reconciles
// the size from metadata the way readRange/readStream do. Skipping this
// returns an empty result for every streaming-written (or copied) object.
if (_encryptor.parseHeader(raw).originalSize > 0) {
return _encryptor.decryptBytes(raw, encKey);
}
final builder = BytesBuilder(copy: false);
await for (final chunk in readStream(key)) {
builder.add(chunk);
}
return builder.takeBytes();
}