copy method

  1. @override
Future<bool> copy(
  1. String from,
  2. String to
)

Copy a file to a new location.

Implementation

@override
Future<bool> copy(String from, String to) {
  return _write(() async {
    final source = await bucket.get(_objectKey(from));
    if (source == null) return false;

    // The storage_fs contract does not carry a stream length. Buffering here
    // gives R2 a fixed-size upload and avoids an unknown-length Worker stream.
    final bytes = await source.readAsBytes();
    final copied = await bucket.put(
      _objectKey(to),
      bytes,
      options: CloudflareR2PutOptions(
        httpMetadata: source.httpMetadata,
        customMetadata: source.customMetadata,
      ),
    );
    return copied != null;
  });
}