1import { EventEmitter, UnavailabilityError, uuid } from 'expo-modules-core'; 2import { Platform } from 'react-native'; 3import ExponentFileSystem from './ExponentFileSystem'; 4import { FileSystemSessionType, FileSystemUploadType, } from './FileSystem.types'; 5if (!ExponentFileSystem) { 6 console.warn("No native ExponentFileSystem module found, are you sure the expo-file-system's module is linked properly?"); 7} 8// Prevent webpack from pruning this. 9const _unused = new EventEmitter(ExponentFileSystem); // eslint-disable-line 10function normalizeEndingSlash(p) { 11 if (p != null) { 12 return p.replace(/\/*$/, '') + '/'; 13 } 14 return null; 15} 16/** 17 * `file://` URI pointing to the directory where user documents for this app will be stored. 18 * Files stored here will remain until explicitly deleted by the app. Ends with a trailing `/`. 19 * Example uses are for files the user saves that they expect to see again. 20 */ 21export const documentDirectory = normalizeEndingSlash(ExponentFileSystem.documentDirectory); 22/** 23 * `file://` URI pointing to the directory where temporary files used by this app will be stored. 24 * Files stored here may be automatically deleted by the system when low on storage. 25 * Example uses are for downloaded or generated files that the app just needs for one-time usage. 26 */ 27export const cacheDirectory = normalizeEndingSlash(ExponentFileSystem.cacheDirectory); 28// @docsMissing 29export const { bundledAssets, bundleDirectory } = ExponentFileSystem; 30/** 31 * Get metadata information about a file, directory or external content/asset. 32 * @param fileUri URI to the file or directory. See [supported URI schemes](#supported-uri-schemes). 33 * @param options A map of options represented by [`InfoOptions`](#infooptions) type. 34 * @return A Promise that resolves to a `FileInfo` object. If no item exists at this URI, 35 * the returned Promise resolves to `FileInfo` object in form of `{ exists: false, isDirectory: false }`. 36 */ 37export async function getInfoAsync(fileUri, options = {}) { 38 if (!ExponentFileSystem.getInfoAsync) { 39 throw new UnavailabilityError('expo-file-system', 'getInfoAsync'); 40 } 41 return await ExponentFileSystem.getInfoAsync(fileUri, options); 42} 43/** 44 * 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. 45 * @param fileUri `file://` or [SAF](#saf-uri) URI to the file or directory. 46 * @param options A map of read options represented by [`ReadingOptions`](#readingoptions) type. 47 * @return A Promise that resolves to a string containing the entire contents of the file. 48 */ 49export async function readAsStringAsync(fileUri, options = {}) { 50 if (!ExponentFileSystem.readAsStringAsync) { 51 throw new UnavailabilityError('expo-file-system', 'readAsStringAsync'); 52 } 53 return await ExponentFileSystem.readAsStringAsync(fileUri, options); 54} 55/** 56 * Takes a `file://` URI and converts it into content URI (`content://`) so that it can be accessed by other applications outside of Expo. 57 * @param fileUri The local URI of the file. If there is no file at this URI, an exception will be thrown. 58 * @example 59 * ```js 60 * FileSystem.getContentUriAsync(uri).then(cUri => { 61 * console.log(cUri); 62 * IntentLauncher.startActivityAsync('android.intent.action.VIEW', { 63 * data: cUri, 64 * flags: 1, 65 * }); 66 * }); 67 * ``` 68 * @return Returns a Promise that resolves to a `string` containing a `content://` URI pointing to the file. 69 * The URI is the same as the `fileUri` input parameter but in a different format. 70 * @platform android 71 */ 72export async function getContentUriAsync(fileUri) { 73 if (Platform.OS === 'android') { 74 if (!ExponentFileSystem.getContentUriAsync) { 75 throw new UnavailabilityError('expo-file-system', 'getContentUriAsync'); 76 } 77 return await ExponentFileSystem.getContentUriAsync(fileUri); 78 } 79 else { 80 return fileUri; 81 } 82} 83/** 84 * Write the entire contents of a file as a string. 85 * @param fileUri `file://` or [SAF](#saf-uri) URI to the file or directory. 86 * > Note: when you're using SAF URI the file needs to exist. You can't create a new file. 87 * @param contents The string to replace the contents of the file with. 88 * @param options A map of write options represented by [`WritingOptions`](#writingoptions) type. 89 */ 90export async function writeAsStringAsync(fileUri, contents, options = {}) { 91 if (!ExponentFileSystem.writeAsStringAsync) { 92 throw new UnavailabilityError('expo-file-system', 'writeAsStringAsync'); 93 } 94 return await ExponentFileSystem.writeAsStringAsync(fileUri, contents, options); 95} 96/** 97 * Delete a file or directory. If the URI points to a directory, the directory and all its contents are recursively deleted. 98 * @param fileUri `file://` or [SAF](#saf-uri) URI to the file or directory. 99 * @param options A map of write options represented by [`DeletingOptions`](#deletingoptions) type. 100 */ 101export async function deleteAsync(fileUri, options = {}) { 102 if (!ExponentFileSystem.deleteAsync) { 103 throw new UnavailabilityError('expo-file-system', 'deleteAsync'); 104 } 105 return await ExponentFileSystem.deleteAsync(fileUri, options); 106} 107export async function deleteLegacyDocumentDirectoryAndroid() { 108 if (Platform.OS !== 'android' || documentDirectory == null) { 109 return; 110 } 111 const legacyDocumentDirectory = `${documentDirectory}ExperienceData/`; 112 return await deleteAsync(legacyDocumentDirectory, { idempotent: true }); 113} 114/** 115 * Move a file or directory to a new location. 116 * @param options A map of move options represented by [`RelocatingOptions`](#relocatingoptions) type. 117 */ 118export async function moveAsync(options) { 119 if (!ExponentFileSystem.moveAsync) { 120 throw new UnavailabilityError('expo-file-system', 'moveAsync'); 121 } 122 return await ExponentFileSystem.moveAsync(options); 123} 124/** 125 * Create a copy of a file or directory. Directories are recursively copied with all of their contents. 126 * It can be also used to copy content shared by other apps to local filesystem. 127 * @param options A map of move options represented by [`RelocatingOptions`](#relocatingoptions) type. 128 */ 129export async function copyAsync(options) { 130 if (!ExponentFileSystem.copyAsync) { 131 throw new UnavailabilityError('expo-file-system', 'copyAsync'); 132 } 133 return await ExponentFileSystem.copyAsync(options); 134} 135/** 136 * Create a new empty directory. 137 * @param fileUri `file://` URI to the new directory to create. 138 * @param options A map of create directory options represented by [`MakeDirectoryOptions`](#makedirectoryoptions) type. 139 */ 140export async function makeDirectoryAsync(fileUri, options = {}) { 141 if (!ExponentFileSystem.makeDirectoryAsync) { 142 throw new UnavailabilityError('expo-file-system', 'makeDirectoryAsync'); 143 } 144 return await ExponentFileSystem.makeDirectoryAsync(fileUri, options); 145} 146/** 147 * Enumerate the contents of a directory. 148 * @param fileUri `file://` URI to the directory. 149 * @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`. 150 */ 151export async function readDirectoryAsync(fileUri) { 152 if (!ExponentFileSystem.readDirectoryAsync) { 153 throw new UnavailabilityError('expo-file-system', 'readDirectoryAsync'); 154 } 155 return await ExponentFileSystem.readDirectoryAsync(fileUri); 156} 157/** 158 * 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. 159 * @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) 160 * if the capacity is greater than 2<sup>53</sup> - 1 bytes. 161 */ 162export async function getFreeDiskStorageAsync() { 163 if (!ExponentFileSystem.getFreeDiskStorageAsync) { 164 throw new UnavailabilityError('expo-file-system', 'getFreeDiskStorageAsync'); 165 } 166 return await ExponentFileSystem.getFreeDiskStorageAsync(); 167} 168/** 169 * 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. 170 * @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) 171 * if the capacity is greater than 2<sup>53</sup> - 1 bytes. 172 */ 173export async function getTotalDiskCapacityAsync() { 174 if (!ExponentFileSystem.getTotalDiskCapacityAsync) { 175 throw new UnavailabilityError('expo-file-system', 'getTotalDiskCapacityAsync'); 176 } 177 return await ExponentFileSystem.getTotalDiskCapacityAsync(); 178} 179/** 180 * 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. 181 * @param uri The remote URI to download from. 182 * @param fileUri The local URI of the file to download to. If there is no file at this URI, a new one is created. 183 * If there is a file at this URI, its contents are replaced. The directory for the file must exist. 184 * @param options A map of download options represented by [`DownloadOptions`](#downloadoptions) type. 185 * @example 186 * ```js 187 * FileSystem.downloadAsync( 188 * 'http://techslides.com/demos/sample-videos/small.mp4', 189 * FileSystem.documentDirectory + 'small.mp4' 190 * ) 191 * .then(({ uri }) => { 192 * console.log('Finished downloading to ', uri); 193 * }) 194 * .catch(error => { 195 * console.error(error); 196 * }); 197 * ``` 198 * @return Returns a Promise that resolves to a `FileSystemDownloadResult` object. 199 */ 200export async function downloadAsync(uri, fileUri, options = {}) { 201 if (!ExponentFileSystem.downloadAsync) { 202 throw new UnavailabilityError('expo-file-system', 'downloadAsync'); 203 } 204 return await ExponentFileSystem.downloadAsync(uri, fileUri, { 205 sessionType: FileSystemSessionType.BACKGROUND, 206 ...options, 207 }); 208} 209/** 210 * Upload the contents of the file pointed by `fileUri` to the remote url. 211 * @param url The remote URL, where the file will be sent. 212 * @param fileUri The local URI of the file to send. The file must exist. 213 * @param options A map of download options represented by [`FileSystemUploadOptions`](#filesystemuploadoptions) type. 214 * @example 215 * **Client** 216 * 217 * ```js 218 * import * as FileSystem from 'expo-file-system'; 219 * 220 * try { 221 * const response = await FileSystem.uploadAsync(`http://192.168.0.1:1234/binary-upload`, fileUri, { 222 * fieldName: 'file', 223 * httpMethod: 'PATCH', 224 * uploadType: FileSystem.FileSystemUploadType.BINARY_CONTENT, 225 * }); 226 * console.log(JSON.stringify(response, null, 4)); 227 * } catch (error) { 228 * console.log(error); 229 * } 230 * ``` 231 * 232 * **Server** 233 * 234 * Please refer to the "[Server: Handling multipart requests](#server-handling-multipart-requests)" example - there is code for a simple Node.js server. 235 * @return Returns a Promise that resolves to `FileSystemUploadResult` object. 236 */ 237export async function uploadAsync(url, fileUri, options = {}) { 238 if (!ExponentFileSystem.uploadAsync) { 239 throw new UnavailabilityError('expo-file-system', 'uploadAsync'); 240 } 241 return await ExponentFileSystem.uploadAsync(url, fileUri, { 242 sessionType: FileSystemSessionType.BACKGROUND, 243 uploadType: FileSystemUploadType.BINARY_CONTENT, 244 ...options, 245 httpMethod: (options.httpMethod || 'POST').toUpperCase(), 246 }); 247} 248/** 249 * 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. 250 * > Note: You need to call `downloadAsync()`, on a `DownloadResumable` instance to initiate the download. 251 * The `DownloadResumable` object has a callback that provides download progress updates. 252 * Downloads can be resumed across app restarts by using `AsyncStorage` to store the `DownloadResumable.savable()` object for later retrieval. 253 * The `savable` object contains the arguments required to initialize a new `DownloadResumable` object to resume the download after an app restart. 254 * The directory for a local file uri must exist prior to calling this function. 255 * @param uri The remote URI to download from. 256 * @param fileUri The local URI of the file to download to. If there is no file at this URI, a new one is created. 257 * If there is a file at this URI, its contents are replaced. The directory for the file must exist. 258 * @param options A map of download options represented by [`DownloadOptions`](#downloadoptions) type. 259 * @param callback This function is called on each data write to update the download progress. 260 * > **Note**: When the app has been moved to the background, this callback won't be fired until it's moved to the foreground. 261 * @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. 262 * When initializing a new `DownloadResumable` this should be `null`. 263 */ 264export function createDownloadResumable(uri, fileUri, options, callback, resumeData) { 265 return new DownloadResumable(uri, fileUri, options, callback, resumeData); 266} 267export function createUploadTask(url, fileUri, options, callback) { 268 return new UploadTask(url, fileUri, options, callback); 269} 270export class FileSystemCancellableNetworkTask { 271 _uuid = uuid.v4(); 272 taskWasCanceled = false; 273 emitter = new EventEmitter(ExponentFileSystem); 274 subscription; 275 // @docsMissing 276 async cancelAsync() { 277 if (!ExponentFileSystem.networkTaskCancelAsync) { 278 throw new UnavailabilityError('expo-file-system', 'networkTaskCancelAsync'); 279 } 280 this.removeSubscription(); 281 this.taskWasCanceled = true; 282 return await ExponentFileSystem.networkTaskCancelAsync(this.uuid); 283 } 284 isTaskCancelled() { 285 if (this.taskWasCanceled) { 286 console.warn('This task was already canceled.'); 287 return true; 288 } 289 return false; 290 } 291 get uuid() { 292 return this._uuid; 293 } 294 addSubscription() { 295 if (this.subscription) { 296 return; 297 } 298 this.subscription = this.emitter.addListener(this.getEventName(), (event) => { 299 if (event.uuid === this.uuid) { 300 const callback = this.getCallback(); 301 if (callback) { 302 callback(event.data); 303 } 304 } 305 }); 306 } 307 removeSubscription() { 308 if (!this.subscription) { 309 return; 310 } 311 this.emitter.removeSubscription(this.subscription); 312 this.subscription = null; 313 } 314} 315export class UploadTask extends FileSystemCancellableNetworkTask { 316 url; 317 fileUri; 318 callback; 319 options; 320 constructor(url, fileUri, options, callback) { 321 super(); 322 this.url = url; 323 this.fileUri = fileUri; 324 this.callback = callback; 325 const httpMethod = (options?.httpMethod?.toUpperCase() || 326 'POST'); 327 this.options = { 328 sessionType: FileSystemSessionType.BACKGROUND, 329 uploadType: FileSystemUploadType.BINARY_CONTENT, 330 ...options, 331 httpMethod, 332 }; 333 } 334 getEventName() { 335 return 'expo-file-system.uploadProgress'; 336 } 337 getCallback() { 338 return this.callback; 339 } 340 // @docsMissing 341 async uploadAsync() { 342 if (!ExponentFileSystem.uploadTaskStartAsync) { 343 throw new UnavailabilityError('expo-file-system', 'uploadTaskStartAsync'); 344 } 345 if (this.isTaskCancelled()) { 346 return; 347 } 348 this.addSubscription(); 349 const result = await ExponentFileSystem.uploadTaskStartAsync(this.url, this.fileUri, this.uuid, this.options); 350 this.removeSubscription(); 351 return result; 352 } 353} 354export class DownloadResumable extends FileSystemCancellableNetworkTask { 355 url; 356 _fileUri; 357 options; 358 callback; 359 resumeData; 360 constructor(url, _fileUri, options = {}, callback, resumeData) { 361 super(); 362 this.url = url; 363 this._fileUri = _fileUri; 364 this.options = options; 365 this.callback = callback; 366 this.resumeData = resumeData; 367 } 368 get fileUri() { 369 return this._fileUri; 370 } 371 getEventName() { 372 return 'expo-file-system.downloadProgress'; 373 } 374 getCallback() { 375 return this.callback; 376 } 377 /** 378 * Download the contents at a remote URI to a file in the app's file system. 379 * @return Returns a Promise that resolves to `FileSystemDownloadResult` object, or to `undefined` when task was cancelled. 380 */ 381 async downloadAsync() { 382 if (!ExponentFileSystem.downloadResumableStartAsync) { 383 throw new UnavailabilityError('expo-file-system', 'downloadResumableStartAsync'); 384 } 385 if (this.isTaskCancelled()) { 386 return; 387 } 388 this.addSubscription(); 389 return await ExponentFileSystem.downloadResumableStartAsync(this.url, this._fileUri, this.uuid, this.options, this.resumeData); 390 } 391 /** 392 * Pause the current download operation. `resumeData` is added to the `DownloadResumable` object after a successful pause operation. 393 * Returns an object that can be saved with `AsyncStorage` for future retrieval (the same object that is returned from calling `FileSystem.DownloadResumable.savable()`). 394 * @return Returns a Promise that resolves to `DownloadPauseState` object. 395 */ 396 async pauseAsync() { 397 if (!ExponentFileSystem.downloadResumablePauseAsync) { 398 throw new UnavailabilityError('expo-file-system', 'downloadResumablePauseAsync'); 399 } 400 if (this.isTaskCancelled()) { 401 return { 402 fileUri: this._fileUri, 403 options: this.options, 404 url: this.url, 405 }; 406 } 407 const pauseResult = await ExponentFileSystem.downloadResumablePauseAsync(this.uuid); 408 this.removeSubscription(); 409 if (pauseResult) { 410 this.resumeData = pauseResult.resumeData; 411 return this.savable(); 412 } 413 else { 414 throw new Error('Unable to generate a savable pause state'); 415 } 416 } 417 /** 418 * Resume a paused download operation. 419 * @return Returns a Promise that resolves to `FileSystemDownloadResult` object, or to `undefined` when task was cancelled. 420 */ 421 async resumeAsync() { 422 if (!ExponentFileSystem.downloadResumableStartAsync) { 423 throw new UnavailabilityError('expo-file-system', 'downloadResumableStartAsync'); 424 } 425 if (this.isTaskCancelled()) { 426 return; 427 } 428 this.addSubscription(); 429 return await ExponentFileSystem.downloadResumableStartAsync(this.url, this.fileUri, this.uuid, this.options, this.resumeData); 430 } 431 /** 432 * Method to get the object which can be saved with `AsyncStorage` for future retrieval. 433 * @returns Returns object in shape of `DownloadPauseState` type. 434 */ 435 savable() { 436 return { 437 url: this.url, 438 fileUri: this.fileUri, 439 options: this.options, 440 resumeData: this.resumeData, 441 }; 442 } 443} 444const baseReadAsStringAsync = readAsStringAsync; 445const baseWriteAsStringAsync = writeAsStringAsync; 446const baseDeleteAsync = deleteAsync; 447const baseMoveAsync = moveAsync; 448const baseCopyAsync = copyAsync; 449/** 450 * 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). 451 * You can read more about SAF in the [Android documentation](https://developer.android.com/guide/topics/providers/document-provider). 452 * 453 * @example 454 * # Basic Usage 455 * 456 * ```ts 457 * import { StorageAccessFramework } from 'expo-file-system'; 458 * 459 * // Requests permissions for external directory 460 * const permissions = await StorageAccessFramework.requestDirectoryPermissionsAsync(); 461 * 462 * if (permissions.granted) { 463 * // Gets SAF URI from response 464 * const uri = permissions.directoryUri; 465 * 466 * // Gets all files inside of selected directory 467 * const files = await StorageAccessFramework.readDirectoryAsync(uri); 468 * alert(`Files inside ${uri}:\n\n${JSON.stringify(files)}`); 469 * } 470 * ``` 471 * 472 * # Migrating an album 473 * 474 * ```ts 475 * import * as MediaLibrary from 'expo-media-library'; 476 * import * as FileSystem from 'expo-file-system'; 477 * const { StorageAccessFramework } = FileSystem; 478 * 479 * async function migrateAlbum(albumName: string) { 480 * // Gets SAF URI to the album 481 * const albumUri = StorageAccessFramework.getUriForDirectoryInRoot(albumName); 482 * 483 * // Requests permissions 484 * const permissions = await StorageAccessFramework.requestDirectoryPermissionsAsync(albumUri); 485 * if (!permissions.granted) { 486 * return; 487 * } 488 * 489 * const permittedUri = permissions.directoryUri; 490 * // Checks if users selected the correct folder 491 * if (!permittedUri.includes(albumName)) { 492 * return; 493 * } 494 * 495 * const mediaLibraryPermissions = await MediaLibrary.requestPermissionsAsync(); 496 * if (!mediaLibraryPermissions.granted) { 497 * return; 498 * } 499 * 500 * // Moves files from external storage to internal storage 501 * await StorageAccessFramework.moveAsync({ 502 * from: permittedUri, 503 * to: FileSystem.documentDirectory!, 504 * }); 505 * 506 * const outputDir = FileSystem.documentDirectory! + albumName; 507 * const migratedFiles = await FileSystem.readDirectoryAsync(outputDir); 508 * 509 * // Creates assets from local files 510 * const [newAlbumCreator, ...assets] = await Promise.all( 511 * migratedFiles.map<Promise<MediaLibrary.Asset>>( 512 * async fileName => await MediaLibrary.createAssetAsync(outputDir + '/' + fileName) 513 * ) 514 * ); 515 * 516 * // Album was empty 517 * if (!newAlbumCreator) { 518 * return; 519 * } 520 * 521 * // Creates a new album in the scoped directory 522 * const newAlbum = await MediaLibrary.createAlbumAsync(albumName, newAlbumCreator, false); 523 * if (assets.length) { 524 * await MediaLibrary.addAssetsToAlbumAsync(assets, newAlbum, false); 525 * } 526 * } 527 * ``` 528 * @platform Android 529 */ 530export var StorageAccessFramework; 531(function (StorageAccessFramework) { 532 /** 533 * Gets a [SAF URI](#saf-uri) pointing to a folder in the Android root directory. You can use this function to get URI for 534 * `StorageAccessFramework.requestDirectoryPermissionsAsync()` when you trying to migrate an album. In that case, the name of the album is the folder name. 535 * @param folderName The name of the folder which is located in the Android root directory. 536 * @return Returns a [SAF URI](#saf-uri) to a folder. 537 */ 538 function getUriForDirectoryInRoot(folderName) { 539 return `content://com.android.externalstorage.documents/tree/primary:${folderName}/document/primary:${folderName}`; 540 } 541 StorageAccessFramework.getUriForDirectoryInRoot = getUriForDirectoryInRoot; 542 /** 543 * Allows users to select a specific directory, granting your app access to all of the files and sub-directories within that directory. 544 * @param initialFileUrl The [SAF URI](#saf-uri) of the directory that the file picker should display when it first loads. 545 * If URI is incorrect or points to a non-existing folder, it's ignored. 546 * @platform android 11+ 547 * @return Returns a Promise that resolves to `FileSystemRequestDirectoryPermissionsResult` object. 548 */ 549 async function requestDirectoryPermissionsAsync(initialFileUrl = null) { 550 if (!ExponentFileSystem.requestDirectoryPermissionsAsync) { 551 throw new UnavailabilityError('expo-file-system', 'StorageAccessFramework.requestDirectoryPermissionsAsync'); 552 } 553 return await ExponentFileSystem.requestDirectoryPermissionsAsync(initialFileUrl); 554 } 555 StorageAccessFramework.requestDirectoryPermissionsAsync = requestDirectoryPermissionsAsync; 556 /** 557 * Enumerate the contents of a directory. 558 * @param dirUri [SAF](#saf-uri) URI to the directory. 559 * @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`. 560 */ 561 async function readDirectoryAsync(dirUri) { 562 if (!ExponentFileSystem.readSAFDirectoryAsync) { 563 throw new UnavailabilityError('expo-file-system', 'StorageAccessFramework.readDirectoryAsync'); 564 } 565 return await ExponentFileSystem.readSAFDirectoryAsync(dirUri); 566 } 567 StorageAccessFramework.readDirectoryAsync = readDirectoryAsync; 568 /** 569 * Creates a new empty directory. 570 * @param parentUri The [SAF](#saf-uri) URI to the parent directory. 571 * @param dirName The name of new directory. 572 * @return A Promise that resolves to a [SAF URI](#saf-uri) to the created directory. 573 */ 574 async function makeDirectoryAsync(parentUri, dirName) { 575 if (!ExponentFileSystem.makeSAFDirectoryAsync) { 576 throw new UnavailabilityError('expo-file-system', 'StorageAccessFramework.makeDirectoryAsync'); 577 } 578 return await ExponentFileSystem.makeSAFDirectoryAsync(parentUri, dirName); 579 } 580 StorageAccessFramework.makeDirectoryAsync = makeDirectoryAsync; 581 /** 582 * Creates a new empty file. 583 * @param parentUri The [SAF](#saf-uri) URI to the parent directory. 584 * @param fileName The name of new file **without the extension**. 585 * @param mimeType The MIME type of new file. 586 * @return A Promise that resolves to a [SAF URI](#saf-uri) to the created file. 587 */ 588 async function createFileAsync(parentUri, fileName, mimeType) { 589 if (!ExponentFileSystem.createSAFFileAsync) { 590 throw new UnavailabilityError('expo-file-system', 'StorageAccessFramework.createFileAsync'); 591 } 592 return await ExponentFileSystem.createSAFFileAsync(parentUri, fileName, mimeType); 593 } 594 StorageAccessFramework.createFileAsync = createFileAsync; 595 /** 596 * Alias for [`writeAsStringAsync`](#filesystemwriteasstringasyncfileuri-contents-options) method. 597 */ 598 StorageAccessFramework.writeAsStringAsync = baseWriteAsStringAsync; 599 /** 600 * Alias for [`readAsStringAsync`](#filesystemreadasstringasyncfileuri-options) method. 601 */ 602 StorageAccessFramework.readAsStringAsync = baseReadAsStringAsync; 603 /** 604 * Alias for [`deleteAsync`](#filesystemdeleteasyncfileuri-options) method. 605 */ 606 StorageAccessFramework.deleteAsync = baseDeleteAsync; 607 /** 608 * Alias for [`moveAsync`](#filesystemmoveasyncoptions) method. 609 */ 610 StorageAccessFramework.moveAsync = baseMoveAsync; 611 /** 612 * Alias for [`copyAsync`](#filesystemcopyasyncoptions) method. 613 */ 614 StorageAccessFramework.copyAsync = baseCopyAsync; 615})(StorageAccessFramework || (StorageAccessFramework = {})); 616//# sourceMappingURL=FileSystem.js.map