CloudStorage

interface CloudStorage(source)

Layer 1: filesystem-style access to the user's own cloud.

Paths are relative and /-separated (notes/2026-09.json). iCloud stores them as nested files; Google Drive app-data is flat, so the path string is used verbatim as the file name. Every write is complete-or-absent from a reader's point of view. All functions are safe to call from any dispatcher; they never block the main thread.

Failures throw CloudStorageException. remoteId parameters are optional hints that save a list round trip on Drive; iCloud ignores them.

Inheritors

GoogleDriveStorage
CloudKitStorage
ICloudStorage

Properties

Link copied to clipboard
abstract val provider: CloudProvider

Functions

Link copied to clipboard
abstract suspend fun availability(): CloudAvailability

Cheap. Never touches the network.

Link copied to clipboard
abstract suspend fun delete(path: String, remoteId: String? = null)

No-op when already absent.

Link copied to clipboard
abstract suspend fun downloadFile(path: String, toLocalPath: String, remoteId: String? = null)

Downloads into toLocalPath, replacing it. Throws CloudError.NotFound when absent.

Link copied to clipboard
abstract suspend fun exists(path: String): Boolean
Link copied to clipboard
abstract suspend fun identityKey(): String?

Stable per (device, cloud account) when the platform can tell, so a sync engine can detect an account switch. Null on Drive, where the engine keys identity off the marker file's id.

Link copied to clipboard
abstract suspend fun list(): List<RemoteFile>

Every file, deduplicated by path (newest wins).

Link copied to clipboard
open suspend fun prefetch(paths: List<String>)

Starts downloading every not-yet-local file in paths at once, without waiting. iCloud only; Drive has nothing to prefetch. Never throws. Call it before a restore so files download in parallel instead of one at a time.

Link copied to clipboard
abstract suspend fun readBytes(path: String, remoteId: String? = null): ByteArray?

Whole contents, or null when absent. Forces an iCloud download first.

Link copied to clipboard
abstract suspend fun writeBytes(path: String, bytes: ByteArray, mimeType: String, existingRemoteId: String? = null): String?

Create or replace from memory. Returns the remote id on Drive, null on iCloud.

Link copied to clipboard
abstract suspend fun writeFile(path: String, localPath: String, mimeType: String, existingRemoteId: String? = null): String?

Create or replace from a local file. Returns the remote id on Drive, null on iCloud.