1export enum FileSystemSessionType {
2  /*
3   * Using this mode means that the downloading/uploading session on the native side will work even if the application is moved to background.
4   *
5   * If the task completes while the application is in background, the Promise will be either resolved immediately or (if the application execution has already been stopped) once the app is moved to foreground again.
6   */
7  BACKGROUND = 0,
8  /*
9   * Using this mode means that downloading/uploading session on the native side will be terminated once the application becomes inactive (e.g. when it goes to background).
10   * Bringing the application to foreground again would trigger Promise rejection.
11   */
12  FOREGROUND = 1,
13}
14
15export enum FileSystemUploadType {
16  BINARY_CONTENT = 0,
17  MULTIPART = 1,
18}
19
20export type DownloadOptions = {
21  md5?: boolean;
22  cache?: boolean;
23  headers?: Record<string, string>;
24  /*
25   * iOS only
26   */
27  sessionType?: FileSystemSessionType;
28};
29
30export type FileSystemHttpResult = {
31  headers: Record<string, string>;
32  status: number;
33  mimeType: string | null;
34};
35
36export type FileSystemDownloadResult = FileSystemHttpResult & {
37  uri: string;
38  md5?: string;
39};
40
41/**
42 * @deprecated Use `FileSystemDownloadResult` instead.
43 */
44export type DownloadResult = FileSystemDownloadResult;
45
46export type FileSystemUploadOptions = (
47  | {
48      uploadType?: FileSystemUploadType.BINARY_CONTENT;
49    }
50  | {
51      uploadType: FileSystemUploadType.MULTIPART;
52      fieldName?: string;
53      mimeType?: string;
54      parameters?: Record<string, string>;
55    }
56) & {
57  headers?: Record<string, string>;
58  httpMethod?: FileSystemAcceptedUploadHttpMethod;
59  sessionType?: FileSystemSessionType;
60};
61
62export type FileSystemUploadResult = FileSystemHttpResult & {
63  body: string;
64};
65
66export type FileSystemNetworkTaskProgressCallback<
67  T extends DownloadProgressData | UploadProgressData
68> = (data: T) => void;
69
70/**
71 * @deprecated use `NetworkTaskProgressCallback<DownloadProgressData>` instead
72 */
73export type DownloadProgressCallback = FileSystemNetworkTaskProgressCallback<DownloadProgressData>;
74
75export type DownloadProgressData = {
76  totalBytesWritten: number;
77  totalBytesExpectedToWrite: number;
78};
79
80export type UploadProgressData = {
81  totalByteSent: number;
82  totalBytesExpectedToSend: number;
83};
84
85export type DownloadPauseState = {
86  url: string;
87  fileUri: string;
88  options: DownloadOptions;
89  resumeData?: string;
90};
91
92export type FileInfo =
93  | {
94      exists: true;
95      uri: string;
96      size: number;
97      isDirectory: boolean;
98      modificationTime: number;
99      md5?: string;
100    }
101  | {
102      exists: false;
103      uri: string;
104      size: undefined;
105      isDirectory: false;
106      modificationTime: undefined;
107      md5: undefined;
108    };
109
110export enum EncodingType {
111  UTF8 = 'utf8',
112  Base64 = 'base64',
113}
114
115export type FileSystemAcceptedUploadHttpMethod = 'POST' | 'PUT' | 'PATCH';
116
117export type ReadingOptions = {
118  encoding?: EncodingType | 'utf8' | 'base64';
119  position?: number;
120  length?: number;
121};
122
123export type WritingOptions = {
124  encoding?: EncodingType | 'utf8' | 'base64';
125};
126
127export type ProgressEvent<T> = {
128  uuid: string;
129  data: T;
130};
131
132export type FileSystemRequestDirectoryPermissionsResult =
133  | {
134      granted: true;
135      directoryUri: string;
136    }
137  | {
138      granted: false;
139    };
140
141type PlatformMethod = (...args: any[]) => Promise<any>;
142
143export interface ExponentFileSystemModule {
144  readonly name: 'ExponentFileSystem';
145  readonly documentDirectory: string | null;
146  readonly cacheDirectory: string | null;
147  readonly bundledAssets: string | null;
148  readonly bundleDirectory: string | null;
149  readonly getInfoAsync?: PlatformMethod;
150  readonly readAsStringAsync?: PlatformMethod;
151  readonly writeAsStringAsync?: PlatformMethod;
152  readonly deleteAsync?: PlatformMethod;
153  readonly moveAsync?: PlatformMethod;
154  readonly copyAsync?: PlatformMethod;
155  readonly makeDirectoryAsync?: PlatformMethod;
156  readonly readDirectoryAsync?: PlatformMethod;
157  readonly downloadAsync?: PlatformMethod;
158  readonly uploadAsync?: PlatformMethod;
159  readonly downloadResumableStartAsync?: PlatformMethod;
160  readonly downloadResumablePauseAsync?: PlatformMethod;
161  readonly getContentUriAsync?: PlatformMethod;
162  readonly getFreeDiskStorageAsync?: PlatformMethod;
163  readonly getTotalDiskCapacityAsync?: PlatformMethod;
164  readonly requestDirectoryPermissionsAsync?: PlatformMethod;
165  readonly readSAFDirectoryAsync?: PlatformMethod;
166  readonly makeSAFDirectoryAsync?: PlatformMethod;
167  readonly createSAFFileAsync?: PlatformMethod;
168  readonly networkTaskCancelAsync?: PlatformMethod;
169  readonly uploadTaskStartAsync?: PlatformMethod;
170  startObserving?: () => void;
171  stopObserving?: () => void;
172  addListener: (eventName: string) => void;
173  removeListeners: (count: number) => void;
174}
175