-
Notifications
You must be signed in to change notification settings - Fork 986
/
index.d.ts
299 lines (256 loc) · 9.14 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
type MkdirOptions = {
NSURLIsExcludedFromBackupKey?: boolean // iOS only
NSFileProtectionKey?: string // IOS only
}
type FileOptions = {
NSFileProtectionKey?: string // IOS only
}
type ReadDirItem = {
ctime: Date | undefined // The creation date of the file (iOS only)
mtime: Date | undefined // The last modified date of the file
name: string // The name of the item
path: string // The absolute path to the item
size: number // Size in bytes
isFile: () => boolean // Is the file just a file?
isDirectory: () => boolean // Is the file a directory?
}
type StatResult = {
name: string | undefined // The name of the item TODO: why is this not documented?
path: string // The absolute path to the item
size: number // Size in bytes
mode: number // UNIX file mode
ctime: number // Created date
mtime: number // Last modified date
originalFilepath: string // In case of content uri this is the pointed file path, otherwise is the same as path
isFile: () => boolean // Is the file just a file?
isDirectory: () => boolean // Is the file a directory?
}
type Headers = { [name: string]: string }
type Fields = { [name: string]: string }
type DownloadFileOptions = {
fromUrl: string // URL to download file from
toFile: string // Local filesystem path to save the file to
headers?: Headers // An object of headers to be passed to the server
background?: boolean // Continue the download in the background after the app terminates (iOS only)
discretionary?: boolean // Allow the OS to control the timing and speed of the download to improve perceived performance (iOS only)
cacheable?: boolean // Whether the download can be stored in the shared NSURLCache (iOS only)
progressInterval?: number
progressDivider?: number
begin?: (res: DownloadBeginCallbackResult) => void
progress?: (res: DownloadProgressCallbackResult) => void
resumable?: () => void // only supported on iOS yet
connectionTimeout?: number // only supported on Android yet
readTimeout?: number // supported on Android and iOS
backgroundTimeout?: number // Maximum time (in milliseconds) to download an entire resource (iOS only, useful for timing out background downloads)
}
type DownloadBeginCallbackResult = {
jobId: number // The download job ID, required if one wishes to cancel the download. See `stopDownload`.
statusCode: number // The HTTP status code
contentLength: number // The total size in bytes of the download resource
headers: Headers // The HTTP response headers from the server
}
type DownloadProgressCallbackResult = {
jobId: number // The download job ID, required if one wishes to cancel the download. See `stopDownload`.
contentLength: number // The total size in bytes of the download resource
bytesWritten: number // The number of bytes written to the file so far
}
type DownloadResult = {
jobId: number // The download job ID, required if one wishes to cancel the download. See `stopDownload`.
statusCode: number // The HTTP status code
bytesWritten: number // The number of bytes written to the file
}
type UploadFileOptions = {
toUrl: string // URL to upload file to
binaryStreamOnly?: boolean // Allow for binary data stream for file to be uploaded without extra headers, Default is 'false'
files: UploadFileItem[] // An array of objects with the file information to be uploaded.
headers?: Headers // An object of headers to be passed to the server
fields?: Fields // An object of fields to be passed to the server
method?: string // Default is 'POST', supports 'POST' and 'PUT'
beginCallback?: (res: UploadBeginCallbackResult) => void // deprecated
progressCallback?: (res: UploadProgressCallbackResult) => void // deprecated
begin?: (res: UploadBeginCallbackResult) => void
progress?: (res: UploadProgressCallbackResult) => void
}
type UploadFileItem = {
name: string // Name of the file, if not defined then filename is used
filename: string // Name of file
filepath: string // Path to file
filetype: string // The mimetype of the file to be uploaded, if not defined it will get mimetype from `filepath` extension
}
type UploadBeginCallbackResult = {
jobId: number // The upload job ID, required if one wishes to cancel the upload. See `stopUpload`.
}
type UploadProgressCallbackResult = {
jobId: number // The upload job ID, required if one wishes to cancel the upload. See `stopUpload`.
totalBytesExpectedToSend: number // The total number of bytes that will be sent to the server
totalBytesSent: number // The number of bytes sent to the server
}
type UploadResult = {
jobId: number // The upload job ID, required if one wishes to cancel the upload. See `stopUpload`.
statusCode: number // The HTTP status code
headers: Headers // The HTTP response headers from the server
body: string // The HTTP response body
}
type FSInfoResult = {
totalSpace: number // The total amount of storage space on the device (in bytes).
freeSpace: number // The amount of available storage space on the device (in bytes).
}
export function mkdir(filepath: string, options?: MkdirOptions): Promise<void>
export function moveFile(
filepath: string,
destPath: string,
options?: FileOptions
): Promise<void>
export function copyFile(
filepath: string,
destPath: string,
options?: FileOptions
): Promise<void>
export function copyFolder(
srcPath: string,
destPath: string,
): Promise<void>
export function pathForBundle(bundleNamed: string): Promise<string>
export function pathForGroup(groupName: string): Promise<string>
export function getFSInfo(): Promise<FSInfoResult>
export function getAllExternalFilesDirs(): Promise<string[]>
export function unlink(filepath: string): Promise<void>
export function exists(filepath: string): Promise<boolean>
export function stopDownload(jobId: number): void
export function resumeDownload(jobId: number): void
export function isResumable(jobId: number): Promise<boolean>
export function stopUpload(jobId: number): void
export function completeHandlerIOS(jobId: number): void
export function readDir(dirpath: string): Promise<ReadDirItem[]>
/**
* Android-only
*/
export function scanFile(path: string): Promise<string[]>
/**
* Android-only
*/
export function readDirAssets(dirpath: string): Promise<ReadDirItem[]>
/**
* Android-only
*/
export function existsAssets(filepath: string): Promise<boolean>
/**
* Android-only
*/
export function existsRes(filepath: string): Promise<boolean>
/**
* Node style version (lowercase d). Returns just the names
*/
export function readdir(dirpath: string): Promise<string[]>
/**
* Android-only
*/
export function setReadable(
filepath: string,
readable: boolean,
ownerOnly: boolean
): Promise<boolean>
export function stat(filepath: string): Promise<StatResult>
export function readFile(
filepath: string,
encodingOrOptions?: any
): Promise<string>
export function read(
filepath: string,
length?: number,
position?: number,
encodingOrOptions?: any
): Promise<string>
/**
* Android only
*/
export function readFileAssets(
filepath: string,
encodingOrOptions?: any
): Promise<string>
/**
* Android only
*/
export function readFileRes(
filepath: string,
encodingOrOptions?: any
): Promise<string>
export function hash(filepath: string, algorithm: string): Promise<string>
/**
* Android only
*/
export function copyFileAssets(
filepath: string,
destPath: string
): Promise<void>
/**
* Android only
*/
export function copyFileRes(
filepath: string,
destPath: string
): Promise<void>
/**
* iOS only
* Copies fotos from asset-library (camera-roll) to a specific location
* with a given width or height
* @see: https://developer.apple.com/reference/photos/phimagemanager/1616964-requestimageforasset
*/
export function copyAssetsFileIOS(
imageUri: string,
destPath: string,
width: number,
height: number,
scale?: number,
compression?: number,
resizeMode?: string
): Promise<string>
/**
* iOS only
* Copies fotos from asset-library (camera-roll) to a specific location
* with a given width or height
* @see: https://developer.apple.com/reference/photos/phimagemanager/1616964-requestimageforasset
*/
export function copyAssetsVideoIOS(
imageUri: string,
destPath: string
): Promise<string>
export function writeFile(
filepath: string,
contents: string,
encodingOrOptions?: any
): Promise<void>
export function appendFile(
filepath: string,
contents: string,
encodingOrOptions?: string
): Promise<void>
export function write(
filepath: string,
contents: string,
position?: number,
encodingOrOptions?: any
): Promise<void>
export function downloadFile(
options: DownloadFileOptions
): { jobId: number; promise: Promise<DownloadResult> }
export function uploadFiles(
options: UploadFileOptions
): { jobId: number; promise: Promise<UploadResult> }
export function touch(
filepath: string,
mtime?: Date,
ctime?: Date,
modifyCreationTime?: boolean
): Promise<void>
export const MainBundlePath: string
export const CachesDirectoryPath: string
export const ExternalCachesDirectoryPath: string
export const DownloadDirectoryPath: string
export const DocumentDirectoryPath: string
export const ExternalDirectoryPath: string
export const ExternalStorageDirectoryPath: string
export const TemporaryDirectoryPath: string
export const LibraryDirectoryPath: string
export const PicturesDirectoryPath: string
export const FileProtectionKeys: string