1import { DownloadOptions, DownloadPauseState, FileSystemNetworkTaskProgressCallback, DownloadProgressData, UploadProgressData, FileInfo, FileSystemDownloadResult, FileSystemRequestDirectoryPermissionsResult, FileSystemUploadOptions, FileSystemUploadResult, ReadingOptions, WritingOptions, DeletingOptions, InfoOptions, RelocatingOptions, MakeDirectoryOptions } from './FileSystem.types'; 2/** 3 * `file://` URI pointing to the directory where user documents for this app will be stored. 4 * Files stored here will remain until explicitly deleted by the app. Ends with a trailing `/`. 5 * Example uses are for files the user saves that they expect to see again. 6 */ 7export declare const documentDirectory: string | null; 8/** 9 * `file://` URI pointing to the directory where temporary files used by this app will be stored. 10 * Files stored here may be automatically deleted by the system when low on storage. 11 * Example uses are for downloaded or generated files that the app just needs for one-time usage. 12 */ 13export declare const cacheDirectory: string | null; 14export declare const bundledAssets: string | null, bundleDirectory: string | null; 15/** 16 * Get metadata information about a file, directory or external content/asset. 17 * @param fileUri URI to the file or directory. See [supported URI schemes](#supported-uri-schemes). 18 * @param options A map of options represented by [`GetInfoAsyncOptions`](#getinfoasyncoptions) type. 19 * @return A Promise that resolves to a `FileInfo` object. If no item exists at this URI, 20 * the returned Promise resolves to `FileInfo` object in form of `{ exists: false, isDirectory: false }`. 21 */ 22export declare function getInfoAsync(fileUri: string, options?: InfoOptions): Promise<FileInfo>; 23/** 24 * Read the entire contents of a file as a string. Binary will be returned in raw format, you will need to append `data:image/png;base64,` to use it as Base64. 25 * @param fileUri `file://` or [SAF](#saf-uri) URI to the file or directory. 26 * @param options A map of read options represented by [`ReadingOptions`](#readingoptions) type. 27 * @return A Promise that resolves to a string containing the entire contents of the file. 28 */ 29export declare function readAsStringAsync(fileUri: string, options?: ReadingOptions): Promise<string>; 30/** 31 * Takes a `file://` URI and converts it into content URI (`content://`) so that it can be accessed by other applications outside of Expo. 32 * @param fileUri The local URI of the file. If there is no file at this URI, an exception will be thrown. 33 * @example 34 * ```js 35 * FileSystem.getContentUriAsync(uri).then(cUri => { 36 * console.log(cUri); 37 * IntentLauncher.startActivityAsync('android.intent.action.VIEW', { 38 * data: cUri, 39 * flags: 1, 40 * }); 41 * }); 42 * ``` 43 * @return Returns a Promise that resolves to a `string` containing a `content://` URI pointing to the file. 44 * The URI is the same as the `fileUri` input parameter but in a different format. 45 */ 46export declare function getContentUriAsync(fileUri: string): Promise<string>; 47/** 48 * Write the entire contents of a file as a string. 49 * @param fileUri `file://` or [SAF](#saf-uri) URI to the file or directory. 50 * > Note: when you're using SAF URI the file needs to exist. You can't create a new file. 51 * @param contents The string to replace the contents of the file with. 52 * @param options A map of write options represented by [`WritingOptions`](#writingoptions) type. 53 */ 54export declare function writeAsStringAsync(fileUri: string, contents: string, options?: WritingOptions): Promise<void>; 55/** 56 * Delete a file or directory. If the URI points to a directory, the directory and all its contents are recursively deleted. 57 * @param fileUri `file://` or [SAF](#saf-uri) URI to the file or directory. 58 * @param options A map of write options represented by [`DeletingOptions`](#deletingoptions) type. 59 */ 60export declare function deleteAsync(fileUri: string, options?: DeletingOptions): Promise<void>; 61export declare function deleteLegacyDocumentDirectoryAndroid(): Promise<void>; 62/** 63 * Move a file or directory to a new location. 64 * @param options A map of move options represented by [`RelocatingOptions`](#relocatingoptions) type. 65 */ 66export declare function moveAsync(options: RelocatingOptions): Promise<void>; 67/** 68 * Create a copy of a file or directory. Directories are recursively copied with all of their contents. 69 * It can be also used to copy content shared by other apps to local filesystem. 70 * @param options A map of move options represented by [`RelocatingOptions`](#relocatingoptions) type. 71 */ 72export declare function copyAsync(options: RelocatingOptions): Promise<void>; 73/** 74 * Create a new empty directory. 75 * @param fileUri `file://` URI to the new directory to create. 76 * @param options A map of create directory options represented by [`MakeDirectoryOptions`](#makedirectoryoptions) type. 77 */ 78export declare function makeDirectoryAsync(fileUri: string, options?: MakeDirectoryOptions): Promise<void>; 79/** 80 * Enumerate the contents of a directory. 81 * @param fileUri `file://` URI to the directory. 82 * @return A Promise that resolves to an array of strings, each containing the name of a file or directory contained in the directory at `fileUri`. 83 */ 84export declare function readDirectoryAsync(fileUri: string): Promise<string[]>; 85/** 86 * Gets the available internal disk storage size, in bytes. This returns the free space on the data partition that hosts all of the internal storage for all apps on the device. 87 * @return Returns a Promise that resolves to the number of bytes available on the internal disk, or JavaScript's [`MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) 88 * if the capacity is greater than 2<sup>53</sup> - 1 bytes. 89 */ 90export declare function getFreeDiskStorageAsync(): Promise<number>; 91/** 92 * Gets total internal disk storage size, in bytes. This is the total capacity of the data partition that hosts all the internal storage for all apps on the device. 93 * @return Returns a Promise that resolves to a number that specifies the total internal disk storage capacity in bytes, or JavaScript's [`MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) 94 * if the capacity is greater than 2<sup>53</sup> - 1 bytes. 95 */ 96export declare function getTotalDiskCapacityAsync(): Promise<number>; 97/** 98 * Download the contents at a remote URI to a file in the app's file system. The directory for a local file uri must exist prior to calling this function. 99 * @param uri The remote URI to download from. 100 * @param fileUri The local URI of the file to download to. If there is no file at this URI, a new one is created. 101 * If there is a file at this URI, its contents are replaced. The directory for the file must exist. 102 * @param options A map of download options represented by [`DownloadOptions`](#downloadoptions) type. 103 * @example 104 * ```js 105 * FileSystem.downloadAsync( 106 * 'http://techslides.com/demos/sample-videos/small.mp4', 107 * FileSystem.documentDirectory + 'small.mp4' 108 * ) 109 * .then(({ uri }) => { 110 * console.log('Finished downloading to ', uri); 111 * }) 112 * .catch(error => { 113 * console.error(error); 114 * }); 115 * ``` 116 * @return Returns a Promise that resolves to a `FileSystemDownloadResult` object. 117 */ 118export declare function downloadAsync(uri: string, fileUri: string, options?: DownloadOptions): Promise<FileSystemDownloadResult>; 119/** 120 * Upload the contents of the file pointed by `fileUri` to the remote url. 121 * @param url The remote URL, where the file will be sent. 122 * @param fileUri The local URI of the file to send. The file must exist. 123 * @param options A map of download options represented by [`FileSystemUploadOptions`](#filesystemuploadoptions) type. 124 * @example 125 * **Client** 126 * 127 * ```js 128 * import * as FileSystem from 'expo-file-system'; 129 * 130 * try { 131 * const response = await FileSystem.uploadAsync(`http://192.168.0.1:1234/binary-upload`, fileUri, { 132 * fieldName: 'file', 133 * httpMethod: 'PATCH', 134 * uploadType: FileSystem.FileSystemUploadType.BINARY_CONTENT, 135 * }); 136 * console.log(JSON.stringify(response, null, 4)); 137 * } catch (error) { 138 * console.log(error); 139 * } 140 * ``` 141 * 142 * **Server** 143 * 144 * Please refer to the "[Server: Handling multipart requests](#server-handling-multipart-requests)" example - there is code for a simple Node.js server. 145 * @return Returns a Promise that resolves to `FileSystemUploadResult` object. 146 */ 147export declare function uploadAsync(url: string, fileUri: string, options?: FileSystemUploadOptions): Promise<FileSystemUploadResult>; 148/** 149 * Create a `DownloadResumable` object which can start, pause, and resume a download of contents at a remote URI to a file in the app's file system. 150 * > Note: You need to call `downloadAsync()`, on a `DownloadResumable` instance to initiate the download. 151 * The `DownloadResumable` object has a callback that provides download progress updates. 152 * Downloads can be resumed across app restarts by using `AsyncStorage` to store the `DownloadResumable.savable()` object for later retrieval. 153 * The `savable` object contains the arguments required to initialize a new `DownloadResumable` object to resume the download after an app restart. 154 * The directory for a local file uri must exist prior to calling this function. 155 * @param uri The remote URI to download from. 156 * @param fileUri The local URI of the file to download to. If there is no file at this URI, a new one is created. 157 * If there is a file at this URI, its contents are replaced. The directory for the file must exist. 158 * @param options A map of download options represented by [`DownloadOptions`](#downloadoptions) type. 159 * @param callback This function is called on each data write to update the download progress. 160 * > **Note**: When the app has been moved to the background, this callback won't be fired until it's moved to the foreground. 161 * @param resumeData The string which allows the api to resume a paused download. This is set on the `DownloadResumable` object automatically when a download is paused. 162 * When initializing a new `DownloadResumable` this should be `null`. 163 */ 164export declare function createDownloadResumable(uri: string, fileUri: string, options?: DownloadOptions, callback?: FileSystemNetworkTaskProgressCallback<DownloadProgressData>, resumeData?: string): DownloadResumable; 165export declare function createUploadTask(url: string, fileUri: string, options?: FileSystemUploadOptions, callback?: FileSystemNetworkTaskProgressCallback<UploadProgressData>): UploadTask; 166export declare abstract class FileSystemCancellableNetworkTask<T extends DownloadProgressData | UploadProgressData> { 167 private _uuid; 168 protected taskWasCanceled: boolean; 169 private emitter; 170 private subscription?; 171 cancelAsync(): Promise<void>; 172 protected isTaskCancelled(): boolean; 173 protected get uuid(): string; 174 protected abstract getEventName(): string; 175 protected abstract getCallback(): FileSystemNetworkTaskProgressCallback<T> | undefined; 176 protected addSubscription(): void; 177 protected removeSubscription(): void; 178} 179export declare class UploadTask extends FileSystemCancellableNetworkTask<UploadProgressData> { 180 private url; 181 private fileUri; 182 private callback?; 183 private options; 184 constructor(url: string, fileUri: string, options?: FileSystemUploadOptions, callback?: FileSystemNetworkTaskProgressCallback<UploadProgressData> | undefined); 185 protected getEventName(): string; 186 protected getCallback(): FileSystemNetworkTaskProgressCallback<UploadProgressData> | undefined; 187 uploadAsync(): Promise<FileSystemUploadResult | undefined>; 188} 189export declare class DownloadResumable extends FileSystemCancellableNetworkTask<DownloadProgressData> { 190 private url; 191 private _fileUri; 192 private options; 193 private callback?; 194 private resumeData?; 195 constructor(url: string, _fileUri: string, options?: DownloadOptions, callback?: FileSystemNetworkTaskProgressCallback<DownloadProgressData> | undefined, resumeData?: string | undefined); 196 get fileUri(): string; 197 protected getEventName(): string; 198 protected getCallback(): FileSystemNetworkTaskProgressCallback<DownloadProgressData> | undefined; 199 /** 200 * Download the contents at a remote URI to a file in the app's file system. 201 * @return Returns a Promise that resolves to `FileSystemDownloadResult` object, or to `undefined` when task was cancelled. 202 */ 203 downloadAsync(): Promise<FileSystemDownloadResult | undefined>; 204 /** 205 * Pause the current download operation. `resumeData` is added to the `DownloadResumable` object after a successful pause operation. 206 * Returns an object that can be saved with `AsyncStorage` for future retrieval (the same object that is returned from calling `FileSystem.DownloadResumable.savable()`). 207 * @return Returns a Promise that resolves to `DownloadPauseState` object. 208 */ 209 pauseAsync(): Promise<DownloadPauseState>; 210 /** 211 * Resume a paused download operation. 212 * @return Returns a Promise that resolves to `FileSystemDownloadResult` object, or to `undefined` when task was cancelled. 213 */ 214 resumeAsync(): Promise<FileSystemDownloadResult | undefined>; 215 /** 216 * Method to get the object which can be saved with `AsyncStorage` for future retrieval. 217 * @returns Returns object in shape of `DownloadPauseState` type. 218 */ 219 savable(): DownloadPauseState; 220} 221/** 222 * The `StorageAccessFramework` is a namespace inside of the `expo-file-system` module, which encapsulates all functions which can be used with [SAF URIs](#saf-uri). 223 * You can read more about SAF in the [Android documentation](https://developer.android.com/guide/topics/providers/document-provider). 224 * 225 * @example 226 * # Basic Usage 227 * 228 * ```ts 229 * import { StorageAccessFramework } from 'expo-file-system'; 230 * 231 * // Requests permissions for external directory 232 * const permissions = await StorageAccessFramework.requestDirectoryPermissionsAsync(); 233 * 234 * if (permissions.granted) { 235 * // Gets SAF URI from response 236 * const uri = permissions.directoryUri; 237 * 238 * // Gets all files inside of selected directory 239 * const files = await StorageAccessFramework.readDirectoryAsync(uri); 240 * alert(`Files inside ${uri}:\n\n${JSON.stringify(files)}`); 241 * } 242 * ``` 243 * 244 * # Migrating an album 245 * 246 * ```ts 247 * import * as MediaLibrary from 'expo-media-library'; 248 * import * as FileSystem from 'expo-file-system'; 249 * const { StorageAccessFramework } = FileSystem; 250 * 251 * async function migrateAlbum(albumName: string) { 252 * // Gets SAF URI to the album 253 * const albumUri = StorageAccessFramework.getUriForDirectoryInRoot(albumName); 254 * 255 * // Requests permissions 256 * const permissions = await StorageAccessFramework.requestDirectoryPermissionsAsync(albumUri); 257 * if (!permissions.granted) { 258 * return; 259 * } 260 * 261 * const permittedUri = permissions.directoryUri; 262 * // Checks if users selected the correct folder 263 * if (!permittedUri.includes(albumName)) { 264 * return; 265 * } 266 * 267 * const mediaLibraryPermissions = await MediaLibrary.requestPermissionsAsync(); 268 * if (!mediaLibraryPermissions.granted) { 269 * return; 270 * } 271 * 272 * // Moves files from external storage to internal storage 273 * await StorageAccessFramework.moveAsync({ 274 * from: permittedUri, 275 * to: FileSystem.documentDirectory!, 276 * }); 277 * 278 * const outputDir = FileSystem.documentDirectory! + albumName; 279 * const migratedFiles = await FileSystem.readDirectoryAsync(outputDir); 280 * 281 * // Creates assets from local files 282 * const [newAlbumCreator, ...assets] = await Promise.all( 283 * migratedFiles.map<Promise<MediaLibrary.Asset>>( 284 * async fileName => await MediaLibrary.createAssetAsync(outputDir + '/' + fileName) 285 * ) 286 * ); 287 * 288 * // Album was empty 289 * if (!newAlbumCreator) { 290 * return; 291 * } 292 * 293 * // Creates a new album in the scoped directory 294 * const newAlbum = await MediaLibrary.createAlbumAsync(albumName, newAlbumCreator, false); 295 * if (assets.length) { 296 * await MediaLibrary.addAssetsToAlbumAsync(assets, newAlbum, false); 297 * } 298 * } 299 * ``` 300 * @platform Android 301 */ 302export declare namespace StorageAccessFramework { 303 /** 304 * Gets a [SAF URI](#saf-uri) pointing to a folder in the Android root directory. You can use this function to get URI for 305 * `StorageAccessFramework.requestDirectoryPermissionsAsync()` when you trying to migrate an album. In that case, the name of the album is the folder name. 306 * @param folderName The name of the folder which is located in the Android root directory. 307 * @return Returns a [SAF URI](#saf-uri) to a folder. 308 */ 309 function getUriForDirectoryInRoot(folderName: string): string; 310 /** 311 * Allows users to select a specific directory, granting your app access to all of the files and sub-directories within that directory. 312 * @param initialFileUrl The [SAF URI](#saf-uri) of the directory that the file picker should display when it first loads. 313 * If URI is incorrect or points to a non-existing folder, it's ignored. 314 * @platform android 11+ 315 * @return Returns a Promise that resolves to `FileSystemRequestDirectoryPermissionsResult` object. 316 */ 317 function requestDirectoryPermissionsAsync(initialFileUrl?: string | null): Promise<FileSystemRequestDirectoryPermissionsResult>; 318 /** 319 * Enumerate the contents of a directory. 320 * @param dirUri [SAF](#saf-uri) URI to the directory. 321 * @return A Promise that resolves to an array of strings, each containing the full [SAF URI](#saf-uri) of a file or directory contained in the directory at `fileUri`. 322 */ 323 function readDirectoryAsync(dirUri: string): Promise<string[]>; 324 /** 325 * Creates a new empty directory. 326 * @param parentUri The [SAF](#saf-uri) URI to the parent directory. 327 * @param dirName The name of new directory. 328 * @return A Promise that resolves to a [SAF URI](#saf-uri) to the created directory. 329 */ 330 function makeDirectoryAsync(parentUri: string, dirName: string): Promise<string>; 331 /** 332 * Creates a new empty file. 333 * @param parentUri The [SAF](#saf-uri) URI to the parent directory. 334 * @param fileName The name of new file **without the extension**. 335 * @param mimeType The MIME type of new file. 336 * @return A Promise that resolves to a [SAF URI](#saf-uri) to the created file. 337 */ 338 function createFileAsync(parentUri: string, fileName: string, mimeType: string): Promise<string>; 339 /** 340 * Alias for [`writeAsStringAsync`](#filesystemwriteasstringasyncfileuri-contents-options) method. 341 */ 342 const writeAsStringAsync: typeof import("./FileSystem").writeAsStringAsync; 343 /** 344 * Alias for [`readAsStringAsync`](#filesystemreadasstringasyncfileuri-options) method. 345 */ 346 const readAsStringAsync: typeof import("./FileSystem").readAsStringAsync; 347 /** 348 * Alias for [`deleteAsync`](#filesystemdeleteasyncfileuri-options) method. 349 */ 350 const deleteAsync: typeof import("./FileSystem").deleteAsync; 351 /** 352 * Alias for [`moveAsync`](#filesystemmoveasyncoptions) method. 353 */ 354 const moveAsync: typeof import("./FileSystem").moveAsync; 355 /** 356 * Alias fro [`copyAsync`](#filesystemcopyasyncoptions) method. 357 */ 358 const copyAsync: typeof import("./FileSystem").copyAsync; 359} 360//# sourceMappingURL=FileSystem.d.ts.map