copy method
Copy an object, including its metadata.
Local: filesystem-level copy. Encrypted: re-encrypts when the
destination resolves to a different encryption key. Remote: server-
side CopyObject. The metadata travels with the body.
Implementation
@override
Future<void> copy(String sourceKey, String destKey) async {
checkNotDisposed();
final manifest = await _readManifest(sourceKey);
if (manifest == null) throw FileNotFoundError(sourceKey);
final destPrevious = await _readManifest(destKey);
final destGeneration = (destPrevious?.generation ?? -1) + 1;
for (var i = 0; i < manifest.chunkCount; i++) {
final chunk = await _readChunk(sourceKey, manifest.generation, i);
await _putChunk(destKey, destGeneration, i, chunk);
}
await _writeManifest(
destKey,
generation: destGeneration,
chunkCount: manifest.chunkCount,
totalSize: manifest.totalSize,
contentType: manifest.contentType,
metadata: manifest.metadata,
);
await _deleteGeneration(destKey, destPrevious);
}