definitions.d.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. import type { HttpOptions, PermissionState, PluginListenerHandle } from '@capacitor/core';
  2. export type CallbackID = string;
  3. export interface PermissionStatus {
  4. publicStorage: PermissionState;
  5. }
  6. export declare enum Directory {
  7. /**
  8. * The Documents directory.
  9. * On iOS it's the app's documents directory.
  10. * Use this directory to store user-generated content.
  11. * On Android it's the Public Documents folder, so it's accessible from other apps.
  12. * It's not accessible on Android 10 unless the app enables legacy External Storage
  13. * by adding `android:requestLegacyExternalStorage="true"` in the `application` tag
  14. * in the `AndroidManifest.xml`.
  15. * On Android 11 or newer the app can only access the files/folders the app created.
  16. *
  17. * @since 1.0.0
  18. */
  19. Documents = "DOCUMENTS",
  20. /**
  21. * The Data directory.
  22. * On iOS it will use the Documents directory.
  23. * On Android it's the directory holding application files.
  24. * Files will be deleted when the application is uninstalled.
  25. *
  26. * @since 1.0.0
  27. */
  28. Data = "DATA",
  29. /**
  30. * The Library directory.
  31. * On iOS it will use the Library directory.
  32. * On Android it's the directory holding application files.
  33. * Files will be deleted when the application is uninstalled.
  34. *
  35. * @since 1.1.0
  36. */
  37. Library = "LIBRARY",
  38. /**
  39. * The Cache directory.
  40. * Can be deleted in cases of low memory, so use this directory to write app-specific files.
  41. * that your app can re-create easily.
  42. *
  43. * @since 1.0.0
  44. */
  45. Cache = "CACHE",
  46. /**
  47. * The external directory.
  48. * On iOS it will use the Documents directory.
  49. * On Android it's the directory on the primary shared/external
  50. * storage device where the application can place persistent files it owns.
  51. * These files are internal to the applications, and not typically visible
  52. * to the user as media.
  53. * Files will be deleted when the application is uninstalled.
  54. *
  55. * @since 1.0.0
  56. */
  57. External = "EXTERNAL",
  58. /**
  59. * The external storage directory.
  60. * On iOS it will use the Documents directory.
  61. * On Android it's the primary shared/external storage directory.
  62. * It's not accessible on Android 10 unless the app enables legacy External Storage
  63. * by adding `android:requestLegacyExternalStorage="true"` in the `application` tag
  64. * in the `AndroidManifest.xml`.
  65. * It's not accessible on Android 11 or newer.
  66. *
  67. * @since 1.0.0
  68. */
  69. ExternalStorage = "EXTERNAL_STORAGE",
  70. /**
  71. * The external cache directory.
  72. * On iOS it will use the Documents directory.
  73. * On Android it's the primary shared/external cache.
  74. *
  75. * @since 7.1.0
  76. */
  77. ExternalCache = "EXTERNAL_CACHE",
  78. /**
  79. * The Library directory without cloud backup. Used in iOS.
  80. * On Android it's the directory holding application files.
  81. *
  82. * @since 7.1.0
  83. */
  84. LibraryNoCloud = "LIBRARY_NO_CLOUD",
  85. /**
  86. * A temporary directory for iOS.
  87. * On Android it's the directory holding the application cache.
  88. *
  89. * @since 7.1.0
  90. */
  91. Temporary = "TEMPORARY"
  92. }
  93. export declare enum Encoding {
  94. /**
  95. * Eight-bit UCS Transformation Format
  96. *
  97. * @since 1.0.0
  98. */
  99. UTF8 = "utf8",
  100. /**
  101. * Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the
  102. * Unicode character set
  103. * This encoding is only supported on Android.
  104. *
  105. * @since 1.0.0
  106. */
  107. ASCII = "ascii",
  108. /**
  109. * Sixteen-bit UCS Transformation Format, byte order identified by an
  110. * optional byte-order mark
  111. * This encoding is only supported on Android.
  112. *
  113. * @since 1.0.0
  114. */
  115. UTF16 = "utf16"
  116. }
  117. export interface WriteFileOptions {
  118. /**
  119. * The path of the file to write
  120. *
  121. * @since 1.0.0
  122. */
  123. path: string;
  124. /**
  125. * The data to write
  126. *
  127. * Note: Blob data is only supported on Web.
  128. *
  129. * @since 1.0.0
  130. */
  131. data: string | Blob;
  132. /**
  133. * The `Directory` to store the file in
  134. *
  135. * @since 1.0.0
  136. */
  137. directory?: Directory;
  138. /**
  139. * The encoding to write the file in. If not provided, data
  140. * is written as base64 encoded.
  141. *
  142. * Pass Encoding.UTF8 to write data as string
  143. *
  144. * @since 1.0.0
  145. */
  146. encoding?: Encoding;
  147. /**
  148. * Whether to create any missing parent directories.
  149. *
  150. * @default false
  151. * @since 1.0.0
  152. */
  153. recursive?: boolean;
  154. }
  155. export interface AppendFileOptions {
  156. /**
  157. * The path of the file to append
  158. *
  159. * @since 1.0.0
  160. */
  161. path: string;
  162. /**
  163. * The data to write
  164. *
  165. * @since 1.0.0
  166. */
  167. data: string;
  168. /**
  169. * The `Directory` to store the file in
  170. *
  171. * @since 1.0.0
  172. */
  173. directory?: Directory;
  174. /**
  175. * The encoding to write the file in. If not provided, data
  176. * is written as base64 encoded.
  177. *
  178. * Pass Encoding.UTF8 to write data as string
  179. *
  180. * @since 1.0.0
  181. */
  182. encoding?: Encoding;
  183. }
  184. export interface ReadFileOptions {
  185. /**
  186. * The path of the file to read
  187. *
  188. * @since 1.0.0
  189. */
  190. path: string;
  191. /**
  192. * The `Directory` to read the file from
  193. *
  194. * @since 1.0.0
  195. */
  196. directory?: Directory;
  197. /**
  198. * The encoding to read the file in, if not provided, data
  199. * is read as binary and returned as base64 encoded.
  200. *
  201. * Pass Encoding.UTF8 to read data as string
  202. *
  203. * @since 1.0.0
  204. */
  205. encoding?: Encoding;
  206. }
  207. export interface ReadFileInChunksOptions extends ReadFileOptions {
  208. /**
  209. * Size of the chunks in bytes.
  210. *
  211. * @since 7.1.0
  212. */
  213. chunkSize: number;
  214. }
  215. export interface DeleteFileOptions {
  216. /**
  217. * The path of the file to delete
  218. *
  219. * @since 1.0.0
  220. */
  221. path: string;
  222. /**
  223. * The `Directory` to delete the file from
  224. *
  225. * @since 1.0.0
  226. */
  227. directory?: Directory;
  228. }
  229. export interface MkdirOptions {
  230. /**
  231. * The path of the new directory
  232. *
  233. * @since 1.0.0
  234. */
  235. path: string;
  236. /**
  237. * The `Directory` to make the new directory in
  238. *
  239. * @since 1.0.0
  240. */
  241. directory?: Directory;
  242. /**
  243. * Whether to create any missing parent directories as well.
  244. *
  245. * @default false
  246. * @since 1.0.0
  247. */
  248. recursive?: boolean;
  249. }
  250. export interface RmdirOptions {
  251. /**
  252. * The path of the directory to remove
  253. *
  254. * @since 1.0.0
  255. */
  256. path: string;
  257. /**
  258. * The `Directory` to remove the directory from
  259. *
  260. * @since 1.0.0
  261. */
  262. directory?: Directory;
  263. /**
  264. * Whether to recursively remove the contents of the directory
  265. *
  266. * @default false
  267. * @since 1.0.0
  268. */
  269. recursive?: boolean;
  270. }
  271. export interface ReaddirOptions {
  272. /**
  273. * The path of the directory to read
  274. *
  275. * @since 1.0.0
  276. */
  277. path: string;
  278. /**
  279. * The `Directory` to list files from
  280. *
  281. * @since 1.0.0
  282. */
  283. directory?: Directory;
  284. }
  285. export interface GetUriOptions {
  286. /**
  287. * The path of the file to get the URI for
  288. *
  289. * @since 1.0.0
  290. */
  291. path: string;
  292. /**
  293. * The `Directory` to get the file under
  294. *
  295. * @since 1.0.0
  296. */
  297. directory: Directory;
  298. }
  299. export interface StatOptions {
  300. /**
  301. * The path of the file to get data about
  302. *
  303. * @since 1.0.0
  304. */
  305. path: string;
  306. /**
  307. * The `Directory` to get the file under
  308. *
  309. * @since 1.0.0
  310. */
  311. directory?: Directory;
  312. }
  313. export interface CopyOptions {
  314. /**
  315. * The existing file or directory
  316. *
  317. * @since 1.0.0
  318. */
  319. from: string;
  320. /**
  321. * The destination file or directory
  322. *
  323. * @since 1.0.0
  324. */
  325. to: string;
  326. /**
  327. * The `Directory` containing the existing file or directory
  328. *
  329. * @since 1.0.0
  330. */
  331. directory?: Directory;
  332. /**
  333. * The `Directory` containing the destination file or directory. If not supplied will use the 'directory'
  334. * parameter as the destination
  335. *
  336. * @since 1.0.0
  337. */
  338. toDirectory?: Directory;
  339. }
  340. export type RenameOptions = CopyOptions;
  341. export interface ReadFileResult {
  342. /**
  343. * The representation of the data contained in the file
  344. *
  345. * Note: Blob is only available on Web. On native, the data is returned as a string.
  346. *
  347. * @since 1.0.0
  348. */
  349. data: string | Blob;
  350. }
  351. export interface WriteFileResult {
  352. /**
  353. * The uri where the file was written into
  354. *
  355. * @since 1.0.0
  356. */
  357. uri: string;
  358. }
  359. export interface ReaddirResult {
  360. /**
  361. * List of files and directories inside the directory
  362. *
  363. * @since 1.0.0
  364. */
  365. files: FileInfo[];
  366. }
  367. export interface FileInfo {
  368. /**
  369. * Name of the file or directory.
  370. *
  371. * @since 7.1.0
  372. */
  373. name: string;
  374. /**
  375. * Type of the file.
  376. *
  377. * @since 4.0.0
  378. */
  379. type: 'directory' | 'file';
  380. /**
  381. * Size of the file in bytes.
  382. *
  383. * @since 4.0.0
  384. */
  385. size: number;
  386. /**
  387. * Time of creation in milliseconds.
  388. *
  389. * It's not available on Android 7 and older devices.
  390. *
  391. * @since 7.1.0
  392. */
  393. ctime?: number;
  394. /**
  395. * Time of last modification in milliseconds.
  396. *
  397. * @since 7.1.0
  398. */
  399. mtime: number;
  400. /**
  401. * The uri of the file.
  402. *
  403. * @since 4.0.0
  404. */
  405. uri: string;
  406. }
  407. export interface GetUriResult {
  408. /**
  409. * The uri of the file
  410. *
  411. * @since 1.0.0
  412. */
  413. uri: string;
  414. }
  415. export type StatResult = FileInfo;
  416. export interface CopyResult {
  417. /**
  418. * The uri where the file was copied into
  419. *
  420. * @since 4.0.0
  421. */
  422. uri: string;
  423. }
  424. export interface DownloadFileOptions extends HttpOptions {
  425. /**
  426. * The path the downloaded file should be moved to.
  427. *
  428. * @since 5.1.0
  429. */
  430. path: string;
  431. /**
  432. * The directory to write the file to.
  433. * If this option is used, filePath can be a relative path rather than absolute.
  434. * The default is the `DATA` directory.
  435. *
  436. * @since 5.1.0
  437. */
  438. directory?: Directory;
  439. /**
  440. * An optional listener function to receive downloaded progress events.
  441. * If this option is used, progress event should be dispatched on every chunk received.
  442. * Chunks are throttled to every 100ms on Android/iOS to avoid slowdowns.
  443. *
  444. * @since 5.1.0
  445. */
  446. progress?: boolean;
  447. /**
  448. * Whether to create any missing parent directories.
  449. *
  450. * @default false
  451. * @since 5.1.2
  452. */
  453. recursive?: boolean;
  454. }
  455. export interface DownloadFileResult {
  456. /**
  457. * The path the file was downloaded to.
  458. *
  459. * @since 5.1.0
  460. */
  461. path?: string;
  462. /**
  463. * The blob data of the downloaded file.
  464. * This is only available on web.
  465. *
  466. * @since 5.1.0
  467. */
  468. blob?: Blob;
  469. }
  470. export interface ProgressStatus {
  471. /**
  472. * The url of the file being downloaded.
  473. *
  474. * @since 5.1.0
  475. */
  476. url: string;
  477. /**
  478. * The number of bytes downloaded so far.
  479. *
  480. * @since 5.1.0
  481. */
  482. bytes: number;
  483. /**
  484. * The total number of bytes to download for this file.
  485. *
  486. * @since 5.1.0
  487. */
  488. contentLength: number;
  489. }
  490. /**
  491. * Callback for receiving chunks read from a file, or error if something went wrong.
  492. *
  493. * @since 7.1.0
  494. */
  495. export type ReadFileInChunksCallback = (chunkRead: ReadFileResult | null, err?: any) => void;
  496. /**
  497. * A listener function that receives progress events.
  498. *
  499. * @since 5.1.0
  500. */
  501. export type ProgressListener = (progress: ProgressStatus) => void;
  502. export interface FilesystemPlugin {
  503. /**
  504. * Check read/write permissions.
  505. * Required on Android, only when using `Directory.Documents` or
  506. * `Directory.ExternalStorage`.
  507. *
  508. * @since 1.0.0
  509. */
  510. checkPermissions(): Promise<PermissionStatus>;
  511. /**
  512. * Request read/write permissions.
  513. * Required on Android, only when using `Directory.Documents` or
  514. * `Directory.ExternalStorage`.
  515. *
  516. * @since 1.0.0
  517. */
  518. requestPermissions(): Promise<PermissionStatus>;
  519. /**
  520. * Read a file from disk
  521. *
  522. * @since 1.0.0
  523. */
  524. readFile(options: ReadFileOptions): Promise<ReadFileResult>;
  525. /**
  526. * Read a file from disk, in chunks.
  527. * Native only (not available in web).
  528. * Use the callback to receive each read chunk.
  529. * If empty chunk is returned, it means file has been completely read.
  530. *
  531. * @since 7.1.0
  532. */
  533. readFileInChunks(options: ReadFileInChunksOptions, callback: ReadFileInChunksCallback): Promise<CallbackID>;
  534. /**
  535. * Write a file to disk in the specified location on device
  536. *
  537. * @since 1.0.0
  538. */
  539. writeFile(options: WriteFileOptions): Promise<WriteFileResult>;
  540. /**
  541. * Append to a file on disk in the specified location on device
  542. *
  543. * @since 1.0.0
  544. */
  545. appendFile(options: AppendFileOptions): Promise<void>;
  546. /**
  547. * Delete a file from disk
  548. *
  549. * @since 1.0.0
  550. */
  551. deleteFile(options: DeleteFileOptions): Promise<void>;
  552. /**
  553. * Create a directory.
  554. *
  555. * @since 1.0.0
  556. */
  557. mkdir(options: MkdirOptions): Promise<void>;
  558. /**
  559. * Remove a directory
  560. *
  561. * @since 1.0.0
  562. */
  563. rmdir(options: RmdirOptions): Promise<void>;
  564. /**
  565. * Return a list of files from the directory (not recursive)
  566. *
  567. * @since 1.0.0
  568. */
  569. readdir(options: ReaddirOptions): Promise<ReaddirResult>;
  570. /**
  571. * Return full File URI for a path and directory
  572. *
  573. * @since 1.0.0
  574. */
  575. getUri(options: GetUriOptions): Promise<GetUriResult>;
  576. /**
  577. * Return data about a file
  578. *
  579. * @since 1.0.0
  580. */
  581. stat(options: StatOptions): Promise<StatResult>;
  582. /**
  583. * Rename a file or directory
  584. *
  585. * @since 1.0.0
  586. */
  587. rename(options: RenameOptions): Promise<void>;
  588. /**
  589. * Copy a file or directory
  590. *
  591. * @since 1.0.0
  592. */
  593. copy(options: CopyOptions): Promise<CopyResult>;
  594. /**
  595. * Perform a http request to a server and download the file to the specified destination.
  596. *
  597. * This method has been deprecated since version 7.1.0.
  598. * We recommend using the @capacitor/file-transfer plugin instead, in conjunction with this plugin.
  599. *
  600. * @since 5.1.0
  601. * @deprecated Use the @capacitor/file-transfer plugin instead.
  602. */
  603. downloadFile(options: DownloadFileOptions): Promise<DownloadFileResult>;
  604. /**
  605. * Add a listener to file download progress events.
  606. *
  607. * This method has been deprecated since version 7.1.0.
  608. * We recommend using the @capacitor/file-transfer plugin instead, in conjunction with this plugin.
  609. *
  610. * @since 5.1.0
  611. * @deprecated Use the @capacitor/file-transfer plugin instead.
  612. */
  613. addListener(eventName: 'progress', listenerFunc: ProgressListener): Promise<PluginListenerHandle>;
  614. /**
  615. * Remove all listeners for this plugin.
  616. *
  617. * This method has been deprecated since version 7.1.0.
  618. * We recommend using the @capacitor/file-transfer plugin instead, in conjunction with this plugin.
  619. *
  620. * @since 5.2.0
  621. * @deprecated Use the @capacitor/file-transfer plugin instead.
  622. */
  623. removeAllListeners(): Promise<void>;
  624. }
  625. /**
  626. * Structure for errors returned by the plugin.
  627. *
  628. * `code` follows "OS-PLUG-FILE-XXXX" format
  629. *
  630. * @since 1.0.0
  631. */
  632. export type PluginError = {
  633. code: string;
  634. message: string;
  635. };
  636. /**
  637. * @deprecated Use `ReadFileOptions`.
  638. * @since 1.0.0
  639. */
  640. export type FileReadOptions = ReadFileOptions;
  641. /**
  642. * @deprecated Use `ReadFileResult`.
  643. * @since 1.0.0
  644. */
  645. export type FileReadResult = ReadFileResult;
  646. /**
  647. * @deprecated Use `WriteFileOptions`.
  648. * @since 1.0.0
  649. */
  650. export type FileWriteOptions = WriteFileOptions;
  651. /**
  652. * @deprecated Use `WriteFileResult`.
  653. * @since 1.0.0
  654. */
  655. export type FileWriteResult = WriteFileResult;
  656. /**
  657. * @deprecated Use `AppendFileOptions`.
  658. * @since 1.0.0
  659. */
  660. export type FileAppendOptions = AppendFileOptions;
  661. /**
  662. * @deprecated Use `DeleteFileOptions`.
  663. * @since 1.0.0
  664. */
  665. export type FileDeleteOptions = DeleteFileOptions;
  666. /**
  667. * @deprecated Use `Directory`.
  668. * @since 1.0.0
  669. */
  670. export declare const FilesystemDirectory: typeof Directory;
  671. /**
  672. * @deprecated Use `Encoding`.
  673. * @since 1.0.0
  674. */
  675. export declare const FilesystemEncoding: typeof Encoding;