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 type DownloadOptions = {
16  md5?: boolean;
17  cache?: boolean;
18  headers?: Record<string, string>;
19  /*
20   * iOS only
21   */
22  sessionType?: FileSystemSessionType;
23};
24
25export type FileSystemHttpResult = {
26  headers: Record<string, string>;
27  status: number;
28  mimeType: string | null;
29};
30
31export type FileSystemDownloadResult = FileSystemHttpResult & {
32  uri: string;
33  md5?: string;
34};
35
36/**
37 * @deprecated Use FileSystemDownloadResult instead.
38 */
39export type DownloadResult = FileSystemDownloadResult;
40
41export type FileSystemUploadOptions = {
42  headers?: Record<string, string>;
43  httpMethod?: FileSystemAcceptedUploadHttpMethod;
44  sessionType?: FileSystemSessionType;
45};
46
47export type FileSystemUploadResult = FileSystemHttpResult & {
48  body: string;
49};
50
51export type DownloadProgressCallback = (data: DownloadProgressData) => void;
52
53export type DownloadProgressData = {
54  totalBytesWritten: number;
55  totalBytesExpectedToWrite: number;
56};
57
58export type DownloadPauseState = {
59  url: string;
60  fileUri: string;
61  options: DownloadOptions;
62  resumeData?: string;
63};
64
65export type FileInfo =
66  | {
67      exists: true;
68      uri: string;
69      size: number;
70      isDirectory: boolean;
71      modificationTime: number;
72      md5?: string;
73    }
74  | {
75      exists: false;
76      uri: string;
77      size: undefined;
78      isDirectory: false;
79      modificationTime: undefined;
80      md5: undefined;
81    };
82
83export enum EncodingType {
84  UTF8 = 'utf8',
85  Base64 = 'base64',
86}
87
88export type FileSystemAcceptedUploadHttpMethod = 'POST' | 'PUT' | 'PATCH';
89
90export type ReadingOptions = {
91  encoding?: EncodingType | 'utf8' | 'base64';
92  position?: number;
93  length?: number;
94};
95
96export type WritingOptions = {
97  encoding?: EncodingType | 'utf8' | 'base64';
98};
99
100export type ProgressEvent = {
101  uuid: string;
102  data: {
103    totalBytesWritten: number;
104    totalBytesExpectedToWrite: number;
105  };
106};
107
108type PlatformMethod = (...args: any[]) => Promise<any>;
109
110export interface ExponentFileSystemModule {
111  readonly name: 'ExponentFileSystem';
112  readonly documentDirectory: string | null;
113  readonly cacheDirectory: string | null;
114  readonly bundledAssets: string | null;
115  readonly bundleDirectory: string | null;
116  readonly getInfoAsync?: PlatformMethod;
117  readonly readAsStringAsync?: PlatformMethod;
118  readonly writeAsStringAsync?: PlatformMethod;
119  readonly deleteAsync?: PlatformMethod;
120  readonly moveAsync?: PlatformMethod;
121  readonly copyAsync?: PlatformMethod;
122  readonly makeDirectoryAsync?: PlatformMethod;
123  readonly readDirectoryAsync?: PlatformMethod;
124  readonly downloadAsync?: PlatformMethod;
125  readonly uploadAsync?: PlatformMethod;
126  readonly downloadResumableStartAsync?: PlatformMethod;
127  readonly downloadResumablePauseAsync?: PlatformMethod;
128  readonly getContentUriAsync?: PlatformMethod;
129  readonly getFreeDiskStorageAsync?: PlatformMethod;
130  readonly getTotalDiskCapacityAsync?: PlatformMethod;
131  startObserving?: () => void;
132  stopObserving?: () => void;
133  addListener: (eventName: string) => void;
134  removeListeners: (count: number) => void;
135}
136