@capacitor/filesystem 5.0.6-nightly-20230711T151007.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -0
- package/android/src/main/java/com/capacitorjs/plugins/filesystem/Filesystem.java +96 -1
- package/android/src/main/java/com/capacitorjs/plugins/filesystem/FilesystemPlugin.java +33 -1
- package/dist/docs.json +209 -0
- package/dist/esm/definitions.d.ts +78 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +8 -1
- package/dist/esm/web.js +54 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +53 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +53 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/Filesystem.swift +157 -0
- package/ios/Plugin/FilesystemPlugin.m +1 -0
- package/ios/Plugin/FilesystemPlugin.swift +17 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -101,6 +101,8 @@ const readFilePath = async () => {
|
|
|
101
101
|
* [`copy(...)`](#copy)
|
|
102
102
|
* [`checkPermissions()`](#checkpermissions)
|
|
103
103
|
* [`requestPermissions()`](#requestpermissions)
|
|
104
|
+
* [`downloadFile(...)`](#downloadfile)
|
|
105
|
+
* [`addListener('progress', ...)`](#addlistenerprogress)
|
|
104
106
|
* [Interfaces](#interfaces)
|
|
105
107
|
* [Type Aliases](#type-aliases)
|
|
106
108
|
* [Enums](#enums)
|
|
@@ -343,6 +345,45 @@ Required on Android, only when using <a href="#directory">`Directory.Documents`<
|
|
|
343
345
|
--------------------
|
|
344
346
|
|
|
345
347
|
|
|
348
|
+
### downloadFile(...)
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
downloadFile(options: DownloadFileOptions) => Promise<DownloadFileResult>
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
Perform a http request to a server and download the file to the specified destination.
|
|
355
|
+
|
|
356
|
+
| Param | Type |
|
|
357
|
+
| ------------- | ------------------------------------------------------------------- |
|
|
358
|
+
| **`options`** | <code><a href="#downloadfileoptions">DownloadFileOptions</a></code> |
|
|
359
|
+
|
|
360
|
+
**Returns:** <code>Promise<<a href="#downloadfileresult">DownloadFileResult</a>></code>
|
|
361
|
+
|
|
362
|
+
**Since:** 5.1.0
|
|
363
|
+
|
|
364
|
+
--------------------
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
### addListener('progress', ...)
|
|
368
|
+
|
|
369
|
+
```typescript
|
|
370
|
+
addListener(eventName: 'progress', listenerFunc: ProgressListener) => Promise<PluginListenerHandle> & PluginListenerHandle
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
Add a listener to file download progress events.
|
|
374
|
+
|
|
375
|
+
| Param | Type |
|
|
376
|
+
| ------------------ | ------------------------------------------------------------- |
|
|
377
|
+
| **`eventName`** | <code>'progress'</code> |
|
|
378
|
+
| **`listenerFunc`** | <code><a href="#progresslistener">ProgressListener</a></code> |
|
|
379
|
+
|
|
380
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>> & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
|
|
381
|
+
|
|
382
|
+
**Since:** 5.1.0
|
|
383
|
+
|
|
384
|
+
--------------------
|
|
385
|
+
|
|
386
|
+
|
|
346
387
|
### Interfaces
|
|
347
388
|
|
|
348
389
|
|
|
@@ -501,6 +542,39 @@ Required on Android, only when using <a href="#directory">`Directory.Documents`<
|
|
|
501
542
|
| **`publicStorage`** | <code><a href="#permissionstate">PermissionState</a></code> |
|
|
502
543
|
|
|
503
544
|
|
|
545
|
+
#### DownloadFileResult
|
|
546
|
+
|
|
547
|
+
| Prop | Type | Description | Since |
|
|
548
|
+
| ---------- | ------------------- | -------------------------------------------------------------------- | ----- |
|
|
549
|
+
| **`path`** | <code>string</code> | The path the file was downloaded to. | 5.1.0 |
|
|
550
|
+
| **`blob`** | <code>Blob</code> | The blob data of the downloaded file. This is only available on web. | 5.1.0 |
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
#### DownloadFileOptions
|
|
554
|
+
|
|
555
|
+
| Prop | Type | Description | Since |
|
|
556
|
+
| --------------- | ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
|
|
557
|
+
| **`path`** | <code>string</code> | The path the downloaded file should be moved to. | 5.1.0 |
|
|
558
|
+
| **`directory`** | <code><a href="#directory">Directory</a></code> | The directory to write the file to. If this option is used, filePath can be a relative path rather than absolute. The default is the `DATA` directory. | 5.1.0 |
|
|
559
|
+
| **`progress`** | <code>boolean</code> | An optional listener function to receive downloaded progress events. If this option is used, progress event should be dispatched on every chunk received. Chunks are throttled to every 100ms on Android/iOS to avoid slowdowns. | 5.1.0 |
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
#### PluginListenerHandle
|
|
563
|
+
|
|
564
|
+
| Prop | Type |
|
|
565
|
+
| ------------ | ----------------------------------------- |
|
|
566
|
+
| **`remove`** | <code>() => Promise<void></code> |
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
#### ProgressStatus
|
|
570
|
+
|
|
571
|
+
| Prop | Type | Description | Since |
|
|
572
|
+
| ------------------- | ------------------- | ---------------------------------------------------- | ----- |
|
|
573
|
+
| **`url`** | <code>string</code> | The url of the file being downloaded. | 5.1.0 |
|
|
574
|
+
| **`bytes`** | <code>number</code> | The number of bytes downloaded so far. | 5.1.0 |
|
|
575
|
+
| **`contentLength`** | <code>number</code> | The total number of bytes to download for this file. | 5.1.0 |
|
|
576
|
+
|
|
577
|
+
|
|
504
578
|
### Type Aliases
|
|
505
579
|
|
|
506
580
|
|
|
@@ -514,6 +588,13 @@ Required on Android, only when using <a href="#directory">`Directory.Documents`<
|
|
|
514
588
|
<code>'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'</code>
|
|
515
589
|
|
|
516
590
|
|
|
591
|
+
#### ProgressListener
|
|
592
|
+
|
|
593
|
+
A listener function that receives progress events.
|
|
594
|
+
|
|
595
|
+
<code>(progress: <a href="#progressstatus">ProgressStatus</a>): void</code>
|
|
596
|
+
|
|
597
|
+
|
|
517
598
|
### Enums
|
|
518
599
|
|
|
519
600
|
|
|
@@ -7,10 +7,27 @@ import android.util.Base64;
|
|
|
7
7
|
import com.capacitorjs.plugins.filesystem.exceptions.CopyFailedException;
|
|
8
8
|
import com.capacitorjs.plugins.filesystem.exceptions.DirectoryExistsException;
|
|
9
9
|
import com.capacitorjs.plugins.filesystem.exceptions.DirectoryNotFoundException;
|
|
10
|
-
import
|
|
10
|
+
import com.getcapacitor.Bridge;
|
|
11
|
+
import com.getcapacitor.JSObject;
|
|
12
|
+
import com.getcapacitor.PluginCall;
|
|
13
|
+
import com.getcapacitor.plugin.util.CapacitorHttpUrlConnection;
|
|
14
|
+
import com.getcapacitor.plugin.util.HttpRequestHandler;
|
|
15
|
+
import java.io.BufferedWriter;
|
|
16
|
+
import java.io.ByteArrayOutputStream;
|
|
17
|
+
import java.io.File;
|
|
18
|
+
import java.io.FileInputStream;
|
|
19
|
+
import java.io.FileNotFoundException;
|
|
20
|
+
import java.io.FileOutputStream;
|
|
21
|
+
import java.io.IOException;
|
|
22
|
+
import java.io.InputStream;
|
|
23
|
+
import java.io.OutputStreamWriter;
|
|
24
|
+
import java.net.URISyntaxException;
|
|
25
|
+
import java.net.URL;
|
|
11
26
|
import java.nio.channels.FileChannel;
|
|
12
27
|
import java.nio.charset.Charset;
|
|
13
28
|
import java.nio.charset.StandardCharsets;
|
|
29
|
+
import java.util.Locale;
|
|
30
|
+
import org.json.JSONException;
|
|
14
31
|
|
|
15
32
|
public class Filesystem {
|
|
16
33
|
|
|
@@ -285,4 +302,82 @@ public class Filesystem {
|
|
|
285
302
|
destination.transferFrom(source, 0, source.size());
|
|
286
303
|
}
|
|
287
304
|
}
|
|
305
|
+
|
|
306
|
+
public JSObject downloadFile(PluginCall call, Bridge bridge, HttpRequestHandler.ProgressEmitter emitter)
|
|
307
|
+
throws IOException, URISyntaxException, JSONException {
|
|
308
|
+
String urlString = call.getString("url", "");
|
|
309
|
+
JSObject headers = call.getObject("headers", new JSObject());
|
|
310
|
+
JSObject params = call.getObject("params", new JSObject());
|
|
311
|
+
Integer connectTimeout = call.getInt("connectTimeout");
|
|
312
|
+
Integer readTimeout = call.getInt("readTimeout");
|
|
313
|
+
Boolean disableRedirects = call.getBoolean("disableRedirects");
|
|
314
|
+
Boolean shouldEncode = call.getBoolean("shouldEncodeUrlParams", true);
|
|
315
|
+
Boolean progress = call.getBoolean("progress", false);
|
|
316
|
+
|
|
317
|
+
String method = call.getString("method", "GET").toUpperCase(Locale.ROOT);
|
|
318
|
+
String path = call.getString("path");
|
|
319
|
+
String directory = call.getString("directory", Environment.DIRECTORY_DOWNLOADS);
|
|
320
|
+
|
|
321
|
+
final URL url = new URL(urlString);
|
|
322
|
+
final File file = getFileObject(path, directory);
|
|
323
|
+
|
|
324
|
+
HttpRequestHandler.HttpURLConnectionBuilder connectionBuilder = new HttpRequestHandler.HttpURLConnectionBuilder()
|
|
325
|
+
.setUrl(url)
|
|
326
|
+
.setMethod(method)
|
|
327
|
+
.setHeaders(headers)
|
|
328
|
+
.setUrlParams(params, shouldEncode)
|
|
329
|
+
.setConnectTimeout(connectTimeout)
|
|
330
|
+
.setReadTimeout(readTimeout)
|
|
331
|
+
.setDisableRedirects(disableRedirects)
|
|
332
|
+
.openConnection();
|
|
333
|
+
|
|
334
|
+
CapacitorHttpUrlConnection connection = connectionBuilder.build();
|
|
335
|
+
|
|
336
|
+
connection.setSSLSocketFactory(bridge);
|
|
337
|
+
|
|
338
|
+
InputStream connectionInputStream = connection.getInputStream();
|
|
339
|
+
FileOutputStream fileOutputStream = new FileOutputStream(file, false);
|
|
340
|
+
|
|
341
|
+
String contentLength = connection.getHeaderField("content-length");
|
|
342
|
+
int bytes = 0;
|
|
343
|
+
int maxBytes = 0;
|
|
344
|
+
|
|
345
|
+
try {
|
|
346
|
+
maxBytes = contentLength != null ? Integer.parseInt(contentLength) : 0;
|
|
347
|
+
} catch (NumberFormatException ignored) {}
|
|
348
|
+
|
|
349
|
+
byte[] buffer = new byte[1024];
|
|
350
|
+
int len;
|
|
351
|
+
|
|
352
|
+
// Throttle emitter to 100ms so it doesn't slow down app
|
|
353
|
+
long lastEmitTime = System.currentTimeMillis();
|
|
354
|
+
long minEmitIntervalMillis = 100;
|
|
355
|
+
|
|
356
|
+
while ((len = connectionInputStream.read(buffer)) > 0) {
|
|
357
|
+
fileOutputStream.write(buffer, 0, len);
|
|
358
|
+
|
|
359
|
+
bytes += len;
|
|
360
|
+
|
|
361
|
+
if (progress && null != emitter) {
|
|
362
|
+
long currentTime = System.currentTimeMillis();
|
|
363
|
+
if (currentTime - lastEmitTime > minEmitIntervalMillis) {
|
|
364
|
+
emitter.emit(bytes, maxBytes);
|
|
365
|
+
lastEmitTime = currentTime;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (progress && null != emitter) {
|
|
371
|
+
emitter.emit(bytes, maxBytes);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
connectionInputStream.close();
|
|
375
|
+
fileOutputStream.close();
|
|
376
|
+
|
|
377
|
+
return new JSObject() {
|
|
378
|
+
{
|
|
379
|
+
put("path", file.getAbsolutePath());
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
}
|
|
288
383
|
}
|
|
@@ -4,6 +4,7 @@ import android.Manifest;
|
|
|
4
4
|
import android.media.MediaScannerConnection;
|
|
5
5
|
import android.net.Uri;
|
|
6
6
|
import android.os.Build;
|
|
7
|
+
import android.os.Environment;
|
|
7
8
|
import com.capacitorjs.plugins.filesystem.exceptions.CopyFailedException;
|
|
8
9
|
import com.capacitorjs.plugins.filesystem.exceptions.DirectoryExistsException;
|
|
9
10
|
import com.capacitorjs.plugins.filesystem.exceptions.DirectoryNotFoundException;
|
|
@@ -17,7 +18,10 @@ import com.getcapacitor.PluginMethod;
|
|
|
17
18
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
18
19
|
import com.getcapacitor.annotation.Permission;
|
|
19
20
|
import com.getcapacitor.annotation.PermissionCallback;
|
|
20
|
-
import
|
|
21
|
+
import com.getcapacitor.plugin.util.HttpRequestHandler;
|
|
22
|
+
import java.io.File;
|
|
23
|
+
import java.io.FileNotFoundException;
|
|
24
|
+
import java.io.IOException;
|
|
21
25
|
import java.nio.charset.Charset;
|
|
22
26
|
import java.nio.file.Files;
|
|
23
27
|
import java.nio.file.attribute.BasicFileAttributes;
|
|
@@ -376,6 +380,31 @@ public class FilesystemPlugin extends Plugin {
|
|
|
376
380
|
this._copy(call, false);
|
|
377
381
|
}
|
|
378
382
|
|
|
383
|
+
@PluginMethod
|
|
384
|
+
public void downloadFile(PluginCall call) {
|
|
385
|
+
try {
|
|
386
|
+
String directory = call.getString("directory", Environment.DIRECTORY_DOWNLOADS);
|
|
387
|
+
|
|
388
|
+
if (isPublicDirectory(directory) && !isStoragePermissionGranted()) {
|
|
389
|
+
requestAllPermissions(call, "permissionCallback");
|
|
390
|
+
} else {
|
|
391
|
+
HttpRequestHandler.ProgressEmitter emitter = (bytes, contentLength) -> {
|
|
392
|
+
JSObject ret = new JSObject();
|
|
393
|
+
ret.put("url", call.getString("url"));
|
|
394
|
+
ret.put("bytes", bytes);
|
|
395
|
+
ret.put("contentLength", contentLength);
|
|
396
|
+
|
|
397
|
+
notifyListeners("progress", ret);
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
JSObject response = implementation.downloadFile(call, bridge, emitter);
|
|
401
|
+
call.resolve(response);
|
|
402
|
+
}
|
|
403
|
+
} catch (Exception ex) {
|
|
404
|
+
call.reject("Error downloading file: " + ex.getLocalizedMessage(), ex);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
379
408
|
private void _copy(PluginCall call, Boolean doRename) {
|
|
380
409
|
String from = call.getString("from");
|
|
381
410
|
String to = call.getString("to");
|
|
@@ -448,6 +477,9 @@ public class FilesystemPlugin extends Plugin {
|
|
|
448
477
|
case "stat":
|
|
449
478
|
stat(call);
|
|
450
479
|
break;
|
|
480
|
+
case "downloadFile":
|
|
481
|
+
downloadFile(call);
|
|
482
|
+
break;
|
|
451
483
|
}
|
|
452
484
|
}
|
|
453
485
|
|
package/dist/docs.json
CHANGED
|
@@ -297,6 +297,59 @@
|
|
|
297
297
|
"PermissionStatus"
|
|
298
298
|
],
|
|
299
299
|
"slug": "requestpermissions"
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
"name": "downloadFile",
|
|
303
|
+
"signature": "(options: DownloadFileOptions) => Promise<DownloadFileResult>",
|
|
304
|
+
"parameters": [
|
|
305
|
+
{
|
|
306
|
+
"name": "options",
|
|
307
|
+
"docs": "",
|
|
308
|
+
"type": "DownloadFileOptions"
|
|
309
|
+
}
|
|
310
|
+
],
|
|
311
|
+
"returns": "Promise<DownloadFileResult>",
|
|
312
|
+
"tags": [
|
|
313
|
+
{
|
|
314
|
+
"name": "since",
|
|
315
|
+
"text": "5.1.0"
|
|
316
|
+
}
|
|
317
|
+
],
|
|
318
|
+
"docs": "Perform a http request to a server and download the file to the specified destination.",
|
|
319
|
+
"complexTypes": [
|
|
320
|
+
"DownloadFileResult",
|
|
321
|
+
"DownloadFileOptions"
|
|
322
|
+
],
|
|
323
|
+
"slug": "downloadfile"
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
"name": "addListener",
|
|
327
|
+
"signature": "(eventName: 'progress', listenerFunc: ProgressListener) => Promise<PluginListenerHandle> & PluginListenerHandle",
|
|
328
|
+
"parameters": [
|
|
329
|
+
{
|
|
330
|
+
"name": "eventName",
|
|
331
|
+
"docs": "",
|
|
332
|
+
"type": "'progress'"
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
"name": "listenerFunc",
|
|
336
|
+
"docs": "",
|
|
337
|
+
"type": "ProgressListener"
|
|
338
|
+
}
|
|
339
|
+
],
|
|
340
|
+
"returns": "Promise<PluginListenerHandle> & PluginListenerHandle",
|
|
341
|
+
"tags": [
|
|
342
|
+
{
|
|
343
|
+
"name": "since",
|
|
344
|
+
"text": "5.1.0"
|
|
345
|
+
}
|
|
346
|
+
],
|
|
347
|
+
"docs": "Add a listener to file download progress events.",
|
|
348
|
+
"complexTypes": [
|
|
349
|
+
"PluginListenerHandle",
|
|
350
|
+
"ProgressListener"
|
|
351
|
+
],
|
|
352
|
+
"slug": "addlistenerprogress"
|
|
300
353
|
}
|
|
301
354
|
],
|
|
302
355
|
"properties": []
|
|
@@ -1061,6 +1114,149 @@
|
|
|
1061
1114
|
"type": "PermissionState"
|
|
1062
1115
|
}
|
|
1063
1116
|
]
|
|
1117
|
+
},
|
|
1118
|
+
{
|
|
1119
|
+
"name": "DownloadFileResult",
|
|
1120
|
+
"slug": "downloadfileresult",
|
|
1121
|
+
"docs": "",
|
|
1122
|
+
"tags": [],
|
|
1123
|
+
"methods": [],
|
|
1124
|
+
"properties": [
|
|
1125
|
+
{
|
|
1126
|
+
"name": "path",
|
|
1127
|
+
"tags": [
|
|
1128
|
+
{
|
|
1129
|
+
"text": "5.1.0",
|
|
1130
|
+
"name": "since"
|
|
1131
|
+
}
|
|
1132
|
+
],
|
|
1133
|
+
"docs": "The path the file was downloaded to.",
|
|
1134
|
+
"complexTypes": [],
|
|
1135
|
+
"type": "string | undefined"
|
|
1136
|
+
},
|
|
1137
|
+
{
|
|
1138
|
+
"name": "blob",
|
|
1139
|
+
"tags": [
|
|
1140
|
+
{
|
|
1141
|
+
"text": "5.1.0",
|
|
1142
|
+
"name": "since"
|
|
1143
|
+
}
|
|
1144
|
+
],
|
|
1145
|
+
"docs": "The blob data of the downloaded file.\nThis is only available on web.",
|
|
1146
|
+
"complexTypes": [
|
|
1147
|
+
"Blob"
|
|
1148
|
+
],
|
|
1149
|
+
"type": "Blob"
|
|
1150
|
+
}
|
|
1151
|
+
]
|
|
1152
|
+
},
|
|
1153
|
+
{
|
|
1154
|
+
"name": "DownloadFileOptions",
|
|
1155
|
+
"slug": "downloadfileoptions",
|
|
1156
|
+
"docs": "",
|
|
1157
|
+
"tags": [],
|
|
1158
|
+
"methods": [],
|
|
1159
|
+
"properties": [
|
|
1160
|
+
{
|
|
1161
|
+
"name": "path",
|
|
1162
|
+
"tags": [
|
|
1163
|
+
{
|
|
1164
|
+
"text": "5.1.0",
|
|
1165
|
+
"name": "since"
|
|
1166
|
+
}
|
|
1167
|
+
],
|
|
1168
|
+
"docs": "The path the downloaded file should be moved to.",
|
|
1169
|
+
"complexTypes": [],
|
|
1170
|
+
"type": "string"
|
|
1171
|
+
},
|
|
1172
|
+
{
|
|
1173
|
+
"name": "directory",
|
|
1174
|
+
"tags": [
|
|
1175
|
+
{
|
|
1176
|
+
"text": "5.1.0",
|
|
1177
|
+
"name": "since"
|
|
1178
|
+
}
|
|
1179
|
+
],
|
|
1180
|
+
"docs": "The directory to write the file to.\nIf this option is used, filePath can be a relative path rather than absolute.\nThe default is the `DATA` directory.",
|
|
1181
|
+
"complexTypes": [
|
|
1182
|
+
"Directory"
|
|
1183
|
+
],
|
|
1184
|
+
"type": "Directory"
|
|
1185
|
+
},
|
|
1186
|
+
{
|
|
1187
|
+
"name": "progress",
|
|
1188
|
+
"tags": [
|
|
1189
|
+
{
|
|
1190
|
+
"text": "5.1.0",
|
|
1191
|
+
"name": "since"
|
|
1192
|
+
}
|
|
1193
|
+
],
|
|
1194
|
+
"docs": "An optional listener function to receive downloaded progress events.\nIf this option is used, progress event should be dispatched on every chunk received.\nChunks are throttled to every 100ms on Android/iOS to avoid slowdowns.",
|
|
1195
|
+
"complexTypes": [],
|
|
1196
|
+
"type": "boolean | undefined"
|
|
1197
|
+
}
|
|
1198
|
+
]
|
|
1199
|
+
},
|
|
1200
|
+
{
|
|
1201
|
+
"name": "PluginListenerHandle",
|
|
1202
|
+
"slug": "pluginlistenerhandle",
|
|
1203
|
+
"docs": "",
|
|
1204
|
+
"tags": [],
|
|
1205
|
+
"methods": [],
|
|
1206
|
+
"properties": [
|
|
1207
|
+
{
|
|
1208
|
+
"name": "remove",
|
|
1209
|
+
"tags": [],
|
|
1210
|
+
"docs": "",
|
|
1211
|
+
"complexTypes": [],
|
|
1212
|
+
"type": "() => Promise<void>"
|
|
1213
|
+
}
|
|
1214
|
+
]
|
|
1215
|
+
},
|
|
1216
|
+
{
|
|
1217
|
+
"name": "ProgressStatus",
|
|
1218
|
+
"slug": "progressstatus",
|
|
1219
|
+
"docs": "",
|
|
1220
|
+
"tags": [],
|
|
1221
|
+
"methods": [],
|
|
1222
|
+
"properties": [
|
|
1223
|
+
{
|
|
1224
|
+
"name": "url",
|
|
1225
|
+
"tags": [
|
|
1226
|
+
{
|
|
1227
|
+
"text": "5.1.0",
|
|
1228
|
+
"name": "since"
|
|
1229
|
+
}
|
|
1230
|
+
],
|
|
1231
|
+
"docs": "The url of the file being downloaded.",
|
|
1232
|
+
"complexTypes": [],
|
|
1233
|
+
"type": "string"
|
|
1234
|
+
},
|
|
1235
|
+
{
|
|
1236
|
+
"name": "bytes",
|
|
1237
|
+
"tags": [
|
|
1238
|
+
{
|
|
1239
|
+
"text": "5.1.0",
|
|
1240
|
+
"name": "since"
|
|
1241
|
+
}
|
|
1242
|
+
],
|
|
1243
|
+
"docs": "The number of bytes downloaded so far.",
|
|
1244
|
+
"complexTypes": [],
|
|
1245
|
+
"type": "number"
|
|
1246
|
+
},
|
|
1247
|
+
{
|
|
1248
|
+
"name": "contentLength",
|
|
1249
|
+
"tags": [
|
|
1250
|
+
{
|
|
1251
|
+
"text": "5.1.0",
|
|
1252
|
+
"name": "since"
|
|
1253
|
+
}
|
|
1254
|
+
],
|
|
1255
|
+
"docs": "The total number of bytes to download for this file.",
|
|
1256
|
+
"complexTypes": [],
|
|
1257
|
+
"type": "number"
|
|
1258
|
+
}
|
|
1259
|
+
]
|
|
1064
1260
|
}
|
|
1065
1261
|
],
|
|
1066
1262
|
"enums": [
|
|
@@ -1212,6 +1408,19 @@
|
|
|
1212
1408
|
"complexTypes": []
|
|
1213
1409
|
}
|
|
1214
1410
|
]
|
|
1411
|
+
},
|
|
1412
|
+
{
|
|
1413
|
+
"name": "ProgressListener",
|
|
1414
|
+
"slug": "progresslistener",
|
|
1415
|
+
"docs": "A listener function that receives progress events.",
|
|
1416
|
+
"types": [
|
|
1417
|
+
{
|
|
1418
|
+
"text": "(progress: ProgressStatus): void",
|
|
1419
|
+
"complexTypes": [
|
|
1420
|
+
"ProgressStatus"
|
|
1421
|
+
]
|
|
1422
|
+
}
|
|
1423
|
+
]
|
|
1215
1424
|
}
|
|
1216
1425
|
],
|
|
1217
1426
|
"pluginConfigs": []
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PermissionState } from '@capacitor/core';
|
|
1
|
+
import type { HttpOptions, PermissionState, PluginListenerHandle } from '@capacitor/core';
|
|
2
2
|
export interface PermissionStatus {
|
|
3
3
|
publicStorage: PermissionState;
|
|
4
4
|
}
|
|
@@ -417,6 +417,71 @@ export interface CopyResult {
|
|
|
417
417
|
*/
|
|
418
418
|
uri: string;
|
|
419
419
|
}
|
|
420
|
+
export interface DownloadFileOptions extends HttpOptions {
|
|
421
|
+
/**
|
|
422
|
+
* The path the downloaded file should be moved to.
|
|
423
|
+
*
|
|
424
|
+
* @since 5.1.0
|
|
425
|
+
*/
|
|
426
|
+
path: string;
|
|
427
|
+
/**
|
|
428
|
+
* The directory to write the file to.
|
|
429
|
+
* If this option is used, filePath can be a relative path rather than absolute.
|
|
430
|
+
* The default is the `DATA` directory.
|
|
431
|
+
*
|
|
432
|
+
* @since 5.1.0
|
|
433
|
+
*/
|
|
434
|
+
directory?: Directory;
|
|
435
|
+
/**
|
|
436
|
+
* An optional listener function to receive downloaded progress events.
|
|
437
|
+
* If this option is used, progress event should be dispatched on every chunk received.
|
|
438
|
+
* Chunks are throttled to every 100ms on Android/iOS to avoid slowdowns.
|
|
439
|
+
*
|
|
440
|
+
* @since 5.1.0
|
|
441
|
+
*/
|
|
442
|
+
progress?: boolean;
|
|
443
|
+
}
|
|
444
|
+
export interface DownloadFileResult {
|
|
445
|
+
/**
|
|
446
|
+
* The path the file was downloaded to.
|
|
447
|
+
*
|
|
448
|
+
* @since 5.1.0
|
|
449
|
+
*/
|
|
450
|
+
path?: string;
|
|
451
|
+
/**
|
|
452
|
+
* The blob data of the downloaded file.
|
|
453
|
+
* This is only available on web.
|
|
454
|
+
*
|
|
455
|
+
* @since 5.1.0
|
|
456
|
+
*/
|
|
457
|
+
blob?: Blob;
|
|
458
|
+
}
|
|
459
|
+
export interface ProgressStatus {
|
|
460
|
+
/**
|
|
461
|
+
* The url of the file being downloaded.
|
|
462
|
+
*
|
|
463
|
+
* @since 5.1.0
|
|
464
|
+
*/
|
|
465
|
+
url: string;
|
|
466
|
+
/**
|
|
467
|
+
* The number of bytes downloaded so far.
|
|
468
|
+
*
|
|
469
|
+
* @since 5.1.0
|
|
470
|
+
*/
|
|
471
|
+
bytes: number;
|
|
472
|
+
/**
|
|
473
|
+
* The total number of bytes to download for this file.
|
|
474
|
+
*
|
|
475
|
+
* @since 5.1.0
|
|
476
|
+
*/
|
|
477
|
+
contentLength: number;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* A listener function that receives progress events.
|
|
481
|
+
*
|
|
482
|
+
* @since 5.1.0
|
|
483
|
+
*/
|
|
484
|
+
export declare type ProgressListener = (progress: ProgressStatus) => void;
|
|
420
485
|
export interface FilesystemPlugin {
|
|
421
486
|
/**
|
|
422
487
|
* Read a file from disk
|
|
@@ -500,6 +565,18 @@ export interface FilesystemPlugin {
|
|
|
500
565
|
* @since 1.0.0
|
|
501
566
|
*/
|
|
502
567
|
requestPermissions(): Promise<PermissionStatus>;
|
|
568
|
+
/**
|
|
569
|
+
* Perform a http request to a server and download the file to the specified destination.
|
|
570
|
+
*
|
|
571
|
+
* @since 5.1.0
|
|
572
|
+
*/
|
|
573
|
+
downloadFile(options: DownloadFileOptions): Promise<DownloadFileResult>;
|
|
574
|
+
/**
|
|
575
|
+
* Add a listener to file download progress events.
|
|
576
|
+
*
|
|
577
|
+
* @since 5.1.0
|
|
578
|
+
*/
|
|
579
|
+
addListener(eventName: 'progress', listenerFunc: ProgressListener): Promise<PluginListenerHandle> & PluginListenerHandle;
|
|
503
580
|
}
|
|
504
581
|
/**
|
|
505
582
|
* @deprecated Use `ReadFileOptions`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAMA,MAAM,CAAN,IAAY,SAqEX;AArED,WAAY,SAAS;IACnB;;;;;;;;;;;OAWG;IACH,oCAAuB,CAAA;IAEvB;;;;;;;OAOG;IACH,0BAAa,CAAA;IAEb;;;;;;;OAOG;IACH,gCAAmB,CAAA;IAEnB;;;;;;OAMG;IACH,4BAAe,CAAA;IAEf;;;;;;;;;;OAUG;IACH,kCAAqB,CAAA;IAErB;;;;;;;;;;OAUG;IACH,iDAAoC,CAAA;AACtC,CAAC,EArEW,SAAS,KAAT,SAAS,QAqEpB;AAED,MAAM,CAAN,IAAY,QAyBX;AAzBD,WAAY,QAAQ;IAClB;;;;OAIG;IACH,yBAAa,CAAA;IAEb;;;;;;OAMG;IACH,2BAAe,CAAA;IAEf;;;;;;OAMG;IACH,2BAAe,CAAA;AACjB,CAAC,EAzBW,QAAQ,KAAR,QAAQ,QAyBnB;AA2fD;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,SAAS,CAAC;AAE7C;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAQ,CAAC","sourcesContent":["import type { PermissionState } from '@capacitor/core';\n\nexport interface PermissionStatus {\n publicStorage: PermissionState;\n}\n\nexport enum Directory {\n /**\n * The Documents directory\n * On iOS it's the app's documents directory.\n * Use this directory to store user-generated content.\n * On Android it's the Public Documents folder, so it's accessible from other apps.\n * It's not accesible on Android 10 unless the app enables legacy External Storage\n * by adding `android:requestLegacyExternalStorage=\"true\"` in the `application` tag\n * in the `AndroidManifest.xml`.\n * It's not accesible on Android 11 or newer.\n *\n * @since 1.0.0\n */\n Documents = 'DOCUMENTS',\n\n /**\n * The Data directory\n * On iOS it will use the Documents directory.\n * On Android it's the directory holding application files.\n * Files will be deleted when the application is uninstalled.\n *\n * @since 1.0.0\n */\n Data = 'DATA',\n\n /**\n * The Library directory\n * On iOS it will use the Library directory.\n * On Android it's the directory holding application files.\n * Files will be deleted when the application is uninstalled.\n *\n * @since 1.1.0\n */\n Library = 'LIBRARY',\n\n /**\n * The Cache directory\n * Can be deleted in cases of low memory, so use this directory to write app-specific files\n * that your app can re-create easily.\n *\n * @since 1.0.0\n */\n Cache = 'CACHE',\n\n /**\n * The external directory\n * On iOS it will use the Documents directory\n * On Android it's the directory on the primary shared/external\n * storage device where the application can place persistent files it owns.\n * These files are internal to the applications, and not typically visible\n * to the user as media.\n * Files will be deleted when the application is uninstalled.\n *\n * @since 1.0.0\n */\n External = 'EXTERNAL',\n\n /**\n * The external storage directory\n * On iOS it will use the Documents directory\n * On Android it's the primary shared/external storage directory.\n * It's not accesible on Android 10 unless the app enables legacy External Storage\n * by adding `android:requestLegacyExternalStorage=\"true\"` in the `application` tag\n * in the `AndroidManifest.xml`.\n * It's not accesible on Android 11 or newer.\n *\n * @since 1.0.0\n */\n ExternalStorage = 'EXTERNAL_STORAGE',\n}\n\nexport enum Encoding {\n /**\n * Eight-bit UCS Transformation Format\n *\n * @since 1.0.0\n */\n UTF8 = 'utf8',\n\n /**\n * Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the\n * Unicode character set\n * This encoding is only supported on Android.\n *\n * @since 1.0.0\n */\n ASCII = 'ascii',\n\n /**\n * Sixteen-bit UCS Transformation Format, byte order identified by an\n * optional byte-order mark\n * This encoding is only supported on Android.\n *\n * @since 1.0.0\n */\n UTF16 = 'utf16',\n}\n\nexport interface WriteFileOptions {\n /**\n * The path of the file to write\n *\n * @since 1.0.0\n */\n path: string;\n\n /**\n * The data to write\n *\n * @since 1.0.0\n */\n data: string;\n\n /**\n * The `Directory` to store the file in\n *\n * @since 1.0.0\n */\n directory?: Directory;\n\n /**\n * The encoding to write the file in. If not provided, data\n * is written as base64 encoded.\n *\n * Pass Encoding.UTF8 to write data as string\n *\n * @since 1.0.0\n */\n encoding?: Encoding;\n\n /**\n * Whether to create any missing parent directories.\n *\n * @default false\n * @since 1.0.0\n */\n recursive?: boolean;\n}\n\nexport interface AppendFileOptions {\n /**\n * The path of the file to append\n *\n * @since 1.0.0\n */\n path: string;\n\n /**\n * The data to write\n *\n * @since 1.0.0\n */\n data: string;\n\n /**\n * The `Directory` to store the file in\n *\n * @since 1.0.0\n */\n directory?: Directory;\n\n /**\n * The encoding to write the file in. If not provided, data\n * is written as base64 encoded.\n *\n * Pass Encoding.UTF8 to write data as string\n *\n * @since 1.0.0\n */\n encoding?: Encoding;\n}\n\nexport interface ReadFileOptions {\n /**\n * The path of the file to read\n *\n * @since 1.0.0\n */\n path: string;\n\n /**\n * The `Directory` to read the file from\n *\n * @since 1.0.0\n */\n directory?: Directory;\n\n /**\n * The encoding to read the file in, if not provided, data\n * is read as binary and returned as base64 encoded.\n *\n * Pass Encoding.UTF8 to read data as string\n *\n * @since 1.0.0\n */\n encoding?: Encoding;\n}\n\nexport interface DeleteFileOptions {\n /**\n * The path of the file to delete\n *\n * @since 1.0.0\n */\n path: string;\n\n /**\n * The `Directory` to delete the file from\n *\n * @since 1.0.0\n */\n directory?: Directory;\n}\n\nexport interface MkdirOptions {\n /**\n * The path of the new directory\n *\n * @since 1.0.0\n */\n path: string;\n\n /**\n * The `Directory` to make the new directory in\n *\n * @since 1.0.0\n */\n directory?: Directory;\n\n /**\n * Whether to create any missing parent directories as well.\n *\n * @default false\n * @since 1.0.0\n */\n recursive?: boolean;\n}\n\nexport interface RmdirOptions {\n /**\n * The path of the directory to remove\n *\n * @since 1.0.0\n */\n path: string;\n\n /**\n * The `Directory` to remove the directory from\n *\n * @since 1.0.0\n */\n directory?: Directory;\n\n /**\n * Whether to recursively remove the contents of the directory\n *\n * @default false\n * @since 1.0.0\n */\n recursive?: boolean;\n}\n\nexport interface ReaddirOptions {\n /**\n * The path of the directory to read\n *\n * @since 1.0.0\n */\n path: string;\n\n /**\n * The `Directory` to list files from\n *\n * @since 1.0.0\n */\n directory?: Directory;\n}\n\nexport interface GetUriOptions {\n /**\n * The path of the file to get the URI for\n *\n * @since 1.0.0\n */\n path: string;\n\n /**\n * The `Directory` to get the file under\n *\n * @since 1.0.0\n */\n directory: Directory;\n}\n\nexport interface StatOptions {\n /**\n * The path of the file to get data about\n *\n * @since 1.0.0\n */\n path: string;\n\n /**\n * The `Directory` to get the file under\n *\n * @since 1.0.0\n */\n directory?: Directory;\n}\n\nexport interface CopyOptions {\n /**\n * The existing file or directory\n *\n * @since 1.0.0\n */\n from: string;\n\n /**\n * The destination file or directory\n *\n * @since 1.0.0\n */\n to: string;\n\n /**\n * The `Directory` containing the existing file or directory\n *\n * @since 1.0.0\n */\n directory?: Directory;\n\n /**\n * The `Directory` containing the destination file or directory. If not supplied will use the 'directory'\n * parameter as the destination\n *\n * @since 1.0.0\n */\n toDirectory?: Directory;\n}\n\nexport type RenameOptions = CopyOptions;\n\nexport interface ReadFileResult {\n /**\n * The string representation of the data contained in the file\n *\n * @since 1.0.0\n */\n data: string;\n}\n\nexport interface WriteFileResult {\n /**\n * The uri where the file was written into\n *\n * @since 1.0.0\n */\n uri: string;\n}\n\nexport interface ReaddirResult {\n /**\n * List of files and directories inside the directory\n *\n * @since 1.0.0\n */\n files: FileInfo[];\n}\n\nexport interface FileInfo {\n /**\n * Name of the file or directory.\n */\n name: string;\n /**\n * Type of the file.\n *\n * @since 4.0.0\n */\n type: 'directory' | 'file';\n\n /**\n * Size of the file in bytes.\n *\n * @since 4.0.0\n */\n size: number;\n\n /**\n * Time of creation in milliseconds.\n *\n * It's not available on Android 7 and older devices.\n *\n * @since 4.0.0\n */\n ctime?: number;\n\n /**\n * Time of last modification in milliseconds.\n *\n * @since 4.0.0\n */\n mtime: number;\n\n /**\n * The uri of the file.\n *\n * @since 4.0.0\n */\n uri: string;\n}\n\nexport interface GetUriResult {\n /**\n * The uri of the file\n *\n * @since 1.0.0\n */\n uri: string;\n}\n\nexport interface StatResult {\n /**\n * Type of the file.\n *\n * @since 1.0.0\n */\n type: 'directory' | 'file';\n\n /**\n * Size of the file in bytes.\n *\n * @since 1.0.0\n */\n size: number;\n\n /**\n * Time of creation in milliseconds.\n *\n * It's not available on Android 7 and older devices.\n *\n * @since 1.0.0\n */\n ctime?: number;\n\n /**\n * Time of last modification in milliseconds.\n *\n * @since 1.0.0\n */\n mtime: number;\n\n /**\n * The uri of the file\n *\n * @since 1.0.0\n */\n uri: string;\n}\n\nexport interface CopyResult {\n /**\n * The uri where the file was copied into\n *\n * @since 4.0.0\n */\n uri: string;\n}\n\nexport interface FilesystemPlugin {\n /**\n * Read a file from disk\n *\n * @since 1.0.0\n */\n readFile(options: ReadFileOptions): Promise<ReadFileResult>;\n\n /**\n * Write a file to disk in the specified location on device\n *\n * @since 1.0.0\n */\n writeFile(options: WriteFileOptions): Promise<WriteFileResult>;\n\n /**\n * Append to a file on disk in the specified location on device\n *\n * @since 1.0.0\n */\n appendFile(options: AppendFileOptions): Promise<void>;\n\n /**\n * Delete a file from disk\n *\n * @since 1.0.0\n */\n deleteFile(options: DeleteFileOptions): Promise<void>;\n\n /**\n * Create a directory.\n *\n * @since 1.0.0\n */\n mkdir(options: MkdirOptions): Promise<void>;\n\n /**\n * Remove a directory\n *\n * @since 1.0.0\n */\n rmdir(options: RmdirOptions): Promise<void>;\n\n /**\n * Return a list of files from the directory (not recursive)\n *\n * @since 1.0.0\n */\n readdir(options: ReaddirOptions): Promise<ReaddirResult>;\n\n /**\n * Return full File URI for a path and directory\n *\n * @since 1.0.0\n */\n getUri(options: GetUriOptions): Promise<GetUriResult>;\n\n /**\n * Return data about a file\n *\n * @since 1.0.0\n */\n stat(options: StatOptions): Promise<StatResult>;\n\n /**\n * Rename a file or directory\n *\n * @since 1.0.0\n */\n rename(options: RenameOptions): Promise<void>;\n\n /**\n * Copy a file or directory\n *\n * @since 1.0.0\n */\n copy(options: CopyOptions): Promise<CopyResult>;\n\n /**\n * Check read/write permissions.\n * Required on Android, only when using `Directory.Documents` or\n * `Directory.ExternalStorage`.\n *\n * @since 1.0.0\n */\n checkPermissions(): Promise<PermissionStatus>;\n\n /**\n * Request read/write permissions.\n * Required on Android, only when using `Directory.Documents` or\n * `Directory.ExternalStorage`.\n *\n * @since 1.0.0\n */\n requestPermissions(): Promise<PermissionStatus>;\n}\n\n/**\n * @deprecated Use `ReadFileOptions`.\n * @since 1.0.0\n */\nexport type FileReadOptions = ReadFileOptions;\n\n/**\n * @deprecated Use `ReadFileResult`.\n * @since 1.0.0\n */\nexport type FileReadResult = ReadFileResult;\n\n/**\n * @deprecated Use `WriteFileOptions`.\n * @since 1.0.0\n */\nexport type FileWriteOptions = WriteFileOptions;\n\n/**\n * @deprecated Use `WriteFileResult`.\n * @since 1.0.0\n */\nexport type FileWriteResult = WriteFileResult;\n\n/**\n * @deprecated Use `AppendFileOptions`.\n * @since 1.0.0\n */\nexport type FileAppendOptions = AppendFileOptions;\n\n/**\n * @deprecated Use `DeleteFileOptions`.\n * @since 1.0.0\n */\nexport type FileDeleteOptions = DeleteFileOptions;\n\n/**\n * @deprecated Use `Directory`.\n * @since 1.0.0\n */\nexport const FilesystemDirectory = Directory;\n\n/**\n * @deprecated Use `Encoding`.\n * @since 1.0.0\n */\nexport const FilesystemEncoding = Encoding;\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAUA,MAAM,CAAN,IAAY,SAqEX;AArED,WAAY,SAAS;IACnB;;;;;;;;;;;OAWG;IACH,oCAAuB,CAAA;IAEvB;;;;;;;OAOG;IACH,0BAAa,CAAA;IAEb;;;;;;;OAOG;IACH,gCAAmB,CAAA;IAEnB;;;;;;OAMG;IACH,4BAAe,CAAA;IAEf;;;;;;;;;;OAUG;IACH,kCAAqB,CAAA;IAErB;;;;;;;;;;OAUG;IACH,iDAAoC,CAAA;AACtC,CAAC,EArEW,SAAS,KAAT,SAAS,QAqEpB;AAED,MAAM,CAAN,IAAY,QAyBX;AAzBD,WAAY,QAAQ;IAClB;;;;OAIG;IACH,yBAAa,CAAA;IAEb;;;;;;OAMG;IACH,2BAAe,CAAA;IAEf;;;;;;OAMG;IACH,2BAAe,CAAA;AACjB,CAAC,EAzBW,QAAQ,KAAR,QAAQ,QAyBnB;AAglBD;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,SAAS,CAAC;AAE7C;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAQ,CAAC","sourcesContent":["import type {\n HttpOptions,\n PermissionState,\n PluginListenerHandle,\n} from '@capacitor/core';\n\nexport interface PermissionStatus {\n publicStorage: PermissionState;\n}\n\nexport enum Directory {\n /**\n * The Documents directory\n * On iOS it's the app's documents directory.\n * Use this directory to store user-generated content.\n * On Android it's the Public Documents folder, so it's accessible from other apps.\n * It's not accesible on Android 10 unless the app enables legacy External Storage\n * by adding `android:requestLegacyExternalStorage=\"true\"` in the `application` tag\n * in the `AndroidManifest.xml`.\n * It's not accesible on Android 11 or newer.\n *\n * @since 1.0.0\n */\n Documents = 'DOCUMENTS',\n\n /**\n * The Data directory\n * On iOS it will use the Documents directory.\n * On Android it's the directory holding application files.\n * Files will be deleted when the application is uninstalled.\n *\n * @since 1.0.0\n */\n Data = 'DATA',\n\n /**\n * The Library directory\n * On iOS it will use the Library directory.\n * On Android it's the directory holding application files.\n * Files will be deleted when the application is uninstalled.\n *\n * @since 1.1.0\n */\n Library = 'LIBRARY',\n\n /**\n * The Cache directory\n * Can be deleted in cases of low memory, so use this directory to write app-specific files\n * that your app can re-create easily.\n *\n * @since 1.0.0\n */\n Cache = 'CACHE',\n\n /**\n * The external directory\n * On iOS it will use the Documents directory\n * On Android it's the directory on the primary shared/external\n * storage device where the application can place persistent files it owns.\n * These files are internal to the applications, and not typically visible\n * to the user as media.\n * Files will be deleted when the application is uninstalled.\n *\n * @since 1.0.0\n */\n External = 'EXTERNAL',\n\n /**\n * The external storage directory\n * On iOS it will use the Documents directory\n * On Android it's the primary shared/external storage directory.\n * It's not accesible on Android 10 unless the app enables legacy External Storage\n * by adding `android:requestLegacyExternalStorage=\"true\"` in the `application` tag\n * in the `AndroidManifest.xml`.\n * It's not accesible on Android 11 or newer.\n *\n * @since 1.0.0\n */\n ExternalStorage = 'EXTERNAL_STORAGE',\n}\n\nexport enum Encoding {\n /**\n * Eight-bit UCS Transformation Format\n *\n * @since 1.0.0\n */\n UTF8 = 'utf8',\n\n /**\n * Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the\n * Unicode character set\n * This encoding is only supported on Android.\n *\n * @since 1.0.0\n */\n ASCII = 'ascii',\n\n /**\n * Sixteen-bit UCS Transformation Format, byte order identified by an\n * optional byte-order mark\n * This encoding is only supported on Android.\n *\n * @since 1.0.0\n */\n UTF16 = 'utf16',\n}\n\nexport interface WriteFileOptions {\n /**\n * The path of the file to write\n *\n * @since 1.0.0\n */\n path: string;\n\n /**\n * The data to write\n *\n * @since 1.0.0\n */\n data: string;\n\n /**\n * The `Directory` to store the file in\n *\n * @since 1.0.0\n */\n directory?: Directory;\n\n /**\n * The encoding to write the file in. If not provided, data\n * is written as base64 encoded.\n *\n * Pass Encoding.UTF8 to write data as string\n *\n * @since 1.0.0\n */\n encoding?: Encoding;\n\n /**\n * Whether to create any missing parent directories.\n *\n * @default false\n * @since 1.0.0\n */\n recursive?: boolean;\n}\n\nexport interface AppendFileOptions {\n /**\n * The path of the file to append\n *\n * @since 1.0.0\n */\n path: string;\n\n /**\n * The data to write\n *\n * @since 1.0.0\n */\n data: string;\n\n /**\n * The `Directory` to store the file in\n *\n * @since 1.0.0\n */\n directory?: Directory;\n\n /**\n * The encoding to write the file in. If not provided, data\n * is written as base64 encoded.\n *\n * Pass Encoding.UTF8 to write data as string\n *\n * @since 1.0.0\n */\n encoding?: Encoding;\n}\n\nexport interface ReadFileOptions {\n /**\n * The path of the file to read\n *\n * @since 1.0.0\n */\n path: string;\n\n /**\n * The `Directory` to read the file from\n *\n * @since 1.0.0\n */\n directory?: Directory;\n\n /**\n * The encoding to read the file in, if not provided, data\n * is read as binary and returned as base64 encoded.\n *\n * Pass Encoding.UTF8 to read data as string\n *\n * @since 1.0.0\n */\n encoding?: Encoding;\n}\n\nexport interface DeleteFileOptions {\n /**\n * The path of the file to delete\n *\n * @since 1.0.0\n */\n path: string;\n\n /**\n * The `Directory` to delete the file from\n *\n * @since 1.0.0\n */\n directory?: Directory;\n}\n\nexport interface MkdirOptions {\n /**\n * The path of the new directory\n *\n * @since 1.0.0\n */\n path: string;\n\n /**\n * The `Directory` to make the new directory in\n *\n * @since 1.0.0\n */\n directory?: Directory;\n\n /**\n * Whether to create any missing parent directories as well.\n *\n * @default false\n * @since 1.0.0\n */\n recursive?: boolean;\n}\n\nexport interface RmdirOptions {\n /**\n * The path of the directory to remove\n *\n * @since 1.0.0\n */\n path: string;\n\n /**\n * The `Directory` to remove the directory from\n *\n * @since 1.0.0\n */\n directory?: Directory;\n\n /**\n * Whether to recursively remove the contents of the directory\n *\n * @default false\n * @since 1.0.0\n */\n recursive?: boolean;\n}\n\nexport interface ReaddirOptions {\n /**\n * The path of the directory to read\n *\n * @since 1.0.0\n */\n path: string;\n\n /**\n * The `Directory` to list files from\n *\n * @since 1.0.0\n */\n directory?: Directory;\n}\n\nexport interface GetUriOptions {\n /**\n * The path of the file to get the URI for\n *\n * @since 1.0.0\n */\n path: string;\n\n /**\n * The `Directory` to get the file under\n *\n * @since 1.0.0\n */\n directory: Directory;\n}\n\nexport interface StatOptions {\n /**\n * The path of the file to get data about\n *\n * @since 1.0.0\n */\n path: string;\n\n /**\n * The `Directory` to get the file under\n *\n * @since 1.0.0\n */\n directory?: Directory;\n}\n\nexport interface CopyOptions {\n /**\n * The existing file or directory\n *\n * @since 1.0.0\n */\n from: string;\n\n /**\n * The destination file or directory\n *\n * @since 1.0.0\n */\n to: string;\n\n /**\n * The `Directory` containing the existing file or directory\n *\n * @since 1.0.0\n */\n directory?: Directory;\n\n /**\n * The `Directory` containing the destination file or directory. If not supplied will use the 'directory'\n * parameter as the destination\n *\n * @since 1.0.0\n */\n toDirectory?: Directory;\n}\n\nexport type RenameOptions = CopyOptions;\n\nexport interface ReadFileResult {\n /**\n * The string representation of the data contained in the file\n *\n * @since 1.0.0\n */\n data: string;\n}\n\nexport interface WriteFileResult {\n /**\n * The uri where the file was written into\n *\n * @since 1.0.0\n */\n uri: string;\n}\n\nexport interface ReaddirResult {\n /**\n * List of files and directories inside the directory\n *\n * @since 1.0.0\n */\n files: FileInfo[];\n}\n\nexport interface FileInfo {\n /**\n * Name of the file or directory.\n */\n name: string;\n /**\n * Type of the file.\n *\n * @since 4.0.0\n */\n type: 'directory' | 'file';\n\n /**\n * Size of the file in bytes.\n *\n * @since 4.0.0\n */\n size: number;\n\n /**\n * Time of creation in milliseconds.\n *\n * It's not available on Android 7 and older devices.\n *\n * @since 4.0.0\n */\n ctime?: number;\n\n /**\n * Time of last modification in milliseconds.\n *\n * @since 4.0.0\n */\n mtime: number;\n\n /**\n * The uri of the file.\n *\n * @since 4.0.0\n */\n uri: string;\n}\n\nexport interface GetUriResult {\n /**\n * The uri of the file\n *\n * @since 1.0.0\n */\n uri: string;\n}\n\nexport interface StatResult {\n /**\n * Type of the file.\n *\n * @since 1.0.0\n */\n type: 'directory' | 'file';\n\n /**\n * Size of the file in bytes.\n *\n * @since 1.0.0\n */\n size: number;\n\n /**\n * Time of creation in milliseconds.\n *\n * It's not available on Android 7 and older devices.\n *\n * @since 1.0.0\n */\n ctime?: number;\n\n /**\n * Time of last modification in milliseconds.\n *\n * @since 1.0.0\n */\n mtime: number;\n\n /**\n * The uri of the file\n *\n * @since 1.0.0\n */\n uri: string;\n}\n\nexport interface CopyResult {\n /**\n * The uri where the file was copied into\n *\n * @since 4.0.0\n */\n uri: string;\n}\n\nexport interface DownloadFileOptions extends HttpOptions {\n /**\n * The path the downloaded file should be moved to.\n *\n * @since 5.1.0\n */\n path: string;\n /**\n * The directory to write the file to.\n * If this option is used, filePath can be a relative path rather than absolute.\n * The default is the `DATA` directory.\n *\n * @since 5.1.0\n */\n directory?: Directory;\n /**\n * An optional listener function to receive downloaded progress events.\n * If this option is used, progress event should be dispatched on every chunk received.\n * Chunks are throttled to every 100ms on Android/iOS to avoid slowdowns.\n *\n * @since 5.1.0\n */\n progress?: boolean;\n}\n\nexport interface DownloadFileResult {\n /**\n * The path the file was downloaded to.\n *\n * @since 5.1.0\n */\n path?: string;\n /**\n * The blob data of the downloaded file.\n * This is only available on web.\n *\n * @since 5.1.0\n */\n blob?: Blob;\n}\nexport interface ProgressStatus {\n /**\n * The url of the file being downloaded.\n *\n * @since 5.1.0\n */\n url: string;\n /**\n * The number of bytes downloaded so far.\n *\n * @since 5.1.0\n */\n bytes: number;\n /**\n * The total number of bytes to download for this file.\n *\n * @since 5.1.0\n */\n contentLength: number;\n}\n\n/**\n * A listener function that receives progress events.\n *\n * @since 5.1.0\n */\nexport type ProgressListener = (progress: ProgressStatus) => void;\n\nexport interface FilesystemPlugin {\n /**\n * Read a file from disk\n *\n * @since 1.0.0\n */\n readFile(options: ReadFileOptions): Promise<ReadFileResult>;\n\n /**\n * Write a file to disk in the specified location on device\n *\n * @since 1.0.0\n */\n writeFile(options: WriteFileOptions): Promise<WriteFileResult>;\n\n /**\n * Append to a file on disk in the specified location on device\n *\n * @since 1.0.0\n */\n appendFile(options: AppendFileOptions): Promise<void>;\n\n /**\n * Delete a file from disk\n *\n * @since 1.0.0\n */\n deleteFile(options: DeleteFileOptions): Promise<void>;\n\n /**\n * Create a directory.\n *\n * @since 1.0.0\n */\n mkdir(options: MkdirOptions): Promise<void>;\n\n /**\n * Remove a directory\n *\n * @since 1.0.0\n */\n rmdir(options: RmdirOptions): Promise<void>;\n\n /**\n * Return a list of files from the directory (not recursive)\n *\n * @since 1.0.0\n */\n readdir(options: ReaddirOptions): Promise<ReaddirResult>;\n\n /**\n * Return full File URI for a path and directory\n *\n * @since 1.0.0\n */\n getUri(options: GetUriOptions): Promise<GetUriResult>;\n\n /**\n * Return data about a file\n *\n * @since 1.0.0\n */\n stat(options: StatOptions): Promise<StatResult>;\n\n /**\n * Rename a file or directory\n *\n * @since 1.0.0\n */\n rename(options: RenameOptions): Promise<void>;\n\n /**\n * Copy a file or directory\n *\n * @since 1.0.0\n */\n copy(options: CopyOptions): Promise<CopyResult>;\n\n /**\n * Check read/write permissions.\n * Required on Android, only when using `Directory.Documents` or\n * `Directory.ExternalStorage`.\n *\n * @since 1.0.0\n */\n checkPermissions(): Promise<PermissionStatus>;\n\n /**\n * Request read/write permissions.\n * Required on Android, only when using `Directory.Documents` or\n * `Directory.ExternalStorage`.\n *\n * @since 1.0.0\n */\n requestPermissions(): Promise<PermissionStatus>;\n\n /**\n * Perform a http request to a server and download the file to the specified destination.\n *\n * @since 5.1.0\n */\n downloadFile(options: DownloadFileOptions): Promise<DownloadFileResult>;\n\n /**\n * Add a listener to file download progress events.\n *\n * @since 5.1.0\n */\n addListener(\n eventName: 'progress',\n listenerFunc: ProgressListener,\n ): Promise<PluginListenerHandle> & PluginListenerHandle;\n}\n\n/**\n * @deprecated Use `ReadFileOptions`.\n * @since 1.0.0\n */\nexport type FileReadOptions = ReadFileOptions;\n\n/**\n * @deprecated Use `ReadFileResult`.\n * @since 1.0.0\n */\nexport type FileReadResult = ReadFileResult;\n\n/**\n * @deprecated Use `WriteFileOptions`.\n * @since 1.0.0\n */\nexport type FileWriteOptions = WriteFileOptions;\n\n/**\n * @deprecated Use `WriteFileResult`.\n * @since 1.0.0\n */\nexport type FileWriteResult = WriteFileResult;\n\n/**\n * @deprecated Use `AppendFileOptions`.\n * @since 1.0.0\n */\nexport type FileAppendOptions = AppendFileOptions;\n\n/**\n * @deprecated Use `DeleteFileOptions`.\n * @since 1.0.0\n */\nexport type FileDeleteOptions = DeleteFileOptions;\n\n/**\n * @deprecated Use `Directory`.\n * @since 1.0.0\n */\nexport const FilesystemDirectory = Directory;\n\n/**\n * @deprecated Use `Encoding`.\n * @since 1.0.0\n */\nexport const FilesystemEncoding = Encoding;\n"]}
|