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kBAAkB,CAAC,2BAA2B,EAAE;YACnD,MAAM,IAAI,mBAAmB,CAAC,kBAAkB,EAAE,6BAA6B,CAAC,CAAC;SAClF;QACD,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxB,OAAO,MAAM,kBAAkB,CAAC,2BAA2B,CACzD,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,WAAW,CACjB,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO;YACL,GAAG,EAAE,IAAI,CAAC,IAAI;YACd,OAAO,EAAE,IAAI,CAAC,QAAQ;YACtB,OAAO,EAAE,IAAI,CAAC,QAAQ;YACtB,UAAU,EAAE,IAAI,CAAC,WAAW;SAC7B,CAAC;IACJ,CAAC;IAED,gBAAgB;QACd,IAAI,IAAI,CAAC,aAAa,EAAE;YACtB,OAAO;SACR;QACD,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAC5C,2BAA2B,EAC3B,CAAC,KAAoB,EAAE,EAAE;YACvB,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,KAAK,EAAE;gBAC7B,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC;gBAChC,IAAI,QAAQ,EAAE;oBACZ,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;iBACtB;aACF;QACH,CAAC,CACF,CAAC;IACJ,CAAC;IAED,mBAAmB;QACjB,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,OAAO;SACR;QACD,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACrD,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import UUID from 'uuid-js';\nimport { Platform } from 'react-native';\nimport { EventEmitter, Subscription, UnavailabilityError } from '@unimodules/core';\n\nimport ExponentFileSystem from './ExponentFileSystem';\n\nimport {\n  DownloadOptions,\n  DownloadResult,\n  DownloadProgressCallback,\n  DownloadProgressData,\n  DownloadPauseState,\n  FileInfo,\n  EncodingType,\n  ReadingOptions,\n  WritingOptions,\n  ProgressEvent,\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  DownloadResult,\n  DownloadProgressCallback,\n  DownloadProgressData,\n  DownloadPauseState,\n  FileInfo,\n  EncodingType,\n  ReadingOptions,\n  WritingOptions,\n  ProgressEvent,\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<DownloadResult> {\n  if (!ExponentFileSystem.downloadAsync) {\n    throw new UnavailabilityError('expo-file-system', 'downloadAsync');\n  }\n  return await ExponentFileSystem.downloadAsync(uri, fileUri, options);\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 = UUID.create(4).toString();\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<DownloadResult | 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<DownloadResult | 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      'Exponent.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"]}