@capacitor/filesystem 1.0.7 → 4.0.0-beta.2

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/CHANGELOG.md CHANGED
@@ -3,6 +3,73 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [4.0.0-beta.2](https://github.com/ionic-team/capacitor-plugins/compare/4.0.0-beta.0...4.0.0-beta.2) (2022-07-08)
7
+
8
+ **Note:** Version bump only for package @capacitor/filesystem
9
+
10
+
11
+
12
+
13
+
14
+ # 4.0.0-beta.0 (2022-06-27)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **filesystem:** Prevent android crash on invalid base64 write ([#937](https://github.com/ionic-team/capacitor-plugins/issues/937)) ([1af0bfe](https://github.com/ionic-team/capacitor-plugins/commit/1af0bfe24d2a36bc2949fe52866131c3327b321e))
20
+ * **filesystem:** Throw errors instead of strings ([#746](https://github.com/ionic-team/capacitor-plugins/issues/746)) ([af4b875](https://github.com/ionic-team/capacitor-plugins/commit/af4b8750be512b869af07bcf96c1602eedc6758e))
21
+ * **filesystem:** web appendFile with base64 data ([#928](https://github.com/ionic-team/capacitor-plugins/issues/928)) ([80253cf](https://github.com/ionic-team/capacitor-plugins/commit/80253cf2652bf7fa9c07933989cbdffeadd52a27))
22
+ * correct addListeners links ([#655](https://github.com/ionic-team/capacitor-plugins/issues/655)) ([f9871e7](https://github.com/ionic-team/capacitor-plugins/commit/f9871e7bd53478addb21155e148829f550c0e457))
23
+ * inline source code in esm map files ([#760](https://github.com/ionic-team/capacitor-plugins/issues/760)) ([a960489](https://github.com/ionic-team/capacitor-plugins/commit/a960489a19db0182b90d187a50deff9dfbe51038))
24
+ * remove postpublish scripts ([#656](https://github.com/ionic-team/capacitor-plugins/issues/656)) ([ed6ac49](https://github.com/ionic-team/capacitor-plugins/commit/ed6ac499ebf4a47525071ccbfc36c27503e11f60))
25
+ * **android:** permissions use "publicStorage" as alias ([#202](https://github.com/ionic-team/capacitor-plugins/issues/202)) ([2dfc7a3](https://github.com/ionic-team/capacitor-plugins/commit/2dfc7a3261a4f98871a86fe6d47fab084a2d1deb))
26
+ * **android:** support writing files without scheme ([#241](https://github.com/ionic-team/capacitor-plugins/issues/241)) ([4285cb1](https://github.com/ionic-team/capacitor-plugins/commit/4285cb1d37ec3361e7ec4da4786502693b04d478))
27
+ * **filesystem:** allow copy if from is not parent of to ([#546](https://github.com/ionic-team/capacitor-plugins/issues/546)) ([a70414e](https://github.com/ionic-team/capacitor-plugins/commit/a70414e79189579ff1a0b5c2a90d12491f5c23cf))
28
+ * **filesystem:** Append doesn't resolve on iOS ([#305](https://github.com/ionic-team/capacitor-plugins/issues/305)) ([98e91cd](https://github.com/ionic-team/capacitor-plugins/commit/98e91cd745fb12bf46f99233bb527f147dbba58b))
29
+ * **filesystem:** Convert stat ctime/mtime timestamp to milliseconds ([#321](https://github.com/ionic-team/capacitor-plugins/issues/321)) ([d978986](https://github.com/ionic-team/capacitor-plugins/commit/d97898662d0ba037e5f8448990a91de5ec6a4234))
30
+ * **filesystem:** copy doesn't resolve on Android ([#233](https://github.com/ionic-team/capacitor-plugins/issues/233)) ([17cbf3b](https://github.com/ionic-team/capacitor-plugins/commit/17cbf3b0ada97f1279fba32b551c380c0e669406))
31
+ * **filesystem:** is not requesting permission on public directories ([#246](https://github.com/ionic-team/capacitor-plugins/issues/246)) ([aa897ab](https://github.com/ionic-team/capacitor-plugins/commit/aa897ab4269e34cd5d762ed645030054ddda7dd6))
32
+ * **filesystem:** Make ctime optional ([#373](https://github.com/ionic-team/capacitor-plugins/issues/373)) ([e3c6212](https://github.com/ionic-team/capacitor-plugins/commit/e3c6212b94c75cf747a8768af5056963683953b2))
33
+ * **filesystem:** rmdir doesn't resolve on iOS ([#239](https://github.com/ionic-team/capacitor-plugins/issues/239)) ([7ca538b](https://github.com/ionic-team/capacitor-plugins/commit/7ca538bb47e2e00080eadfe8d875323c1e198cb2))
34
+ * add es2017 lib to tsconfig ([#180](https://github.com/ionic-team/capacitor-plugins/issues/180)) ([2c3776c](https://github.com/ionic-team/capacitor-plugins/commit/2c3776c38ca025c5ee965dec10ccf1cdb6c02e2f))
35
+ * support deprecated types from Capacitor 2 ([#139](https://github.com/ionic-team/capacitor-plugins/issues/139)) ([2d7127a](https://github.com/ionic-team/capacitor-plugins/commit/2d7127a488e26f0287951921a6db47c49d817336))
36
+ * **filesystem:** Use PermissionState from @capacitor/core ([#148](https://github.com/ionic-team/capacitor-plugins/issues/148)) ([5ce3c5d](https://github.com/ionic-team/capacitor-plugins/commit/5ce3c5d491a35b8771661f3e4eb98aac6df15911))
37
+
38
+
39
+ ### Features
40
+
41
+ * set targetSDK default value to 32 ([#970](https://github.com/ionic-team/capacitor-plugins/issues/970)) ([fa70d96](https://github.com/ionic-team/capacitor-plugins/commit/fa70d96f141af751aae53ceb5642c46b204f5958))
42
+ * **filesystem:** Make readDir return files information ([#949](https://github.com/ionic-team/capacitor-plugins/issues/949)) ([0a9f43d](https://github.com/ionic-team/capacitor-plugins/commit/0a9f43dffd3815f600c35ed4528c017644fdb55e))
43
+ * **filesystem:** Return path of copied file ([#931](https://github.com/ionic-team/capacitor-plugins/issues/931)) ([310f583](https://github.com/ionic-team/capacitor-plugins/commit/310f583ccec58730ab8046a1618782c950c60656))
44
+ * add commonjs output format ([#179](https://github.com/ionic-team/capacitor-plugins/issues/179)) ([8e9e098](https://github.com/ionic-team/capacitor-plugins/commit/8e9e09862064b3f6771d7facbc4008e995d9b463))
45
+ * Filesystem plugin ([#19](https://github.com/ionic-team/capacitor-plugins/issues/19)) ([3b86a4a](https://github.com/ionic-team/capacitor-plugins/commit/3b86a4a972e00eaed1d078bfcc69af6136222dc4))
46
+ * set targetSDK default value to 31 ([#824](https://github.com/ionic-team/capacitor-plugins/issues/824)) ([3ee10de](https://github.com/ionic-team/capacitor-plugins/commit/3ee10de98067984c1a4e75295d001c5a895c47f4))
47
+ * Upgrade gradle to 7.4 ([#826](https://github.com/ionic-team/capacitor-plugins/issues/826)) ([5db0906](https://github.com/ionic-team/capacitor-plugins/commit/5db0906f6264287c4f8e69dbaecf19d4d387824b))
48
+ * Use java 11 ([#910](https://github.com/ionic-team/capacitor-plugins/issues/910)) ([5acb2a2](https://github.com/ionic-team/capacitor-plugins/commit/5acb2a288a413492b163e4e97da46a085d9e4be0))
49
+ * **android:** implements Activity Result API changes for permissions and activity results ([#222](https://github.com/ionic-team/capacitor-plugins/issues/222)) ([f671b9f](https://github.com/ionic-team/capacitor-plugins/commit/f671b9f4b472806ef43db6dcf302d4503cf1828c))
50
+ * **filesystem:** Allow the use of absolute urls on iOS and web ([#250](https://github.com/ionic-team/capacitor-plugins/issues/250)) ([03ad97c](https://github.com/ionic-team/capacitor-plugins/commit/03ad97c1b7450e864504198853aac2b3bdc4b8a4))
51
+ * **filesystem:** support Library directory ([#666](https://github.com/ionic-team/capacitor-plugins/issues/666)) ([ce7ee95](https://github.com/ionic-team/capacitor-plugins/commit/ce7ee958b141f1dd4f86493923455f8264d0b6db))
52
+
53
+
54
+
55
+
56
+
57
+ # [1.1.0](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/filesystem@1.0.7...@capacitor/filesystem@1.1.0) (2022-01-19)
58
+
59
+
60
+ ### Bug Fixes
61
+
62
+ * inline source code in esm map files ([#760](https://github.com/ionic-team/capacitor-plugins/issues/760)) ([a960489](https://github.com/ionic-team/capacitor-plugins/commit/a960489a19db0182b90d187a50deff9dfbe51038))
63
+
64
+
65
+ ### Features
66
+
67
+ * **filesystem:** support Library directory ([#666](https://github.com/ionic-team/capacitor-plugins/issues/666)) ([ce7ee95](https://github.com/ionic-team/capacitor-plugins/commit/ce7ee958b141f1dd4f86493923455f8264d0b6db))
68
+
69
+
70
+
71
+
72
+
6
73
  ## [1.0.7](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/filesystem@1.0.6...@capacitor/filesystem@1.0.7) (2022-01-10)
7
74
 
8
75
 
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.author = package['author']
12
12
  s.source = { :git => 'https://github.com/ionic-team/capacitor-plugins.git', :tag => package['name'] + '@' + package['version'] }
13
13
  s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}', 'filesystem/ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
- s.ios.deployment_target = '12.0'
14
+ s.ios.deployment_target = '13.0'
15
15
  s.dependency 'Capacitor'
16
16
  s.swift_version = '5.1'
17
17
  end
package/README.md CHANGED
@@ -282,7 +282,7 @@ Rename a file or directory
282
282
  ### copy(...)
283
283
 
284
284
  ```typescript
285
- copy(options: CopyOptions) => Promise<void>
285
+ copy(options: CopyOptions) => Promise<CopyResult>
286
286
  ```
287
287
 
288
288
  Copy a file or directory
@@ -291,6 +291,8 @@ Copy a file or directory
291
291
  | ------------- | --------------------------------------------------- |
292
292
  | **`options`** | <code><a href="#copyoptions">CopyOptions</a></code> |
293
293
 
294
+ **Returns:** <code>Promise&lt;<a href="#copyresult">CopyResult</a>&gt;</code>
295
+
294
296
  **Since:** 1.0.0
295
297
 
296
298
  --------------------
@@ -405,9 +407,21 @@ Required on Android, only when using <a href="#directory">`Directory.Documents`<
405
407
 
406
408
  #### ReaddirResult
407
409
 
408
- | Prop | Type | Description | Since |
409
- | ----------- | --------------------- | -------------------------------------------------- | ----- |
410
- | **`files`** | <code>string[]</code> | List of files and directories inside the directory | 1.0.0 |
410
+ | Prop | Type | Description | Since |
411
+ | ----------- | ----------------------- | -------------------------------------------------- | ----- |
412
+ | **`files`** | <code>FileInfo[]</code> | List of files and directories inside the directory | 1.0.0 |
413
+
414
+
415
+ #### FileInfo
416
+
417
+ | Prop | Type | Description | Since |
418
+ | ----------- | ---------------------------------- | ------------------------------------------------------------------------------------ | ----- |
419
+ | **`name`** | <code>string</code> | Name of the file or directory. | |
420
+ | **`type`** | <code>'directory' \| 'file'</code> | Type of the file. | 4.0.0 |
421
+ | **`size`** | <code>number</code> | Size of the file in bytes. | 4.0.0 |
422
+ | **`ctime`** | <code>number</code> | Time of creation in milliseconds. It's not available on Android 7 and older devices. | 4.0.0 |
423
+ | **`mtime`** | <code>number</code> | Time of last modification in milliseconds. | 4.0.0 |
424
+ | **`uri`** | <code>string</code> | The uri of the file. | 4.0.0 |
411
425
 
412
426
 
413
427
  #### ReaddirOptions
@@ -435,13 +449,13 @@ Required on Android, only when using <a href="#directory">`Directory.Documents`<
435
449
 
436
450
  #### StatResult
437
451
 
438
- | Prop | Type | Description | Since |
439
- | ----------- | ------------------- | ------------------------------------------------------------------------------------ | ----- |
440
- | **`type`** | <code>string</code> | Type of the file | 1.0.0 |
441
- | **`size`** | <code>number</code> | Size of the file | 1.0.0 |
442
- | **`ctime`** | <code>number</code> | Time of creation in milliseconds. It's not available on Android 7 and older devices. | 1.0.0 |
443
- | **`mtime`** | <code>number</code> | Time of last modification in milliseconds. | 1.0.0 |
444
- | **`uri`** | <code>string</code> | The uri of the file | 1.0.0 |
452
+ | Prop | Type | Description | Since |
453
+ | ----------- | ---------------------------------- | ------------------------------------------------------------------------------------ | ----- |
454
+ | **`type`** | <code>'directory' \| 'file'</code> | Type of the file. | 1.0.0 |
455
+ | **`size`** | <code>number</code> | Size of the file in bytes. | 1.0.0 |
456
+ | **`ctime`** | <code>number</code> | Time of creation in milliseconds. It's not available on Android 7 and older devices. | 1.0.0 |
457
+ | **`mtime`** | <code>number</code> | Time of last modification in milliseconds. | 1.0.0 |
458
+ | **`uri`** | <code>string</code> | The uri of the file | 1.0.0 |
445
459
 
446
460
 
447
461
  #### StatOptions
@@ -462,6 +476,13 @@ Required on Android, only when using <a href="#directory">`Directory.Documents`<
462
476
  | **`toDirectory`** | <code><a href="#directory">Directory</a></code> | The <a href="#directory">`Directory`</a> containing the destination file or directory. If not supplied will use the 'directory' parameter as the destination | 1.0.0 |
463
477
 
464
478
 
479
+ #### CopyResult
480
+
481
+ | Prop | Type | Description | Since |
482
+ | --------- | ------------------- | -------------------------------------- | ----- |
483
+ | **`uri`** | <code>string</code> | The uri where the file was copied into | 4.0.0 |
484
+
485
+
465
486
  #### PermissionStatus
466
487
 
467
488
  | Prop | Type |
@@ -490,7 +511,8 @@ Required on Android, only when using <a href="#directory">`Directory.Documents`<
490
511
  | Members | Value | Description | Since |
491
512
  | --------------------- | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
492
513
  | **`Documents`** | <code>'DOCUMENTS'</code> | The Documents directory On iOS it's the app's documents directory. Use this directory to store user-generated content. On Android it's the Public Documents folder, so it's accessible from other apps. It's not accesible on Android 10 unless the app enables legacy External Storage by adding `android:requestLegacyExternalStorage="true"` in the `application` tag in the `AndroidManifest.xml`. It's not accesible on Android 11 or newer. | 1.0.0 |
493
- | **`Data`** | <code>'DATA'</code> | The Data directory On iOS it will use the Documents directory On Android it's the directory holding application files. Files will be deleted when the application is uninstalled. | 1.0.0 |
514
+ | **`Data`** | <code>'DATA'</code> | The Data directory On iOS it will use the Documents directory. On Android it's the directory holding application files. Files will be deleted when the application is uninstalled. | 1.0.0 |
515
+ | **`Library`** | <code>'LIBRARY'</code> | The Library directory On iOS it will use the Library directory. On Android it's the directory holding application files. Files will be deleted when the application is uninstalled. | 1.1.0 |
494
516
  | **`Cache`** | <code>'CACHE'</code> | The Cache directory Can be deleted in cases of low memory, so use this directory to write app-specific files that your app can re-create easily. | 1.0.0 |
495
517
  | **`External`** | <code>'EXTERNAL'</code> | The external directory On iOS it will use the Documents directory On Android it's the directory on the primary shared/external storage device where the application can place persistent files it owns. These files are internal to the applications, and not typically visible to the user as media. Files will be deleted when the application is uninstalled. | 1.0.0 |
496
518
  | **`ExternalStorage`** | <code>'EXTERNAL_STORAGE'</code> | The external storage directory On iOS it will use the Documents directory On Android it's the primary shared/external storage directory. It's not accesible on Android 10 unless the app enables legacy External Storage by adding `android:requestLegacyExternalStorage="true"` in the `application` tag in the `AndroidManifest.xml`. It's not accesible on Android 11 or newer. | 1.0.0 |
@@ -1,7 +1,7 @@
1
1
  ext {
2
- junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.1'
3
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.2'
4
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.3.0'
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.3'
4
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.4.0'
5
5
  }
6
6
 
7
7
  buildscript {
@@ -10,17 +10,17 @@ buildscript {
10
10
  mavenCentral()
11
11
  }
12
12
  dependencies {
13
- classpath 'com.android.tools.build:gradle:4.2.1'
13
+ classpath 'com.android.tools.build:gradle:7.2.1'
14
14
  }
15
15
  }
16
16
 
17
17
  apply plugin: 'com.android.library'
18
18
 
19
19
  android {
20
- compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 30
20
+ compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 32
21
21
  defaultConfig {
22
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21
23
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 30
22
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
23
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 32
24
24
  versionCode 1
25
25
  versionName "1.0"
26
26
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -35,14 +35,13 @@ android {
35
35
  abortOnError false
36
36
  }
37
37
  compileOptions {
38
- sourceCompatibility JavaVersion.VERSION_1_8
39
- targetCompatibility JavaVersion.VERSION_1_8
38
+ sourceCompatibility JavaVersion.VERSION_11
39
+ targetCompatibility JavaVersion.VERSION_11
40
40
  }
41
41
  }
42
42
 
43
43
  repositories {
44
44
  google()
45
- jcenter()
46
45
  mavenCentral()
47
46
  }
48
47
 
@@ -72,18 +72,18 @@ public class Filesystem {
72
72
  return created;
73
73
  }
74
74
 
75
- public String[] readdir(String path, String directory) throws DirectoryNotFoundException {
76
- String[] files = null;
75
+ public File[] readdir(String path, String directory) throws DirectoryNotFoundException {
76
+ File[] files = null;
77
77
  File fileObject = getFileObject(path, directory);
78
78
  if (fileObject != null && fileObject.exists()) {
79
- files = fileObject.list();
79
+ files = fileObject.listFiles();
80
80
  } else {
81
81
  throw new DirectoryNotFoundException("Directory does not exist");
82
82
  }
83
83
  return files;
84
84
  }
85
85
 
86
- public boolean copy(String from, String directory, String to, String toDirectory, boolean doRename)
86
+ public File copy(String from, String directory, String to, String toDirectory, boolean doRename)
87
87
  throws IOException, CopyFailedException {
88
88
  if (toDirectory == null) {
89
89
  toDirectory = directory;
@@ -100,7 +100,7 @@ public class Filesystem {
100
100
  }
101
101
 
102
102
  if (toObject.equals(fromObject)) {
103
- return true;
103
+ return toObject;
104
104
  }
105
105
 
106
106
  if (!fromObject.exists()) {
@@ -130,7 +130,7 @@ public class Filesystem {
130
130
  copyRecursively(fromObject, toObject);
131
131
  }
132
132
 
133
- return true;
133
+ return toObject;
134
134
  }
135
135
 
136
136
  public InputStream getInputStream(String path, String directory) throws IOException {
@@ -180,12 +180,14 @@ public class Filesystem {
180
180
  return Base64.encodeToString(byteStream.toByteArray(), Base64.NO_WRAP);
181
181
  }
182
182
 
183
+ @SuppressWarnings("deprecation")
183
184
  public File getDirectory(String directory) {
184
185
  Context c = this.context;
185
186
  switch (directory) {
186
187
  case "DOCUMENTS":
187
188
  return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
188
189
  case "DATA":
190
+ case "LIBRARY":
189
191
  return c.getFilesDir();
190
192
  case "CACHE":
191
193
  return c.getCacheDir();
@@ -169,6 +169,8 @@ public class FilesystemPlugin extends Plugin {
169
169
  ex
170
170
  );
171
171
  call.reject("FILE_NOTCREATED");
172
+ } catch (IllegalArgumentException ex) {
173
+ call.reject("The supplied data is not valid base64 content.");
172
174
  }
173
175
  }
174
176
 
@@ -267,10 +269,37 @@ public class FilesystemPlugin extends Plugin {
267
269
  requestAllPermissions(call, "permissionCallback");
268
270
  } else {
269
271
  try {
270
- String[] files = implementation.readdir(path, directory);
272
+ File[] files = implementation.readdir(path, directory);
273
+ JSArray filesArray = new JSArray();
271
274
  if (files != null) {
275
+ for (var i = 0; i < files.length; i++) {
276
+ File fileObject = files[i];
277
+ JSObject data = new JSObject();
278
+ data.put("name", fileObject.getName());
279
+ data.put("type", fileObject.isDirectory() ? "directory" : "file");
280
+ data.put("size", fileObject.length());
281
+ data.put("mtime", fileObject.lastModified());
282
+ data.put("uri", Uri.fromFile(fileObject).toString());
283
+
284
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
285
+ try {
286
+ BasicFileAttributes attr = Files.readAttributes(fileObject.toPath(), BasicFileAttributes.class);
287
+
288
+ // use whichever is the oldest between creationTime and lastAccessTime
289
+ if (attr.creationTime().toMillis() < attr.lastAccessTime().toMillis()) {
290
+ data.put("ctime", attr.creationTime().toMillis());
291
+ } else {
292
+ data.put("ctime", attr.lastAccessTime().toMillis());
293
+ }
294
+ } catch (Exception ex) {}
295
+ } else {
296
+ data.put("ctime", null);
297
+ }
298
+ filesArray.put(data);
299
+ }
300
+
272
301
  JSObject ret = new JSObject();
273
- ret.put("files", JSArray.from(files));
302
+ ret.put("files", filesArray);
274
303
  call.resolve(ret);
275
304
  } else {
276
305
  call.reject("Unable to read directory");
@@ -364,8 +393,14 @@ public class FilesystemPlugin extends Plugin {
364
393
  }
365
394
  }
366
395
  try {
367
- implementation.copy(from, directory, to, toDirectory, doRename);
368
- call.resolve();
396
+ File file = implementation.copy(from, directory, to, toDirectory, doRename);
397
+ if (!doRename) {
398
+ JSObject result = new JSObject();
399
+ result.put("uri", Uri.fromFile(file).toString());
400
+ call.resolve(result);
401
+ } else {
402
+ call.resolve();
403
+ }
369
404
  } catch (CopyFailedException ex) {
370
405
  call.reject(ex.getMessage());
371
406
  } catch (IOException ex) {
package/dist/docs.json CHANGED
@@ -242,7 +242,7 @@
242
242
  },
243
243
  {
244
244
  "name": "copy",
245
- "signature": "(options: CopyOptions) => Promise<void>",
245
+ "signature": "(options: CopyOptions) => Promise<CopyResult>",
246
246
  "parameters": [
247
247
  {
248
248
  "name": "options",
@@ -250,7 +250,7 @@
250
250
  "type": "CopyOptions"
251
251
  }
252
252
  ],
253
- "returns": "Promise<void>",
253
+ "returns": "Promise<CopyResult>",
254
254
  "tags": [
255
255
  {
256
256
  "name": "since",
@@ -259,6 +259,7 @@
259
259
  ],
260
260
  "docs": "Copy a file or directory",
261
261
  "complexTypes": [
262
+ "CopyResult",
262
263
  "CopyOptions"
263
264
  ],
264
265
  "slug": "copy"
@@ -683,8 +684,86 @@
683
684
  }
684
685
  ],
685
686
  "docs": "List of files and directories inside the directory",
687
+ "complexTypes": [
688
+ "FileInfo"
689
+ ],
690
+ "type": "FileInfo[]"
691
+ }
692
+ ]
693
+ },
694
+ {
695
+ "name": "FileInfo",
696
+ "slug": "fileinfo",
697
+ "docs": "",
698
+ "tags": [],
699
+ "methods": [],
700
+ "properties": [
701
+ {
702
+ "name": "name",
703
+ "tags": [],
704
+ "docs": "Name of the file or directory.",
705
+ "complexTypes": [],
706
+ "type": "string"
707
+ },
708
+ {
709
+ "name": "type",
710
+ "tags": [
711
+ {
712
+ "text": "4.0.0",
713
+ "name": "since"
714
+ }
715
+ ],
716
+ "docs": "Type of the file.",
717
+ "complexTypes": [],
718
+ "type": "'directory' | 'file'"
719
+ },
720
+ {
721
+ "name": "size",
722
+ "tags": [
723
+ {
724
+ "text": "4.0.0",
725
+ "name": "since"
726
+ }
727
+ ],
728
+ "docs": "Size of the file in bytes.",
729
+ "complexTypes": [],
730
+ "type": "number"
731
+ },
732
+ {
733
+ "name": "ctime",
734
+ "tags": [
735
+ {
736
+ "text": "4.0.0",
737
+ "name": "since"
738
+ }
739
+ ],
740
+ "docs": "Time of creation in milliseconds.\n\nIt's not available on Android 7 and older devices.",
741
+ "complexTypes": [],
742
+ "type": "number | undefined"
743
+ },
744
+ {
745
+ "name": "mtime",
746
+ "tags": [
747
+ {
748
+ "text": "4.0.0",
749
+ "name": "since"
750
+ }
751
+ ],
752
+ "docs": "Time of last modification in milliseconds.",
686
753
  "complexTypes": [],
687
- "type": "string[]"
754
+ "type": "number"
755
+ },
756
+ {
757
+ "name": "uri",
758
+ "tags": [
759
+ {
760
+ "text": "4.0.0",
761
+ "name": "since"
762
+ }
763
+ ],
764
+ "docs": "The uri of the file.",
765
+ "complexTypes": [],
766
+ "type": "string"
688
767
  }
689
768
  ]
690
769
  },
@@ -794,9 +873,9 @@
794
873
  "name": "since"
795
874
  }
796
875
  ],
797
- "docs": "Type of the file",
876
+ "docs": "Type of the file.",
798
877
  "complexTypes": [],
799
- "type": "string"
878
+ "type": "'directory' | 'file'"
800
879
  },
801
880
  {
802
881
  "name": "size",
@@ -806,7 +885,7 @@
806
885
  "name": "since"
807
886
  }
808
887
  ],
809
- "docs": "Size of the file",
888
+ "docs": "Size of the file in bytes.",
810
889
  "complexTypes": [],
811
890
  "type": "number"
812
891
  },
@@ -944,6 +1023,27 @@
944
1023
  }
945
1024
  ]
946
1025
  },
1026
+ {
1027
+ "name": "CopyResult",
1028
+ "slug": "copyresult",
1029
+ "docs": "",
1030
+ "tags": [],
1031
+ "methods": [],
1032
+ "properties": [
1033
+ {
1034
+ "name": "uri",
1035
+ "tags": [
1036
+ {
1037
+ "text": "4.0.0",
1038
+ "name": "since"
1039
+ }
1040
+ ],
1041
+ "docs": "The uri where the file was copied into",
1042
+ "complexTypes": [],
1043
+ "type": "string"
1044
+ }
1045
+ ]
1046
+ },
947
1047
  {
948
1048
  "name": "PermissionStatus",
949
1049
  "slug": "permissionstatus",
@@ -988,7 +1088,18 @@
988
1088
  "name": "since"
989
1089
  }
990
1090
  ],
991
- "docs": "The Data directory\nOn iOS it will use the Documents directory\nOn Android it's the directory holding application files.\nFiles will be deleted when the application is uninstalled."
1091
+ "docs": "The Data directory\nOn iOS it will use the Documents directory.\nOn Android it's the directory holding application files.\nFiles will be deleted when the application is uninstalled."
1092
+ },
1093
+ {
1094
+ "name": "Library",
1095
+ "value": "'LIBRARY'",
1096
+ "tags": [
1097
+ {
1098
+ "text": "1.1.0",
1099
+ "name": "since"
1100
+ }
1101
+ ],
1102
+ "docs": "The Library directory\nOn iOS it will use the Library directory.\nOn Android it's the directory holding application files.\nFiles will be deleted when the application is uninstalled."
992
1103
  },
993
1104
  {
994
1105
  "name": "Cache",
@@ -18,13 +18,22 @@ export declare enum Directory {
18
18
  Documents = "DOCUMENTS",
19
19
  /**
20
20
  * The Data directory
21
- * On iOS it will use the Documents directory
21
+ * On iOS it will use the Documents directory.
22
22
  * On Android it's the directory holding application files.
23
23
  * Files will be deleted when the application is uninstalled.
24
24
  *
25
25
  * @since 1.0.0
26
26
  */
27
27
  Data = "DATA",
28
+ /**
29
+ * The Library directory
30
+ * On iOS it will use the Library directory.
31
+ * On Android it's the directory holding application files.
32
+ * Files will be deleted when the application is uninstalled.
33
+ *
34
+ * @since 1.1.0
35
+ */
36
+ Library = "LIBRARY",
28
37
  /**
29
38
  * The Cache directory
30
39
  * Can be deleted in cases of low memory, so use this directory to write app-specific files
@@ -318,7 +327,45 @@ export interface ReaddirResult {
318
327
  *
319
328
  * @since 1.0.0
320
329
  */
321
- files: string[];
330
+ files: FileInfo[];
331
+ }
332
+ export interface FileInfo {
333
+ /**
334
+ * Name of the file or directory.
335
+ */
336
+ name: string;
337
+ /**
338
+ * Type of the file.
339
+ *
340
+ * @since 4.0.0
341
+ */
342
+ type: 'directory' | 'file';
343
+ /**
344
+ * Size of the file in bytes.
345
+ *
346
+ * @since 4.0.0
347
+ */
348
+ size: number;
349
+ /**
350
+ * Time of creation in milliseconds.
351
+ *
352
+ * It's not available on Android 7 and older devices.
353
+ *
354
+ * @since 4.0.0
355
+ */
356
+ ctime?: number;
357
+ /**
358
+ * Time of last modification in milliseconds.
359
+ *
360
+ * @since 4.0.0
361
+ */
362
+ mtime: number;
363
+ /**
364
+ * The uri of the file.
365
+ *
366
+ * @since 4.0.0
367
+ */
368
+ uri: string;
322
369
  }
323
370
  export interface GetUriResult {
324
371
  /**
@@ -330,13 +377,13 @@ export interface GetUriResult {
330
377
  }
331
378
  export interface StatResult {
332
379
  /**
333
- * Type of the file
380
+ * Type of the file.
334
381
  *
335
382
  * @since 1.0.0
336
383
  */
337
- type: string;
384
+ type: 'directory' | 'file';
338
385
  /**
339
- * Size of the file
386
+ * Size of the file in bytes.
340
387
  *
341
388
  * @since 1.0.0
342
389
  */
@@ -362,6 +409,14 @@ export interface StatResult {
362
409
  */
363
410
  uri: string;
364
411
  }
412
+ export interface CopyResult {
413
+ /**
414
+ * The uri where the file was copied into
415
+ *
416
+ * @since 4.0.0
417
+ */
418
+ uri: string;
419
+ }
365
420
  export interface FilesystemPlugin {
366
421
  /**
367
422
  * Read a file from disk
@@ -428,7 +483,7 @@ export interface FilesystemPlugin {
428
483
  *
429
484
  * @since 1.0.0
430
485
  */
431
- copy(options: CopyOptions): Promise<void>;
486
+ copy(options: CopyOptions): Promise<CopyResult>;
432
487
  /**
433
488
  * Check read/write permissions.
434
489
  * Required on Android, only when using `Directory.Documents` or