UNPKG

react-native-cloud-storage

Version:

☁️ Save to & read from iCloud and Google Drive using React Native

280 lines 16.2 kB
import { CloudStorageProvider, CloudStorageScope, type CloudStorageFileStat, type CloudStorageProviderOptions } from './types/main'; export default class RNCloudStorage { private static defaultInstance; private provider; private cloudAvailabilityListeners; /** * Creates a new RNCloudStorage instance for the given provider. * @param provider The provider to create the instance for. Defaults to the default provider for the current platform. */ constructor(provider?: CloudStorageProvider, options?: CloudStorageProviderOptions[keyof CloudStorageProviderOptions]); private get nativeStorage(); /** * Gets the default CloudStorageProvider for the current platform. * @returns The default CloudStorageProvider. */ static getDefaultProvider(): CloudStorageProvider; /** * Gets the list of supported CloudStorageProviders on the current platform. * @returns An array of supported CloudStorageProviders. */ static getSupportedProviders(): CloudStorageProvider[]; /** * Gets the current CloudStorageProvider. * @returns The current CloudStorageProvider. */ getProvider(): CloudStorageProvider; /** * Sets the current CloudStorageProvider. * @param provider The provider to set. */ setProvider(provider: CloudStorageProvider): void; /** * Gets the current options for the current provider. * @returns The current options for the current provider. */ getProviderOptions(): CloudStorageProviderOptions[keyof CloudStorageProviderOptions]; /** * Sets the options for the current provider. * @param options The options to set for the provider. */ setProviderOptions(options: CloudStorageProviderOptions[keyof CloudStorageProviderOptions]): void; subscribeToCloudAvailability(listener: (available: boolean) => void): void; unsubscribeFromCloudAvailability(listener: (available: boolean) => void): void; /** * Tests whether or not the cloud storage is available. Always returns true for Google Drive. iCloud may be * unavailable right after app launch or if the user is not logged in. * @returns A promise that resolves to true if the cloud storage is available, false otherwise. */ isCloudAvailable(): Promise<boolean>; /** * Appends the data to the file at the given path, creating the file if it doesn't exist. * @param path The file to append to. * @param data The data to append. * @param scope The directory scope the path is in. Defaults to the default scope set for the current provider. * @returns A promise that resolves when the data has been appended. */ appendFile(path: string, data: string, scope?: CloudStorageScope): Promise<void>; /** * Tests whether or not the file at the given path exists. * @param path The path to test. * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider. * @returns A promise that resolves to true if the path exists, false otherwise. */ exists(path: string, scope?: CloudStorageScope): Promise<boolean>; /** * Writes to the file at the given path, creating it if it doesn't exist or overwriting it if it does. * @param path The file to write to. * @param data The data to write. * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider. * @returns A promise that resolves when the file has been written. */ writeFile(path: string, data: string, scope?: CloudStorageScope): Promise<void>; /** * Creates a new directory at the given path. * @param path The directory to create. * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider. * @returns A promise that resolves when the directory has been created. */ mkdir(path: string, scope?: CloudStorageScope): Promise<void>; /** * Lists the contents of the directory at the given path. * @param path The directory to list. * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider. * @returns A promise that resolves to an array of file names, excluding '.' and '..'. */ readdir(path: string, scope?: CloudStorageScope): Promise<string[]>; /** * Reads the contents of the file at the given path. * @param path The file to read. * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider. * @returns A promise that resolves to the contents of the file. */ readFile(path: string, scope?: CloudStorageScope): Promise<string>; /** * Triggers synchronization for the file at the given path. Does not have any effect on Google Drive. * @param path The file to trigger synchronization for. * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider. * @returns A promise that resolves once the synchronization has been triggered. */ triggerSync(path: string, scope?: CloudStorageScope): Promise<void>; /** * Uploads the file at the given local path to the given path, creating it if it doesn't exist or overwriting it if it does. * @param remotePath The remote path to upload to. * @param localPath The local path of the file to upload. * @param options The options for the upload. Must contain a `mimeType` property. * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider. * @returns A promise that resolves when the file has been uploaded. */ uploadFile(remotePath: string, localPath: string, options: { mimeType: string; }, scope?: CloudStorageScope): Promise<void>; /** * Triggers synchronization for the file at the given path. Does not have any effect on Google Drive. * @param path The file to trigger synchronization for. * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider. * @returns A promise that resolves once the synchronization has been triggered. * @deprecated Use `triggerSync` instead. */ downloadFile(path: string, scope?: CloudStorageScope): Promise<void>; /** * Downloads the cloud file at the given remote path to the given local path. * @param remotePath The remote path of the file to download from the cloud. * @param localPath The local path to download the cloud file to. * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider. */ downloadFile(remotePath: string, localPath: string, scope?: CloudStorageScope): Promise<void>; /** * Deletes the file at the given path. * @param path The file to delete. * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider. * @returns A promise that resolves when the file has been deleted. */ unlink(path: string, scope?: CloudStorageScope): Promise<void>; /** * Deletes the directory at the given path. * @param path The directory to delete. * @param options Options for the delete operation. Defaults to { recursive: false }. * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider. * @returns A promise that resolves when the directory has been deleted. */ rmdir(path: string, options?: { recursive?: boolean; }, scope?: CloudStorageScope): Promise<void>; /** * Gets the size, creation time, and modification time of the file at the given path. * @param path The file to stat. * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider. * @returns A promise that resolves to the CloudStorageFileStat object. */ stat(path: string, scope?: CloudStorageScope): Promise<CloudStorageFileStat>; static getDefaultInstance(): RNCloudStorage; /** * Gets the current provider of the default static instance. * @returns The current provider of the default static instance. */ static getProvider(): CloudStorageProvider; /** * Sets the provider of the default static instance. * @param provider The provider to set. */ static setProvider(provider: CloudStorageProvider): void; /** * Gets the current options for the provider of the default static instance. * @returns The current options for the provider of the default static instance. */ static getProviderOptions(): CloudStorageProviderOptions[keyof CloudStorageProviderOptions]; /** * Sets the options for the provider of the default static instance. * @param options The options to set for the provider of the default static instance. */ static setProviderOptions(options: CloudStorageProviderOptions[keyof CloudStorageProviderOptions]): void; /** * Tests whether or not the file at the given path exists in the provider of the default static instance. * @param path The path to test. * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider. * @returns A promise that resolves to true if the path exists, false otherwise. */ static exists(path: string, scope?: CloudStorageScope): Promise<boolean>; /** * Tests whether or not the cloud storage is available for the provider of the default static instance. Always returns true for Google Drive. iCloud may be * unavailable right after app launch or if the user is not logged in. * @returns A promise that resolves to true if the cloud storage is available, false otherwise. */ static isCloudAvailable(): Promise<boolean>; /** * Appends the data to the file at the given path in the provider of the default static instance, creating the file if it doesn't exist. * @param path The file to append to. * @param data The data to append. * @param scope The directory scope the path is in. Defaults to the default scope set for the default static instance. * @returns A promise that resolves when the data has been appended. */ static appendFile(path: string, data: string, scope?: CloudStorageScope): Promise<void>; /** * Writes to the file at the given path in the provider of the default static instance, creating it if it doesn't exist or overwriting it if it does. * @param path The file to write to. * @param data The data to write. * @param scope The directory scope the path is in. Defaults to the default scope set for the default static instance. * @returns A promise that resolves when the file has been written. */ static writeFile(path: string, data: string, scope?: CloudStorageScope): Promise<void>; /** * Creates a new directory at the given path in the provider of the default static instance. * @param path The directory to create. * @param scope The directory scope the path is in. Defaults to the default scope set for the default static instance. * @returns A promise that resolves when the directory has been created. */ static mkdir(path: string, scope?: CloudStorageScope): Promise<void>; /** * Lists the contents of the directory at the given path in the provider of the default static instance. * @param path The directory to list. * @param scope The directory scope the path is in. Defaults to the default scope set for the default static instance. * @returns A promise that resolves to an array of file names, excluding '.' and '..'. */ static readdir(path: string, scope?: CloudStorageScope): Promise<string[]>; /** * Reads the contents of the file at the given path in the provider of the default static instance. * @param path The file to read. * @param scope The directory scope the path is in. Defaults to the default scope set for the default static instance. * @returns A promise that resolves to the contents of the file. */ static readFile(path: string, scope?: CloudStorageScope): Promise<string>; /** * Triggers synchronization for the file at the given path in the provider of the default static instance. Does not have any effect on Google Drive. * @param path The file to trigger synchronization for. * @param scope The directory scope the path is in. Defaults to the default scope set for the default static instance. * @returns A promise that resolves once the synchronization has been triggered. */ static triggerSync(path: string, scope?: CloudStorageScope): Promise<void>; /** * Uploads the file at the given local path to the given path in the provider of the default static instance, creating it if it doesn't exist or overwriting it if it does. * @param remotePath The remote path to upload to. * @param localPath The local path of the file to upload. * @param options The options for the upload. Must contain a `mimeType` property. * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider. * @returns A promise that resolves when the file has been uploaded. */ static uploadFile(remotePath: string, localPath: string, options: { mimeType: string; }, scope?: CloudStorageScope): Promise<void>; /** * Triggers synchronization for the file at the given path in the provider of the default static instance. Does not have any effect on Google Drive. * @param path The file to trigger synchronization for. * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider. * @returns A promise that resolves once the synchronization has been triggered. * @deprecated Use `triggerSync` instead. */ static downloadFile(path: string, scope?: CloudStorageScope): Promise<void>; /** * Downloads the cloud file at the given remote path to the given local path. * @param remotePath The remote path of the file to download from the cloud. * @param localPath The local path to download the cloud file to. * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider. */ static downloadFile(remotePath: string, localPath: string, scope?: CloudStorageScope): Promise<void>; /** * Deletes the file at the given path in the provider of the default static instance. * @param path The file to delete. * @param scope The directory scope the path is in. Defaults to the default scope set for the default static instance. * @returns A promise that resolves when the file has been deleted. */ static unlink(path: string, scope?: CloudStorageScope): Promise<void>; /** * Deletes the directory at the given path in the provider of the default static instance. * @param path The directory to delete. * @param options Options for the delete operation. Defaults to { recursive: false }. * @param scope The directory scope the path is in. Defaults to the default scope set for the default static instance. * @returns A promise that resolves when the directory has been deleted. */ static rmdir(path: string, options?: { recursive?: boolean; }, scope?: CloudStorageScope): Promise<void>; /** * Gets the size, creation time, and modification time of the file at the given path in the provider of the default static instance. * @param path The file to stat. * @param scope The directory scope the path is in. Defaults to the default scope set for the default static instance. * @returns A promise that resolves to the CloudStorageFileStat object. */ static stat(path: string, scope?: CloudStorageScope): Promise<CloudStorageFileStat>; } //# sourceMappingURL=cloud-storage.d.ts.map