UNPKG

4.45 kBPlain TextView Raw
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 DownloadProgressCallback = (data: DownloadProgressData) => void;
67
68export type DownloadProgressData = {
69 totalBytesWritten: number;
70 totalBytesExpectedToWrite: number;
71};
72
73export type DownloadPauseState = {
74 url: string;
75 fileUri: string;
76 options: DownloadOptions;
77 resumeData?: string;
78};
79
80export type FileInfo =
81 | {
82 exists: true;
83 uri: string;
84 size: number;
85 isDirectory: boolean;
86 modificationTime: number;
87 md5?: string;
88 }
89 | {
90 exists: false;
91 uri: string;
92 size: undefined;
93 isDirectory: false;
94 modificationTime: undefined;
95 md5: undefined;
96 };
97
98export enum EncodingType {
99 UTF8 = 'utf8',
100 Base64 = 'base64',
101}
102
103export type FileSystemAcceptedUploadHttpMethod = 'POST' | 'PUT' | 'PATCH';
104
105export type ReadingOptions = {
106 encoding?: EncodingType | 'utf8' | 'base64';
107 position?: number;
108 length?: number;
109};
110
111export type WritingOptions = {
112 encoding?: EncodingType | 'utf8' | 'base64';
113};
114
115export type ProgressEvent = {
116 uuid: string;
117 data: {
118 totalBytesWritten: number;
119 totalBytesExpectedToWrite: number;
120 };
121};
122
123export type FileSystemRequestDirectoryPermissionsResult =
124 | {
125 granted: true;
126 directoryUri: string;
127 }
128 | {
129 granted: false;
130 };
131
132type PlatformMethod = (...args: any[]) => Promise<any>;
133
134export interface ExponentFileSystemModule {
135 readonly name: 'ExponentFileSystem';
136 readonly documentDirectory: string | null;
137 readonly cacheDirectory: string | null;
138 readonly bundledAssets: string | null;
139 readonly bundleDirectory: string | null;
140 readonly getInfoAsync?: PlatformMethod;
141 readonly readAsStringAsync?: PlatformMethod;
142 readonly writeAsStringAsync?: PlatformMethod;
143 readonly deleteAsync?: PlatformMethod;
144 readonly moveAsync?: PlatformMethod;
145 readonly copyAsync?: PlatformMethod;
146 readonly makeDirectoryAsync?: PlatformMethod;
147 readonly readDirectoryAsync?: PlatformMethod;
148 readonly downloadAsync?: PlatformMethod;
149 readonly uploadAsync?: PlatformMethod;
150 readonly downloadResumableStartAsync?: PlatformMethod;
151 readonly downloadResumablePauseAsync?: PlatformMethod;
152 readonly getContentUriAsync?: PlatformMethod;
153 readonly getFreeDiskStorageAsync?: PlatformMethod;
154 readonly getTotalDiskCapacityAsync?: PlatformMethod;
155 readonly requestDirectoryPermissionsAsync?: PlatformMethod;
156 readonly readSAFDirectoryAsync?: PlatformMethod;
157 readonly makeSAFDirectoryAsync?: PlatformMethod;
158 readonly createSAFFileAsync?: PlatformMethod;
159 startObserving?: () => void;
160 stopObserving?: () => void;
161 addListener: (eventName: string) => void;
162 removeListeners: (count: number) => void;
163}