@capacitor/filesystem
Advanced tools
Comparing version 1.1.0 to 4.0.0-beta.0
@@ -6,2 +6,45 @@ # Change Log | ||
# 4.0.0-beta.0 (2022-06-27) | ||
### Bug Fixes | ||
* **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)) | ||
* **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)) | ||
* **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)) | ||
* correct addListeners links ([#655](https://github.com/ionic-team/capacitor-plugins/issues/655)) ([f9871e7](https://github.com/ionic-team/capacitor-plugins/commit/f9871e7bd53478addb21155e148829f550c0e457)) | ||
* 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)) | ||
* remove postpublish scripts ([#656](https://github.com/ionic-team/capacitor-plugins/issues/656)) ([ed6ac49](https://github.com/ionic-team/capacitor-plugins/commit/ed6ac499ebf4a47525071ccbfc36c27503e11f60)) | ||
* **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)) | ||
* **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)) | ||
* **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)) | ||
* **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)) | ||
* **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)) | ||
* **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)) | ||
* **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)) | ||
* **filesystem:** Make ctime optional ([#373](https://github.com/ionic-team/capacitor-plugins/issues/373)) ([e3c6212](https://github.com/ionic-team/capacitor-plugins/commit/e3c6212b94c75cf747a8768af5056963683953b2)) | ||
* **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)) | ||
* 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)) | ||
* 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)) | ||
* **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)) | ||
### Features | ||
* 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)) | ||
* **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)) | ||
* **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)) | ||
* add commonjs output format ([#179](https://github.com/ionic-team/capacitor-plugins/issues/179)) ([8e9e098](https://github.com/ionic-team/capacitor-plugins/commit/8e9e09862064b3f6771d7facbc4008e995d9b463)) | ||
* Filesystem plugin ([#19](https://github.com/ionic-team/capacitor-plugins/issues/19)) ([3b86a4a](https://github.com/ionic-team/capacitor-plugins/commit/3b86a4a972e00eaed1d078bfcc69af6136222dc4)) | ||
* 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)) | ||
* 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)) | ||
* Use java 11 ([#910](https://github.com/ionic-team/capacitor-plugins/issues/910)) ([5acb2a2](https://github.com/ionic-team/capacitor-plugins/commit/5acb2a288a413492b163e4e97da46a085d9e4be0)) | ||
* **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)) | ||
* **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)) | ||
* **filesystem:** support Library directory ([#666](https://github.com/ionic-team/capacitor-plugins/issues/666)) ([ce7ee95](https://github.com/ionic-team/capacitor-plugins/commit/ce7ee958b141f1dd4f86493923455f8264d0b6db)) | ||
# [1.1.0](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/filesystem@1.0.7...@capacitor/filesystem@1.1.0) (2022-01-19) | ||
@@ -8,0 +51,0 @@ |
@@ -245,3 +245,3 @@ { | ||
"name": "copy", | ||
"signature": "(options: CopyOptions) => Promise<void>", | ||
"signature": "(options: CopyOptions) => Promise<CopyResult>", | ||
"parameters": [ | ||
@@ -254,3 +254,3 @@ { | ||
], | ||
"returns": "Promise<void>", | ||
"returns": "Promise<CopyResult>", | ||
"tags": [ | ||
@@ -264,2 +264,3 @@ { | ||
"complexTypes": [ | ||
"CopyResult", | ||
"CopyOptions" | ||
@@ -689,4 +690,82 @@ ], | ||
"docs": "List of files and directories inside the directory", | ||
"complexTypes": [ | ||
"FileInfo" | ||
], | ||
"type": "FileInfo[]" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "FileInfo", | ||
"slug": "fileinfo", | ||
"docs": "", | ||
"tags": [], | ||
"methods": [], | ||
"properties": [ | ||
{ | ||
"name": "name", | ||
"tags": [], | ||
"docs": "Name of the file or directory.", | ||
"complexTypes": [], | ||
"type": "string[]" | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "type", | ||
"tags": [ | ||
{ | ||
"text": "4.0.0", | ||
"name": "since" | ||
} | ||
], | ||
"docs": "Type of the file.", | ||
"complexTypes": [], | ||
"type": "'directory' | 'file'" | ||
}, | ||
{ | ||
"name": "size", | ||
"tags": [ | ||
{ | ||
"text": "4.0.0", | ||
"name": "since" | ||
} | ||
], | ||
"docs": "Size of the file in bytes.", | ||
"complexTypes": [], | ||
"type": "number" | ||
}, | ||
{ | ||
"name": "ctime", | ||
"tags": [ | ||
{ | ||
"text": "4.0.0", | ||
"name": "since" | ||
} | ||
], | ||
"docs": "Time of creation in milliseconds.\n\nIt's not available on Android 7 and older devices.", | ||
"complexTypes": [], | ||
"type": "number | undefined" | ||
}, | ||
{ | ||
"name": "mtime", | ||
"tags": [ | ||
{ | ||
"text": "4.0.0", | ||
"name": "since" | ||
} | ||
], | ||
"docs": "Time of last modification in milliseconds.", | ||
"complexTypes": [], | ||
"type": "number" | ||
}, | ||
{ | ||
"name": "uri", | ||
"tags": [ | ||
{ | ||
"text": "4.0.0", | ||
"name": "since" | ||
} | ||
], | ||
"docs": "The uri of the file.", | ||
"complexTypes": [], | ||
"type": "string" | ||
} | ||
@@ -801,5 +880,5 @@ ] | ||
], | ||
"docs": "Type of the file", | ||
"docs": "Type of the file.", | ||
"complexTypes": [], | ||
"type": "string" | ||
"type": "'directory' | 'file'" | ||
}, | ||
@@ -814,3 +893,3 @@ { | ||
], | ||
"docs": "Size of the file", | ||
"docs": "Size of the file in bytes.", | ||
"complexTypes": [], | ||
@@ -954,2 +1033,23 @@ "type": "number" | ||
{ | ||
"name": "CopyResult", | ||
"slug": "copyresult", | ||
"docs": "", | ||
"tags": [], | ||
"methods": [], | ||
"properties": [ | ||
{ | ||
"name": "uri", | ||
"tags": [ | ||
{ | ||
"text": "4.0.0", | ||
"name": "since" | ||
} | ||
], | ||
"docs": "The uri where the file was copied into", | ||
"complexTypes": [], | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "PermissionStatus", | ||
@@ -956,0 +1056,0 @@ "slug": "permissionstatus", |
@@ -330,4 +330,42 @@ import type { PermissionState } from '@capacitor/core'; | ||
*/ | ||
files: string[]; | ||
files: FileInfo[]; | ||
} | ||
export interface FileInfo { | ||
/** | ||
* Name of the file or directory. | ||
*/ | ||
name: string; | ||
/** | ||
* Type of the file. | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
type: 'directory' | 'file'; | ||
/** | ||
* Size of the file in bytes. | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
size: number; | ||
/** | ||
* Time of creation in milliseconds. | ||
* | ||
* It's not available on Android 7 and older devices. | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
ctime?: number; | ||
/** | ||
* Time of last modification in milliseconds. | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
mtime: number; | ||
/** | ||
* The uri of the file. | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
uri: string; | ||
} | ||
export interface GetUriResult { | ||
@@ -343,9 +381,9 @@ /** | ||
/** | ||
* Type of the file | ||
* Type of the file. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
type: string; | ||
type: 'directory' | 'file'; | ||
/** | ||
* Size of the file | ||
* Size of the file in bytes. | ||
* | ||
@@ -376,2 +414,10 @@ * @since 1.0.0 | ||
} | ||
export interface CopyResult { | ||
/** | ||
* The uri where the file was copied into | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
uri: string; | ||
} | ||
export interface FilesystemPlugin { | ||
@@ -443,3 +489,3 @@ /** | ||
*/ | ||
copy(options: CopyOptions): Promise<void>; | ||
copy(options: CopyOptions): Promise<CopyResult>; | ||
/** | ||
@@ -446,0 +492,0 @@ * Check read/write permissions. |
import { WebPlugin } from '@capacitor/core'; | ||
import type { AppendFileOptions, CopyOptions, DeleteFileOptions, FilesystemPlugin, GetUriOptions, GetUriResult, MkdirOptions, PermissionStatus, ReadFileOptions, ReadFileResult, ReaddirOptions, ReaddirResult, RenameOptions, RmdirOptions, StatOptions, StatResult, WriteFileOptions, WriteFileResult } from './definitions'; | ||
import type { AppendFileOptions, CopyOptions, CopyResult, DeleteFileOptions, FilesystemPlugin, GetUriOptions, GetUriResult, MkdirOptions, PermissionStatus, ReadFileOptions, ReadFileResult, ReaddirOptions, ReaddirResult, RenameOptions, RmdirOptions, StatOptions, StatResult, WriteFileOptions, WriteFileResult } from './definitions'; | ||
export declare class FilesystemWeb extends WebPlugin implements FilesystemPlugin { | ||
@@ -79,3 +79,3 @@ DB_VERSION: number; | ||
*/ | ||
copy(options: CopyOptions): Promise<void>; | ||
copy(options: CopyOptions): Promise<CopyResult>; | ||
requestPermissions(): Promise<PermissionStatus>; | ||
@@ -90,2 +90,3 @@ checkPermissions(): Promise<PermissionStatus>; | ||
private _copy; | ||
private isBase64String; | ||
} |
@@ -127,3 +127,4 @@ import { WebPlugin } from '@capacitor/core'; | ||
const path = this.getPath(options.directory, options.path); | ||
const data = options.data; | ||
let data = options.data; | ||
const encoding = options.encoding; | ||
const doRecursive = options.recursive; | ||
@@ -133,3 +134,2 @@ const occupiedEntry = (await this.dbRequest('get', [path])); | ||
throw Error('The supplied path is a directory.'); | ||
const encoding = options.encoding; | ||
const parentPath = path.substr(0, path.lastIndexOf('/')); | ||
@@ -148,2 +148,7 @@ const parentEntry = (await this.dbRequest('get', [parentPath])); | ||
} | ||
if (!encoding) { | ||
data = data.indexOf(',') >= 0 ? data.split(',')[1] : data; | ||
if (!this.isBase64String(data)) | ||
throw Error('The supplied data is not valid base64 content.'); | ||
} | ||
const now = Date.now(); | ||
@@ -157,3 +162,3 @@ const pathObj = { | ||
mtime: now, | ||
content: !encoding && data.indexOf(',') >= 0 ? data.split(',')[1] : data, | ||
content: data, | ||
}; | ||
@@ -173,3 +178,3 @@ await this.dbRequest('put', [pathObj]); | ||
let data = options.data; | ||
// const encoding = options.encoding; | ||
const encoding = options.encoding; | ||
const parentPath = path.substr(0, path.lastIndexOf('/')); | ||
@@ -193,4 +198,11 @@ const now = Date.now(); | ||
} | ||
if (!encoding && !this.isBase64String(data)) | ||
throw Error('The supplied data is not valid base64 content.'); | ||
if (occupiedEntry !== undefined) { | ||
data = occupiedEntry.content + data; | ||
if (occupiedEntry.content !== undefined && !encoding) { | ||
data = btoa(atob(occupiedEntry.content) + atob(data)); | ||
} | ||
else { | ||
data = occupiedEntry.content + data; | ||
} | ||
ctime = occupiedEntry.ctime; | ||
@@ -301,6 +313,17 @@ } | ||
const entries = await this.dbIndexRequest('by_folder', 'getAllKeys', [IDBKeyRange.only(path)]); | ||
const names = entries.map(e => { | ||
return e.substring(path.length + 1); | ||
}); | ||
return { files: names }; | ||
const files = await Promise.all(entries.map(async (e) => { | ||
let subEntry = (await this.dbRequest('get', [e])); | ||
if (subEntry === undefined) { | ||
subEntry = (await this.dbRequest('get', [e + '/'])); | ||
} | ||
return { | ||
name: e.substring(path.length + 1), | ||
type: subEntry.type, | ||
size: subEntry.size, | ||
ctime: subEntry.ctime, | ||
mtime: subEntry.mtime, | ||
uri: subEntry.path, | ||
}; | ||
})); | ||
return { files: files }; | ||
} | ||
@@ -349,3 +372,4 @@ /** | ||
async rename(options) { | ||
return this._copy(options, true); | ||
await this._copy(options, true); | ||
return; | ||
} | ||
@@ -386,3 +410,5 @@ /** | ||
if (fromPath === toPath) { | ||
return; | ||
return { | ||
uri: toPath, | ||
}; | ||
} | ||
@@ -450,3 +476,3 @@ if (isPathParent(fromPath, toPath)) { | ||
// Write the file to the new location | ||
await this.writeFile({ | ||
const writeResult = await this.writeFile({ | ||
path: to, | ||
@@ -461,3 +487,3 @@ directory: toDirectory, | ||
// Resolve promise | ||
return; | ||
return writeResult; | ||
} | ||
@@ -506,5 +532,12 @@ case 'directory': { | ||
} | ||
return { | ||
uri: toPath, | ||
}; | ||
} | ||
isBase64String(str) { | ||
const base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/; | ||
return base64regex.test(str); | ||
} | ||
} | ||
FilesystemWeb._debug = true; | ||
//# sourceMappingURL=web.js.map |
@@ -238,3 +238,4 @@ 'use strict'; | ||
const path = this.getPath(options.directory, options.path); | ||
const data = options.data; | ||
let data = options.data; | ||
const encoding = options.encoding; | ||
const doRecursive = options.recursive; | ||
@@ -244,3 +245,2 @@ const occupiedEntry = (await this.dbRequest('get', [path])); | ||
throw Error('The supplied path is a directory.'); | ||
const encoding = options.encoding; | ||
const parentPath = path.substr(0, path.lastIndexOf('/')); | ||
@@ -259,2 +259,7 @@ const parentEntry = (await this.dbRequest('get', [parentPath])); | ||
} | ||
if (!encoding) { | ||
data = data.indexOf(',') >= 0 ? data.split(',')[1] : data; | ||
if (!this.isBase64String(data)) | ||
throw Error('The supplied data is not valid base64 content.'); | ||
} | ||
const now = Date.now(); | ||
@@ -268,3 +273,3 @@ const pathObj = { | ||
mtime: now, | ||
content: !encoding && data.indexOf(',') >= 0 ? data.split(',')[1] : data, | ||
content: data, | ||
}; | ||
@@ -284,3 +289,3 @@ await this.dbRequest('put', [pathObj]); | ||
let data = options.data; | ||
// const encoding = options.encoding; | ||
const encoding = options.encoding; | ||
const parentPath = path.substr(0, path.lastIndexOf('/')); | ||
@@ -304,4 +309,11 @@ const now = Date.now(); | ||
} | ||
if (!encoding && !this.isBase64String(data)) | ||
throw Error('The supplied data is not valid base64 content.'); | ||
if (occupiedEntry !== undefined) { | ||
data = occupiedEntry.content + data; | ||
if (occupiedEntry.content !== undefined && !encoding) { | ||
data = btoa(atob(occupiedEntry.content) + atob(data)); | ||
} | ||
else { | ||
data = occupiedEntry.content + data; | ||
} | ||
ctime = occupiedEntry.ctime; | ||
@@ -412,6 +424,17 @@ } | ||
const entries = await this.dbIndexRequest('by_folder', 'getAllKeys', [IDBKeyRange.only(path)]); | ||
const names = entries.map(e => { | ||
return e.substring(path.length + 1); | ||
}); | ||
return { files: names }; | ||
const files = await Promise.all(entries.map(async (e) => { | ||
let subEntry = (await this.dbRequest('get', [e])); | ||
if (subEntry === undefined) { | ||
subEntry = (await this.dbRequest('get', [e + '/'])); | ||
} | ||
return { | ||
name: e.substring(path.length + 1), | ||
type: subEntry.type, | ||
size: subEntry.size, | ||
ctime: subEntry.ctime, | ||
mtime: subEntry.mtime, | ||
uri: subEntry.path, | ||
}; | ||
})); | ||
return { files: files }; | ||
} | ||
@@ -460,3 +483,4 @@ /** | ||
async rename(options) { | ||
return this._copy(options, true); | ||
await this._copy(options, true); | ||
return; | ||
} | ||
@@ -497,3 +521,5 @@ /** | ||
if (fromPath === toPath) { | ||
return; | ||
return { | ||
uri: toPath, | ||
}; | ||
} | ||
@@ -561,3 +587,3 @@ if (isPathParent(fromPath, toPath)) { | ||
// Write the file to the new location | ||
await this.writeFile({ | ||
const writeResult = await this.writeFile({ | ||
path: to, | ||
@@ -572,3 +598,3 @@ directory: toDirectory, | ||
// Resolve promise | ||
return; | ||
return writeResult; | ||
} | ||
@@ -617,3 +643,10 @@ case 'directory': { | ||
} | ||
return { | ||
uri: toPath, | ||
}; | ||
} | ||
isBase64String(str) { | ||
const base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/; | ||
return base64regex.test(str); | ||
} | ||
} | ||
@@ -620,0 +653,0 @@ FilesystemWeb._debug = true; |
@@ -235,3 +235,4 @@ var capacitorFilesystem = (function (exports, core) { | ||
const path = this.getPath(options.directory, options.path); | ||
const data = options.data; | ||
let data = options.data; | ||
const encoding = options.encoding; | ||
const doRecursive = options.recursive; | ||
@@ -241,3 +242,2 @@ const occupiedEntry = (await this.dbRequest('get', [path])); | ||
throw Error('The supplied path is a directory.'); | ||
const encoding = options.encoding; | ||
const parentPath = path.substr(0, path.lastIndexOf('/')); | ||
@@ -256,2 +256,7 @@ const parentEntry = (await this.dbRequest('get', [parentPath])); | ||
} | ||
if (!encoding) { | ||
data = data.indexOf(',') >= 0 ? data.split(',')[1] : data; | ||
if (!this.isBase64String(data)) | ||
throw Error('The supplied data is not valid base64 content.'); | ||
} | ||
const now = Date.now(); | ||
@@ -265,3 +270,3 @@ const pathObj = { | ||
mtime: now, | ||
content: !encoding && data.indexOf(',') >= 0 ? data.split(',')[1] : data, | ||
content: data, | ||
}; | ||
@@ -281,3 +286,3 @@ await this.dbRequest('put', [pathObj]); | ||
let data = options.data; | ||
// const encoding = options.encoding; | ||
const encoding = options.encoding; | ||
const parentPath = path.substr(0, path.lastIndexOf('/')); | ||
@@ -301,4 +306,11 @@ const now = Date.now(); | ||
} | ||
if (!encoding && !this.isBase64String(data)) | ||
throw Error('The supplied data is not valid base64 content.'); | ||
if (occupiedEntry !== undefined) { | ||
data = occupiedEntry.content + data; | ||
if (occupiedEntry.content !== undefined && !encoding) { | ||
data = btoa(atob(occupiedEntry.content) + atob(data)); | ||
} | ||
else { | ||
data = occupiedEntry.content + data; | ||
} | ||
ctime = occupiedEntry.ctime; | ||
@@ -409,6 +421,17 @@ } | ||
const entries = await this.dbIndexRequest('by_folder', 'getAllKeys', [IDBKeyRange.only(path)]); | ||
const names = entries.map(e => { | ||
return e.substring(path.length + 1); | ||
}); | ||
return { files: names }; | ||
const files = await Promise.all(entries.map(async (e) => { | ||
let subEntry = (await this.dbRequest('get', [e])); | ||
if (subEntry === undefined) { | ||
subEntry = (await this.dbRequest('get', [e + '/'])); | ||
} | ||
return { | ||
name: e.substring(path.length + 1), | ||
type: subEntry.type, | ||
size: subEntry.size, | ||
ctime: subEntry.ctime, | ||
mtime: subEntry.mtime, | ||
uri: subEntry.path, | ||
}; | ||
})); | ||
return { files: files }; | ||
} | ||
@@ -457,3 +480,4 @@ /** | ||
async rename(options) { | ||
return this._copy(options, true); | ||
await this._copy(options, true); | ||
return; | ||
} | ||
@@ -494,3 +518,5 @@ /** | ||
if (fromPath === toPath) { | ||
return; | ||
return { | ||
uri: toPath, | ||
}; | ||
} | ||
@@ -558,3 +584,3 @@ if (isPathParent(fromPath, toPath)) { | ||
// Write the file to the new location | ||
await this.writeFile({ | ||
const writeResult = await this.writeFile({ | ||
path: to, | ||
@@ -569,3 +595,3 @@ directory: toDirectory, | ||
// Resolve promise | ||
return; | ||
return writeResult; | ||
} | ||
@@ -614,3 +640,10 @@ case 'directory': { | ||
} | ||
return { | ||
uri: toPath, | ||
}; | ||
} | ||
isBase64String(str) { | ||
const base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/; | ||
return base64regex.test(str); | ||
} | ||
} | ||
@@ -617,0 +650,0 @@ FilesystemWeb._debug = true; |
{ | ||
"name": "@capacitor/filesystem", | ||
"version": "1.1.0", | ||
"version": "4.0.0-beta.0", | ||
"description": "The Filesystem API provides a NodeJS-like API for working with files on the device.", | ||
@@ -32,3 +32,3 @@ "main": "dist/plugin.cjs.js", | ||
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web", | ||
"verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin && cd ..", | ||
"verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..", | ||
"verify:android": "cd android && ./gradlew clean build test && cd ..", | ||
@@ -49,6 +49,6 @@ "verify:web": "npm run build", | ||
"devDependencies": { | ||
"@capacitor/android": "^3.0.0", | ||
"@capacitor/core": "^3.0.0", | ||
"@capacitor/android": "next", | ||
"@capacitor/core": "next", | ||
"@capacitor/docgen": "0.0.18", | ||
"@capacitor/ios": "^3.0.0", | ||
"@capacitor/ios": "next", | ||
"@ionic/eslint-config": "^0.3.0", | ||
@@ -66,3 +66,3 @@ "@ionic/prettier-config": "~1.0.1", | ||
"peerDependencies": { | ||
"@capacitor/core": "^3.0.0" | ||
"@capacitor/core": "next" | ||
}, | ||
@@ -85,3 +85,3 @@ "prettier": "@ionic/prettier-config", | ||
}, | ||
"gitHead": "f18ee6482e1ec8e5fb0290d51f598397133af990" | ||
"gitHead": "fd7db8285f72990522da0adc889514c9804b6dae" | ||
} |
@@ -285,3 +285,3 @@ # @capacitor/filesystem | ||
```typescript | ||
copy(options: CopyOptions) => Promise<void> | ||
copy(options: CopyOptions) => Promise<CopyResult> | ||
``` | ||
@@ -295,2 +295,4 @@ | ||
**Returns:** <code>Promise<<a href="#copyresult">CopyResult</a>></code> | ||
**Since:** 1.0.0 | ||
@@ -410,7 +412,19 @@ | ||
| Prop | Type | Description | Since | | ||
| ----------- | --------------------- | -------------------------------------------------- | ----- | | ||
| **`files`** | <code>string[]</code> | List of files and directories inside the directory | 1.0.0 | | ||
| Prop | Type | Description | Since | | ||
| ----------- | ----------------------- | -------------------------------------------------- | ----- | | ||
| **`files`** | <code>FileInfo[]</code> | List of files and directories inside the directory | 1.0.0 | | ||
#### FileInfo | ||
| Prop | Type | Description | Since | | ||
| ----------- | ---------------------------------- | ------------------------------------------------------------------------------------ | ----- | | ||
| **`name`** | <code>string</code> | Name of the file or directory. | | | ||
| **`type`** | <code>'directory' \| 'file'</code> | Type of the file. | 4.0.0 | | ||
| **`size`** | <code>number</code> | Size of the file in bytes. | 4.0.0 | | ||
| **`ctime`** | <code>number</code> | Time of creation in milliseconds. It's not available on Android 7 and older devices. | 4.0.0 | | ||
| **`mtime`** | <code>number</code> | Time of last modification in milliseconds. | 4.0.0 | | ||
| **`uri`** | <code>string</code> | The uri of the file. | 4.0.0 | | ||
#### ReaddirOptions | ||
@@ -441,9 +455,9 @@ | ||
| Prop | Type | Description | Since | | ||
| ----------- | ------------------- | ------------------------------------------------------------------------------------ | ----- | | ||
| **`type`** | <code>string</code> | Type of the file | 1.0.0 | | ||
| **`size`** | <code>number</code> | Size of the file | 1.0.0 | | ||
| **`ctime`** | <code>number</code> | Time of creation in milliseconds. It's not available on Android 7 and older devices. | 1.0.0 | | ||
| **`mtime`** | <code>number</code> | Time of last modification in milliseconds. | 1.0.0 | | ||
| **`uri`** | <code>string</code> | The uri of the file | 1.0.0 | | ||
| Prop | Type | Description | Since | | ||
| ----------- | ---------------------------------- | ------------------------------------------------------------------------------------ | ----- | | ||
| **`type`** | <code>'directory' \| 'file'</code> | Type of the file. | 1.0.0 | | ||
| **`size`** | <code>number</code> | Size of the file in bytes. | 1.0.0 | | ||
| **`ctime`** | <code>number</code> | Time of creation in milliseconds. It's not available on Android 7 and older devices. | 1.0.0 | | ||
| **`mtime`** | <code>number</code> | Time of last modification in milliseconds. | 1.0.0 | | ||
| **`uri`** | <code>string</code> | The uri of the file | 1.0.0 | | ||
@@ -469,2 +483,9 @@ | ||
#### CopyResult | ||
| Prop | Type | Description | Since | | ||
| --------- | ------------------- | -------------------------------------- | ----- | | ||
| **`uri`** | <code>string</code> | The uri where the file was copied into | 4.0.0 | | ||
#### PermissionStatus | ||
@@ -471,0 +492,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
360293
4486
530
2
1