Brak opisu

index.js.flow 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // @flow strict
  2. declare class AndroidApi {
  3. actionViewIntent(path: string, mime?: string): Promise<void>;
  4. addCompleteDownload(options: AndroidDownloadOption): Promise<void>;
  5. getContentIntent(mime: string): Promise<string>;
  6. getSDCardApplicationDir(): Promise<string>;
  7. getSDCardDir(): Promise<string>;
  8. }
  9. declare class FetchBlobResponse {
  10. data: string;
  11. respInfo: RNFetchBlobResponseInfo;
  12. taskId: string;
  13. type: "utf8" | "base64" | "path";
  14. array(): Promise<number[]>;
  15. base64(): string | Promise<string>;
  16. blob(): Promise<Blob>;
  17. flush(): Promise<void>;
  18. info(): RNFetchBlobResponseInfo;
  19. // $FlowExpectedError Not possible to specify in strict mode.
  20. json(): any;
  21. path(): string;
  22. readFile(encoding: Encoding): ?Promise<number[] | string>;
  23. readStream(encoding: Encoding): ?Promise<RNFetchBlobReadStream>;
  24. session(name: string): ?RNFetchBlobSession;
  25. text(): string | Promise<string>;
  26. }
  27. declare class FsApi {
  28. RNFetchBlobSession: RNFetchBlobSession;
  29. dirs: Dirs;
  30. appendFile(path: string, data: string | number[], encoding?: Encoding | "uri"): Promise<number>;
  31. asset(path: string): string;
  32. cp(path: string, dest: string): Promise<boolean>;
  33. createFile(path: string, data: string, encoding: Encoding | "uri"): Promise<string>;
  34. df(): Promise<AndroidFsStat | IosFsStat>;
  35. exists(path: string): Promise<boolean>;
  36. hash(path: string, algorithm: HashAlgorithm): Promise<string>;
  37. isDir(path: string): Promise<boolean>;
  38. ls(path: string): Promise<string[]>;
  39. lstat(path: string): Promise<RNFetchBlobStat[]>;
  40. mkdir(path: string): Promise<boolean>;
  41. mv(path: string, dest: string): Promise<boolean>;
  42. pathForAppGroup(groupName: string): Promise<string>;
  43. readFile(path: string, encoding: Encoding, bufferSize?: number): Promise<number[] | string>;
  44. readStream(path: string, encoding: Encoding, bufferSize?: number, tick?: number): Promise<RNFetchBlobReadStream>;
  45. scanFile(pairs: {mime: string, path: string}[]): Promise<void>;
  46. session(name: string): RNFetchBlobSession;
  47. slice(src: string, dest: string, start: number, end: number): Promise<string>;
  48. stat(path: string): Promise<RNFetchBlobStat>;
  49. unlink(path: string): Promise<void>;
  50. writeFile(path: string, data: string | number[], encoding?: Encoding | "uri"): Promise<number>;
  51. writeStream(path: string, encoding: Encoding, append?: boolean): Promise<RNFetchBlobWriteStream>;
  52. }
  53. declare class IosApi {
  54. excludeFromBackupKey(path: string): Promise<void>;
  55. openDocument(path: string, scheme?: string): Promise<void>;
  56. previewDocument(path: string, scheme?: string): Promise<void>;
  57. }
  58. declare class RNFetchBlobReadStream {
  59. bufferSize?: number;
  60. closed: boolean;
  61. encoding: Encoding;
  62. path: string;
  63. tick: number;
  64. onData(fn: (chunk: string) => void): void;
  65. onEnd(fn: () => void): void;
  66. onError(fn: (err: Error) => void): void;
  67. open(): void;
  68. }
  69. declare class RNFetchBlobSession {
  70. static getSession(name: string): RNFetchBlobSession;
  71. static removeSession(name: string): void;
  72. static setSession(name: string, val: RNFetchBlobSession): void;
  73. name: string;
  74. add(path: string): RNFetchBlobSession;
  75. constructor(name: string, list: string[]): RNFetchBlobSession;
  76. dispose(): Promise<void>;
  77. list(): string[];
  78. remove(path: string): RNFetchBlobSession;
  79. }
  80. declare class RNFetchBlobWriteStream {
  81. append: boolean;
  82. encoding: string;
  83. id: string;
  84. close(): void;
  85. write(data: string): Promise<void>;
  86. }
  87. declare class RNFetchBlob {
  88. android: AndroidApi;
  89. base64: {+decode: (input: string) => string, +encode: (input: string) => string};
  90. fs: FsApi;
  91. ios: IosApi;
  92. config(options: RNFetchBlobConfig): {fetch: (method: Methods, url: string, headers?: {[key: string]: string}, body?: string | FormField[]) => StatefulPromise<FetchBlobResponse>};
  93. fetch(method: Methods, url: string, headers?: {[key: string]: string}, body?: string | FormField[]): StatefulPromise<FetchBlobResponse>;
  94. session(name: string): RNFetchBlobSession;
  95. wrap(path: string): string;
  96. }
  97. declare class StatefulPromise<T> extends Promise<T> {
  98. cancel(callback?: (error: ?string, taskId: ?string) => void): void;
  99. expire(callback: () => void): StatefulPromise<void>;
  100. progress(config: {count?: number, interval?: number} | ProgressCallback, callback?: ProgressCallback): StatefulPromise<T>;
  101. stateChange(callback: (state: RNFetchBlobResponseInfo) => void): StatefulPromise<T>;
  102. uploadProgress(config: {count?: number, interval?: number} | UploadProgressCallback, callback?: UploadProgressCallback): StatefulPromise<T>;
  103. }
  104. export type AddAndroidDownloads = {
  105. description?: string,
  106. mediaScannable?: boolean,
  107. mime?: string,
  108. notification?: boolean,
  109. path?: string,
  110. title?: string,
  111. useDownloadManager?: boolean
  112. };
  113. export type AndroidDownloadOption = {
  114. description?: string,
  115. mime?: string,
  116. path: string,
  117. showNotification?: boolean,
  118. title?: string
  119. };
  120. export type AndroidFsStat = {
  121. external_free: number,
  122. external_total: number,
  123. internal_free: number,
  124. internal_total: number
  125. };
  126. export type Dirs = {
  127. CacheDir: string,
  128. DCIMDir: string,
  129. DocumentDir: string,
  130. DownloadDir: string,
  131. LibraryDir: string,
  132. MainBundleDir: string,
  133. MovieDir: string,
  134. MusicDir: string,
  135. PictureDir: string,
  136. SDCardApplicationDir: string,
  137. SDCardDir: string
  138. };
  139. export type Encoding = "utf8" | "ascii" | "base64";
  140. export type FormField = {data: string, filename?: string, name: string, type?: string};
  141. export type HashAlgorithm = "md5" | "sha1" | "sha224" | "sha256" | "sha384" | "sha512";
  142. export type IosFsStat = {free: number, total: number};
  143. export type Methods = "POST" | "GET" | "DELETE" | "PUT" | "post" | "get" | "delete" | "put";
  144. export type ProgressCallback = (received: number, total: number) => void;
  145. export type RNFetchBlobConfig = {
  146. IOSBackgroundTask?: boolean,
  147. addAndroidDownloads?: AddAndroidDownloads,
  148. appendExt?: string,
  149. fileCache?: boolean,
  150. indicator?: boolean,
  151. overwrite?: boolean,
  152. path?: string,
  153. session?: string,
  154. timeout?: number,
  155. trusty?: boolean
  156. };
  157. export type RNFetchBlobResponseInfo = {
  158. headers: {[fieldName: string]: string},
  159. redirects: string[],
  160. respType: "text" | "blob" | "" | "json",
  161. rnfbEncode: "path" | Encoding,
  162. state: string,
  163. status: number,
  164. taskId: string,
  165. timeout: boolean
  166. };
  167. export type RNFetchBlobStat = {
  168. filename: string,
  169. lastModified: number,
  170. path: string,
  171. size: number,
  172. type: "directory" | "file" | "asset"
  173. };
  174. export type UploadProgressCallback = (sent: number, total: number) => void;
  175. declare export default RNFetchBlob;