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qB,EAAE;YAC7C,MAAM,IAAI,mBAAmB,CAC3B,kBAAkB,EAClB,2CAA2C,CAC5C,CAAC;SACH;QACD,OAAO,MAAM,kBAAkB,CAAC,qBAAqB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACpE,CAAC;IARqB,yCAAkB,qBAQvC,CAAA;IAEM,KAAK,UAAU,kBAAkB,CAAC,SAAiB,EAAE,OAAe;QACzE,IAAI,CAAC,kBAAkB,CAAC,qBAAqB,EAAE;YAC7C,MAAM,IAAI,mBAAmB,CAC3B,kBAAkB,EAClB,2CAA2C,CAC5C,CAAC;SACH;QACD,OAAO,MAAM,kBAAkB,CAAC,qBAAqB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAC5E,CAAC;IARqB,yCAAkB,qBAQvC,CAAA;IAEM,KAAK,UAAU,eAAe,CACnC,SAAiB,EACjB,QAAgB,EAChB,QAAgB;QAEhB,IAAI,CAAC,kBAAkB,CAAC,kBAAkB,EAAE;YAC1C,MAAM,IAAI,mBAAmB,CAAC,kBAAkB,EAAE,wCAAwC,CAAC,CAAC;SAC7F;QACD,OAAO,MAAM,kBAAkB,CAAC,kBAAkB,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACpF,CAAC;IATqB,sCAAe,kBASpC,CAAA;IAEY,yCAAkB,GAAG,sBAAsB,CAAC;IAC5C,wCAAiB,GAAG,qBAAqB,CAAC;IAC1C,kCAAW,GAAG,eAAe,CAAC;IAC9B,gCAAS,GAAG,aAAa,CAAC;IAC1B,gCAAS,GAAG,aAAa,CAAC;AACzC,CAAC,EAtDgB,sBAAsB,KAAtB,sBAAsB,QAsDtC","sourcesContent":["import { EventEmitter, Subscription, UnavailabilityError } from '@unimodules/core';\nimport { Platform } from 'react-native';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport ExponentFileSystem from './ExponentFileSystem';\nimport {\n DownloadOptions,\n DownloadPauseState,\n DownloadProgressCallback,\n DownloadProgressData,\n DownloadResult,\n EncodingType,\n FileInfo,\n FileSystemAcceptedUploadHttpMethod,\n FileSystemDownloadResult,\n FileSystemRequestDirectoryPermissionsResult,\n FileSystemSessionType,\n FileSystemUploadOptions,\n FileSystemUploadResult,\n FileSystemUploadType,\n ProgressEvent,\n ReadingOptions,\n WritingOptions,\n} from './FileSystem.types';\n\nif (!ExponentFileSystem) {\n console.warn(\n \"No native ExponentFileSystem module found, are you sure the expo-file-system's module is linked properly?\"\n );\n}\n// Prevent webpack from pruning this.\nconst _unused = new EventEmitter(ExponentFileSystem); // eslint-disable-line\n\nexport {\n DownloadOptions,\n DownloadPauseState,\n DownloadProgressCallback,\n DownloadProgressData,\n DownloadResult,\n EncodingType,\n FileInfo,\n FileSystemDownloadResult,\n FileSystemRequestDirectoryPermissionsResult,\n FileSystemAcceptedUploadHttpMethod,\n FileSystemSessionType,\n FileSystemUploadOptions,\n FileSystemUploadResult,\n FileSystemUploadType,\n ProgressEvent,\n ReadingOptions,\n WritingOptions,\n};\n\nfunction normalizeEndingSlash(p: string | null): string | null {\n if (p != null) {\n return p.replace(/\\/*$/, '') + '/';\n }\n return null;\n}\n\nexport const documentDirectory = normalizeEndingSlash(ExponentFileSystem.documentDirectory);\nexport const cacheDirectory = normalizeEndingSlash(ExponentFileSystem.cacheDirectory);\n\nexport const { bundledAssets, bundleDirectory } = ExponentFileSystem;\n\nexport async function getInfoAsync(\n fileUri: string,\n options: { md5?: boolean; size?: boolean } = {}\n): Promise<FileInfo> {\n if (!ExponentFileSystem.getInfoAsync) {\n throw new UnavailabilityError('expo-file-system', 'getInfoAsync');\n }\n return await ExponentFileSystem.getInfoAsync(fileUri, options);\n}\n\nexport async function readAsStringAsync(\n fileUri: string,\n options?: ReadingOptions\n): Promise<string> {\n if (!ExponentFileSystem.readAsStringAsync) {\n throw new UnavailabilityError('expo-file-system', 'readAsStringAsync');\n }\n return await ExponentFileSystem.readAsStringAsync(fileUri, options || {});\n}\n\nexport async function getContentUriAsync(fileUri: string): Promise<string> {\n if (Platform.OS === 'android') {\n if (!ExponentFileSystem.getContentUriAsync) {\n throw new UnavailabilityError('expo-file-system', 'getContentUriAsync');\n }\n return await ExponentFileSystem.getContentUriAsync(fileUri);\n } else {\n return new Promise(function(resolve, reject) {\n resolve(fileUri);\n });\n }\n}\n\nexport async function writeAsStringAsync(\n fileUri: string,\n contents: string,\n options: WritingOptions = {}\n): Promise<void> {\n if (!ExponentFileSystem.writeAsStringAsync) {\n throw new UnavailabilityError('expo-file-system', 'writeAsStringAsync');\n }\n return await ExponentFileSystem.writeAsStringAsync(fileUri, contents, options);\n}\n\nexport async function deleteAsync(\n fileUri: string,\n options: { idempotent?: boolean } = {}\n): Promise<void> {\n if (!ExponentFileSystem.deleteAsync) {\n throw new UnavailabilityError('expo-file-system', 'deleteAsync');\n }\n return await ExponentFileSystem.deleteAsync(fileUri, options);\n}\n\nexport async function deleteLegacyDocumentDirectoryAndroid(): Promise<void> {\n if (Platform.OS !== 'android' || documentDirectory == null) {\n return;\n }\n const legacyDocumentDirectory = `${documentDirectory}ExperienceData/`;\n return await deleteAsync(legacyDocumentDirectory, { idempotent: true });\n}\n\nexport async function moveAsync(options: { from: string; to: string }): Promise<void> {\n if (!ExponentFileSystem.moveAsync) {\n throw new UnavailabilityError('expo-file-system', 'moveAsync');\n }\n return await ExponentFileSystem.moveAsync(options);\n}\n\nexport async function copyAsync(options: { from: string; to: string }): Promise<void> {\n if (!ExponentFileSystem.copyAsync) {\n throw new UnavailabilityError('expo-file-system', 'copyAsync');\n }\n return await ExponentFileSystem.copyAsync(options);\n}\n\nexport async function makeDirectoryAsync(\n fileUri: string,\n options: { intermediates?: boolean } = {}\n): Promise<void> {\n if (!ExponentFileSystem.makeDirectoryAsync) {\n throw new UnavailabilityError('expo-file-system', 'makeDirectoryAsync');\n }\n return await ExponentFileSystem.makeDirectoryAsync(fileUri, options);\n}\n\nexport async function readDirectoryAsync(fileUri: string): Promise<string[]> {\n if (!ExponentFileSystem.readDirectoryAsync) {\n throw new UnavailabilityError('expo-file-system', 'readDirectoryAsync');\n }\n return await ExponentFileSystem.readDirectoryAsync(fileUri, {});\n}\n\nexport async function getFreeDiskStorageAsync(): Promise<number> {\n if (!ExponentFileSystem.getFreeDiskStorageAsync) {\n throw new UnavailabilityError('expo-file-system', 'getFreeDiskStorageAsync');\n }\n return await ExponentFileSystem.getFreeDiskStorageAsync();\n}\n\nexport async function getTotalDiskCapacityAsync(): Promise<number> {\n if (!ExponentFileSystem.getTotalDiskCapacityAsync) {\n throw new UnavailabilityError('expo-file-system', 'getTotalDiskCapacityAsync');\n }\n return await ExponentFileSystem.getTotalDiskCapacityAsync();\n}\n\nexport async function downloadAsync(\n uri: string,\n fileUri: string,\n options: DownloadOptions = {}\n): Promise<FileSystemDownloadResult> {\n if (!ExponentFileSystem.downloadAsync) {\n throw new UnavailabilityError('expo-file-system', 'downloadAsync');\n }\n\n return await ExponentFileSystem.downloadAsync(uri, fileUri, {\n sessionType: FileSystemSessionType.BACKGROUND,\n ...options,\n });\n}\n\nexport async function uploadAsync(\n url: string,\n fileUri: string,\n options: FileSystemUploadOptions = {}\n): Promise<FileSystemUploadResult> {\n if (!ExponentFileSystem.uploadAsync) {\n throw new UnavailabilityError('expo-file-system', 'uploadAsync');\n }\n\n return await ExponentFileSystem.uploadAsync(url, fileUri, {\n sessionType: FileSystemSessionType.BACKGROUND,\n uploadType: FileSystemUploadType.BINARY_CONTENT,\n ...options,\n httpMethod: (options.httpMethod || 'POST').toUpperCase(),\n });\n}\n\nexport function createDownloadResumable(\n uri: string,\n fileUri: string,\n options?: DownloadOptions,\n callback?: DownloadProgressCallback,\n resumeData?: string\n): DownloadResumable {\n return new DownloadResumable(uri, fileUri, options, callback, resumeData);\n}\n\nexport class DownloadResumable {\n _uuid: string;\n _url: string;\n _fileUri: string;\n _options: DownloadOptions;\n _resumeData?: string;\n _callback?: DownloadProgressCallback;\n _subscription?: Subscription | null;\n _emitter: EventEmitter;\n\n constructor(\n url: string,\n fileUri: string,\n options: DownloadOptions = {},\n callback?: DownloadProgressCallback,\n resumeData?: string\n ) {\n this._uuid = uuidv4();\n this._url = url;\n this._fileUri = fileUri;\n this._options = options;\n this._resumeData = resumeData;\n this._callback = callback;\n this._subscription = null;\n this._emitter = new EventEmitter(ExponentFileSystem);\n }\n\n async downloadAsync(): Promise<FileSystemDownloadResult | undefined> {\n if (!ExponentFileSystem.downloadResumableStartAsync) {\n throw new UnavailabilityError('expo-file-system', 'downloadResumableStartAsync');\n }\n this._addSubscription();\n return await ExponentFileSystem.downloadResumableStartAsync(\n this._url,\n this._fileUri,\n this._uuid,\n this._options,\n this._resumeData\n );\n }\n\n async pauseAsync(): Promise<DownloadPauseState> {\n if (!ExponentFileSystem.downloadResumablePauseAsync) {\n throw new UnavailabilityError('expo-file-system', 'downloadResumablePauseAsync');\n }\n const pauseResult = await ExponentFileSystem.downloadResumablePauseAsync(this._uuid);\n this._removeSubscription();\n if (pauseResult) {\n this._resumeData = pauseResult.resumeData;\n return this.savable();\n } else {\n throw new Error('Unable to generate a savable pause state');\n }\n }\n\n async resumeAsync(): Promise<FileSystemDownloadResult | undefined> {\n if (!ExponentFileSystem.downloadResumableStartAsync) {\n throw new UnavailabilityError('expo-file-system', 'downloadResumableStartAsync');\n }\n this._addSubscription();\n return await ExponentFileSystem.downloadResumableStartAsync(\n this._url,\n this._fileUri,\n this._uuid,\n this._options,\n this._resumeData\n );\n }\n\n savable(): DownloadPauseState {\n return {\n url: this._url,\n fileUri: this._fileUri,\n options: this._options,\n resumeData: this._resumeData,\n };\n }\n\n _addSubscription(): void {\n if (this._subscription) {\n return;\n }\n this._subscription = this._emitter.addListener(\n 'expo-file-system.downloadProgress',\n (event: ProgressEvent) => {\n if (event.uuid === this._uuid) {\n const callback = this._callback;\n if (callback) {\n callback(event.data);\n }\n }\n }\n );\n }\n\n _removeSubscription(): void {\n if (!this._subscription) {\n return;\n }\n this._emitter.removeSubscription(this._subscription);\n this._subscription = null;\n }\n}\n\nconst baseReadAsStringAsync = readAsStringAsync;\nconst baseWriteAsStringAsync = writeAsStringAsync;\nconst baseDeleteAsync = deleteAsync;\nconst baseMoveAsync = moveAsync;\nconst baseCopyAsync = copyAsync;\n/**\n * Android only\n */\nexport namespace StorageAccessFramework {\n export function getUriForDirectoryInRoot(folderName: string) {\n return `content://com.android.externalstorage.documents/tree/primary:${folderName}/document/primary:${folderName}`;\n }\n\n export async function requestDirectoryPermissionsAsync(\n initialFileUrl: string | null = null\n ): Promise<FileSystemRequestDirectoryPermissionsResult> {\n if (!ExponentFileSystem.requestDirectoryPermissionsAsync) {\n throw new UnavailabilityError(\n 'expo-file-system',\n 'StorageAccessFramework.requestDirectoryPermissionsAsync'\n );\n }\n\n return await ExponentFileSystem.requestDirectoryPermissionsAsync(initialFileUrl);\n }\n\n export async function readDirectoryAsync(dirUri: string): Promise<string[]> {\n if (!ExponentFileSystem.readSAFDirectoryAsync) {\n throw new UnavailabilityError(\n 'expo-file-system',\n 'StorageAccessFramework.readDirectoryAsync'\n );\n }\n return await ExponentFileSystem.readSAFDirectoryAsync(dirUri, {});\n }\n\n export async function makeDirectoryAsync(parentUri: string, dirName: string): Promise<string> {\n if (!ExponentFileSystem.makeSAFDirectoryAsync) {\n throw new UnavailabilityError(\n 'expo-file-system',\n 'StorageAccessFramework.makeDirectoryAsync'\n );\n }\n return await ExponentFileSystem.makeSAFDirectoryAsync(parentUri, dirName);\n }\n\n export async function createFileAsync(\n parentUri: string,\n fileName: string,\n mimeType: string\n ): Promise<string> {\n if (!ExponentFileSystem.createSAFFileAsync) {\n throw new UnavailabilityError('expo-file-system', 'StorageAccessFramework.createFileAsync');\n }\n return await ExponentFileSystem.createSAFFileAsync(parentUri, fileName, mimeType);\n }\n\n export const writeAsStringAsync = baseWriteAsStringAsync;\n export const readAsStringAsync = baseReadAsStringAsync;\n export const deleteAsync = baseDeleteAsync;\n export const moveAsync = baseMoveAsync;\n export const copyAsync = baseCopyAsync;\n}\n"]} |