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