minip-bridge 1.0.29 → 1.0.31
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/dist/{chunk-QWZNCALB.mjs → chunk-4HUUDNXW.mjs} +25 -19
- package/dist/chunk-4HUUDNXW.mjs.map +1 -0
- package/dist/fs/index.d.mts +21 -19
- package/dist/fs/index.mjs +81 -148
- package/dist/fs/index.mjs.map +1 -1
- package/dist/index.d.mts +56 -58
- package/dist/index.mjs +104 -102
- package/dist/index.mjs.map +1 -1
- package/dist/kysely/index.mjs +23 -30
- package/dist/kysely/index.mjs.map +1 -1
- package/dist/path/index.d.mts +11 -0
- package/dist/path/index.mjs +84 -0
- package/dist/path/index.mjs.map +1 -0
- package/package.json +7 -3
- package/src/api/app.ts +15 -13
- package/src/api/device.ts +20 -18
- package/src/api/kvstorage.ts +20 -18
- package/src/api/memory-cache.ts +16 -15
- package/src/api/route.ts +12 -13
- package/src/api/sqlite.ts +56 -42
- package/src/api/ui.ts +44 -55
- package/src/fs/common.ts +36 -49
- package/src/fs/dir.ts +10 -10
- package/src/fs/fd.ts +14 -59
- package/src/fs/file.ts +25 -56
- package/src/kysely/core/sqlite-connection.ts +10 -9
- package/src/kysely/core/sqlite-database.ts +13 -20
- package/src/kysely/core/sqlite-query-iterator.ts +2 -2
- package/src/kysely/core/sqlite-statement.ts +0 -5
- package/src/path/index.ts +87 -0
- package/src/utils/utils.ts +39 -33
- package/tsup.config.ts +1 -1
- package/dist/chunk-QWZNCALB.mjs.map +0 -1
|
@@ -3,33 +3,35 @@ import {
|
|
|
3
3
|
} from "./chunk-GXHJCCLG.mjs";
|
|
4
4
|
|
|
5
5
|
// src/api/sqlite.ts
|
|
6
|
-
function sqliteOpenDB(path) {
|
|
7
|
-
|
|
6
|
+
async function sqliteOpenDB(path) {
|
|
7
|
+
const res = await bridge_default.callNative({
|
|
8
8
|
api: "sqliteOpenDB",
|
|
9
9
|
data: {
|
|
10
10
|
path
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
|
+
return res.data.dbKey;
|
|
13
14
|
}
|
|
14
|
-
function sqliteCloseDB(dbKey) {
|
|
15
|
-
|
|
15
|
+
async function sqliteCloseDB(dbKey) {
|
|
16
|
+
await bridge_default.callNative({
|
|
16
17
|
api: "sqliteCloseDB",
|
|
17
18
|
data: {
|
|
18
19
|
dbKey
|
|
19
20
|
}
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
|
-
function sqlitePrepare(dbKey, sql) {
|
|
23
|
-
|
|
23
|
+
async function sqlitePrepare(dbKey, sql) {
|
|
24
|
+
const res = await bridge_default.callNative({
|
|
24
25
|
api: "sqlitePrepare",
|
|
25
26
|
data: {
|
|
26
27
|
dbKey,
|
|
27
28
|
sql
|
|
28
29
|
}
|
|
29
30
|
});
|
|
31
|
+
return res.data;
|
|
30
32
|
}
|
|
31
|
-
function sqliteStatementAll(dbKey, stmtKey, parameters) {
|
|
32
|
-
|
|
33
|
+
async function sqliteStatementAll(dbKey, stmtKey, parameters) {
|
|
34
|
+
const res = await bridge_default.callNative({
|
|
33
35
|
api: "sqliteStatementAll",
|
|
34
36
|
data: {
|
|
35
37
|
dbKey,
|
|
@@ -37,9 +39,10 @@ function sqliteStatementAll(dbKey, stmtKey, parameters) {
|
|
|
37
39
|
parameters
|
|
38
40
|
}
|
|
39
41
|
});
|
|
42
|
+
return res.data;
|
|
40
43
|
}
|
|
41
|
-
function sqliteStatementRun(dbKey, stmtKey, parameters) {
|
|
42
|
-
|
|
44
|
+
async function sqliteStatementRun(dbKey, stmtKey, parameters) {
|
|
45
|
+
const res = await bridge_default.callNative({
|
|
43
46
|
api: "sqliteStatementRun",
|
|
44
47
|
data: {
|
|
45
48
|
dbKey,
|
|
@@ -47,9 +50,10 @@ function sqliteStatementRun(dbKey, stmtKey, parameters) {
|
|
|
47
50
|
parameters
|
|
48
51
|
}
|
|
49
52
|
});
|
|
53
|
+
return res.data;
|
|
50
54
|
}
|
|
51
|
-
function sqliteExecute(dbKey, sql, parameters) {
|
|
52
|
-
|
|
55
|
+
async function sqliteExecute(dbKey, sql, parameters) {
|
|
56
|
+
const res = await bridge_default.callNative({
|
|
53
57
|
api: "sqliteExecute",
|
|
54
58
|
data: {
|
|
55
59
|
dbKey,
|
|
@@ -57,9 +61,10 @@ function sqliteExecute(dbKey, sql, parameters) {
|
|
|
57
61
|
parameters
|
|
58
62
|
}
|
|
59
63
|
});
|
|
64
|
+
return res.data;
|
|
60
65
|
}
|
|
61
|
-
function sqliteCreateIterator(dbKey, stmtKey, parameters) {
|
|
62
|
-
|
|
66
|
+
async function sqliteCreateIterator(dbKey, stmtKey, parameters) {
|
|
67
|
+
await bridge_default.callNative({
|
|
63
68
|
api: "sqliteCreateIterator",
|
|
64
69
|
data: {
|
|
65
70
|
dbKey,
|
|
@@ -68,17 +73,18 @@ function sqliteCreateIterator(dbKey, stmtKey, parameters) {
|
|
|
68
73
|
}
|
|
69
74
|
});
|
|
70
75
|
}
|
|
71
|
-
function sqliteIteratorNext(dbKey, stmtKey) {
|
|
72
|
-
|
|
76
|
+
async function sqliteIteratorNext(dbKey, stmtKey) {
|
|
77
|
+
const res = await bridge_default.callNative({
|
|
73
78
|
api: "sqliteIteratorNext",
|
|
74
79
|
data: {
|
|
75
80
|
dbKey,
|
|
76
81
|
stmtKey
|
|
77
82
|
}
|
|
78
83
|
});
|
|
84
|
+
return res.data;
|
|
79
85
|
}
|
|
80
|
-
function sqliteIteratorRelease(dbKey, stmtKey) {
|
|
81
|
-
|
|
86
|
+
async function sqliteIteratorRelease(dbKey, stmtKey) {
|
|
87
|
+
await bridge_default.callNative({
|
|
82
88
|
api: "sqliteIteratorRelease",
|
|
83
89
|
data: {
|
|
84
90
|
dbKey,
|
|
@@ -98,4 +104,4 @@ export {
|
|
|
98
104
|
sqliteIteratorNext,
|
|
99
105
|
sqliteIteratorRelease
|
|
100
106
|
};
|
|
101
|
-
//# sourceMappingURL=chunk-
|
|
107
|
+
//# sourceMappingURL=chunk-4HUUDNXW.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/api/sqlite.ts"],"sourcesContent":["import jsBridge from \"../bridge\";\r\nimport { MResponseWithData } from \"../types\";\r\n\r\nexport async function sqliteOpenDB(path: string): Promise<number> {\r\n const res = await jsBridge.callNative({\r\n api: \"sqliteOpenDB\",\r\n data: {\r\n path,\r\n },\r\n });\r\n return (res as MResponseWithData<{ dbKey: number }>).data.dbKey;\r\n}\r\n\r\nexport async function sqliteCloseDB(dbKey: number): Promise<void> {\r\n await jsBridge.callNative({\r\n api: \"sqliteCloseDB\",\r\n data: {\r\n dbKey,\r\n },\r\n });\r\n}\r\n\r\nexport async function sqlitePrepare(\r\n dbKey: number,\r\n sql: string,\r\n): Promise<{ stmtKey: number; reader: boolean }> {\r\n const res = await jsBridge.callNative({\r\n api: \"sqlitePrepare\",\r\n data: {\r\n dbKey,\r\n sql,\r\n },\r\n });\r\n return (res as MResponseWithData<{ stmtKey: number; reader: boolean }>).data;\r\n}\r\n\r\nexport async function sqliteStatementAll(\r\n dbKey: number,\r\n stmtKey: number,\r\n parameters: ReadonlyArray<unknown>,\r\n): Promise<unknown[]> {\r\n const res = await jsBridge.callNative({\r\n api: \"sqliteStatementAll\",\r\n data: {\r\n dbKey,\r\n stmtKey,\r\n parameters,\r\n },\r\n });\r\n return (res as MResponseWithData<unknown[]>).data;\r\n}\r\n\r\nexport async function sqliteStatementRun(\r\n dbKey: number,\r\n stmtKey: number,\r\n parameters: ReadonlyArray<unknown>,\r\n): Promise<{\r\n changes: number | bigint;\r\n lastInsertRowid: number | bigint;\r\n}> {\r\n const res = await jsBridge.callNative({\r\n api: \"sqliteStatementRun\",\r\n data: {\r\n dbKey,\r\n stmtKey,\r\n parameters,\r\n },\r\n });\r\n return (\r\n res as MResponseWithData<{\r\n changes: number | bigint;\r\n lastInsertRowid: number | bigint;\r\n }>\r\n ).data;\r\n}\r\n\r\nexport async function sqliteExecute(\r\n dbKey: number,\r\n sql: string,\r\n parameters: ReadonlyArray<unknown>,\r\n): Promise<{\r\n reader: boolean;\r\n runRes?: {\r\n changes: number | bigint;\r\n lastInsertRowid: number | bigint;\r\n };\r\n entityData?: unknown[];\r\n}> {\r\n const res = await jsBridge.callNative({\r\n api: \"sqliteExecute\",\r\n data: {\r\n dbKey,\r\n sql,\r\n parameters,\r\n },\r\n });\r\n return (\r\n res as MResponseWithData<{\r\n reader: boolean;\r\n runRes?: {\r\n changes: number | bigint;\r\n lastInsertRowid: number | bigint;\r\n };\r\n entityData?: unknown[];\r\n }>\r\n ).data;\r\n}\r\n\r\nexport async function sqliteCreateIterator(\r\n dbKey: number,\r\n stmtKey: number,\r\n parameters: ReadonlyArray<unknown>,\r\n): Promise<void> {\r\n await jsBridge.callNative({\r\n api: \"sqliteCreateIterator\",\r\n data: {\r\n dbKey,\r\n stmtKey,\r\n parameters,\r\n },\r\n });\r\n}\r\n\r\nexport async function sqliteIteratorNext(\r\n dbKey: number,\r\n stmtKey: number,\r\n): Promise<unknown | undefined> {\r\n const res = await jsBridge.callNative({\r\n api: \"sqliteIteratorNext\",\r\n data: {\r\n dbKey,\r\n stmtKey,\r\n },\r\n });\r\n return (res as MResponseWithData<unknown | undefined>).data;\r\n}\r\n\r\nexport async function sqliteIteratorRelease(\r\n dbKey: number,\r\n stmtKey: number,\r\n): Promise<void> {\r\n await jsBridge.callNative({\r\n api: \"sqliteIteratorRelease\",\r\n data: {\r\n dbKey,\r\n stmtKey,\r\n },\r\n });\r\n}\r\n"],"mappings":";;;;;AAGA,eAAsB,aAAa,MAA+B;AAChE,QAAM,MAAM,MAAM,eAAS,WAAW;AAAA,IACpC,KAAK;AAAA,IACL,MAAM;AAAA,MACJ;AAAA,IACF;AAAA,EACF,CAAC;AACD,SAAQ,IAA6C,KAAK;AAC5D;AAEA,eAAsB,cAAc,OAA8B;AAChE,QAAM,eAAS,WAAW;AAAA,IACxB,KAAK;AAAA,IACL,MAAM;AAAA,MACJ;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEA,eAAsB,cACpB,OACA,KAC+C;AAC/C,QAAM,MAAM,MAAM,eAAS,WAAW;AAAA,IACpC,KAAK;AAAA,IACL,MAAM;AAAA,MACJ;AAAA,MACA;AAAA,IACF;AAAA,EACF,CAAC;AACD,SAAQ,IAAgE;AAC1E;AAEA,eAAsB,mBACpB,OACA,SACA,YACoB;AACpB,QAAM,MAAM,MAAM,eAAS,WAAW;AAAA,IACpC,KAAK;AAAA,IACL,MAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,CAAC;AACD,SAAQ,IAAqC;AAC/C;AAEA,eAAsB,mBACpB,OACA,SACA,YAIC;AACD,QAAM,MAAM,MAAM,eAAS,WAAW;AAAA,IACpC,KAAK;AAAA,IACL,MAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,CAAC;AACD,SACE,IAIA;AACJ;AAEA,eAAsB,cACpB,OACA,KACA,YAQC;AACD,QAAM,MAAM,MAAM,eAAS,WAAW;AAAA,IACpC,KAAK;AAAA,IACL,MAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,CAAC;AACD,SACE,IAQA;AACJ;AAEA,eAAsB,qBACpB,OACA,SACA,YACe;AACf,QAAM,eAAS,WAAW;AAAA,IACxB,KAAK;AAAA,IACL,MAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEA,eAAsB,mBACpB,OACA,SAC8B;AAC9B,QAAM,MAAM,MAAM,eAAS,WAAW;AAAA,IACpC,KAAK;AAAA,IACL,MAAM;AAAA,MACJ;AAAA,MACA;AAAA,IACF;AAAA,EACF,CAAC;AACD,SAAQ,IAA+C;AACzD;AAEA,eAAsB,sBACpB,OACA,SACe;AACf,QAAM,eAAS,WAAW;AAAA,IACxB,KAAK;AAAA,IACL,MAAM;AAAA,MACJ;AAAA,MACA;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
|
package/dist/fs/index.d.mts
CHANGED
|
@@ -22,8 +22,10 @@ interface FileStats {
|
|
|
22
22
|
isSymbolicLink(): boolean;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
declare function enrichStats(file: FileStats): FileStats;
|
|
25
26
|
declare function access(path: string, mode?: number): Promise<void>;
|
|
26
27
|
declare function accessSync(path: string, mode?: number): void;
|
|
28
|
+
declare function existsSync(path: string): boolean;
|
|
27
29
|
declare function unlink(path: string): Promise<void>;
|
|
28
30
|
declare function unlinkSync(path: string): void;
|
|
29
31
|
declare function rename(oldPath: string, newPath: string): Promise<void>;
|
|
@@ -37,21 +39,21 @@ declare function cpSync(src: string, dest: string, recursive?: boolean): void;
|
|
|
37
39
|
|
|
38
40
|
declare function mkdir(path: string, recursive?: boolean): Promise<void>;
|
|
39
41
|
declare function mkdirSync(path: string, recursive?: boolean): void;
|
|
40
|
-
declare function
|
|
41
|
-
declare function
|
|
42
|
-
declare function rmdir(path: string,
|
|
43
|
-
declare function rmdirSync(path: string,
|
|
42
|
+
declare function readdir(path: string): Promise<string[]>;
|
|
43
|
+
declare function readdirSync(path: string): string[];
|
|
44
|
+
declare function rmdir(path: string, recursive?: boolean): Promise<void>;
|
|
45
|
+
declare function rmdirSync(path: string, recursive?: boolean): void;
|
|
44
46
|
|
|
45
|
-
declare function readFile(path: string): Promise<
|
|
46
|
-
declare function readFileSync(path: string):
|
|
47
|
-
declare function writeFile(path: string, data:
|
|
48
|
-
declare function writeFileSync(path: string, data:
|
|
49
|
-
declare function appendFile(path: string, data:
|
|
50
|
-
declare function appendFileSync(path: string, data:
|
|
47
|
+
declare function readFile(path: string, encoding?: string): Promise<Uint8Array | string>;
|
|
48
|
+
declare function readFileSync(path: string, encoding?: string): Uint8Array | string;
|
|
49
|
+
declare function writeFile(path: string, data: Uint8Array | string): Promise<void>;
|
|
50
|
+
declare function writeFileSync(path: string, data: Uint8Array | string): void;
|
|
51
|
+
declare function appendFile(path: string, data: Uint8Array | string): Promise<void>;
|
|
52
|
+
declare function appendFileSync(path: string, data: Uint8Array | string): void;
|
|
51
53
|
declare function copyFile(src: string, dest: string): Promise<void>;
|
|
52
54
|
declare function copyFileSync(src: string, dest: string): void;
|
|
53
|
-
declare function truncate(path: string, length
|
|
54
|
-
declare function truncateSync(path: string, length
|
|
55
|
+
declare function truncate(path: string, length?: number): Promise<void>;
|
|
56
|
+
declare function truncateSync(path: string, length?: number): void;
|
|
55
57
|
|
|
56
58
|
declare enum OpenFlags {
|
|
57
59
|
O_RDONLY = 0,
|
|
@@ -68,11 +70,11 @@ declare function close(fd: number): Promise<void>;
|
|
|
68
70
|
declare function closeSync(fd: number): void;
|
|
69
71
|
declare function fstat(fd: number): Promise<FileStats>;
|
|
70
72
|
declare function fstatSync(fd: number): FileStats;
|
|
71
|
-
declare function ftruncate(fd: number, length
|
|
72
|
-
declare function ftruncateSync(fd: number, length
|
|
73
|
-
declare function read(fd: number, buffer:
|
|
74
|
-
declare function readSync(fd: number, buffer:
|
|
75
|
-
declare function write(fd: number, buffer:
|
|
76
|
-
declare function writeSync(fd: number, buffer:
|
|
73
|
+
declare function ftruncate(fd: number, length?: number): Promise<void>;
|
|
74
|
+
declare function ftruncateSync(fd: number, length?: number): void;
|
|
75
|
+
declare function read(fd: number, buffer: Uint8Array, offset: number, length: number, position?: number): Promise<number>;
|
|
76
|
+
declare function readSync(fd: number, buffer: Uint8Array, offset: number, length: number, position?: number): number;
|
|
77
|
+
declare function write(fd: number, buffer: Uint8Array, offset: number, length: number, position?: number): Promise<number>;
|
|
78
|
+
declare function writeSync(fd: number, buffer: Uint8Array, offset: number, length: number, position?: number): number;
|
|
77
79
|
|
|
78
|
-
export { OpenFlags, access, accessSync, appendFile, appendFileSync, close, closeSync, copyFile, copyFileSync, cp, cpSync, fstat, fstatSync, ftruncate, ftruncateSync, mkdir, mkdirSync, open, openSync, read,
|
|
80
|
+
export { OpenFlags, access, accessSync, appendFile, appendFileSync, close, closeSync, copyFile, copyFileSync, cp, cpSync, enrichStats, existsSync, fstat, fstatSync, ftruncate, ftruncateSync, mkdir, mkdirSync, open, openSync, read, readFile, readFileSync, readSync, readdir, readdirSync, rename, renameSync, rm, rmSync, rmdir, rmdirSync, stat, statSync, truncate, truncateSync, unlink, unlinkSync, write, writeFile, writeFileSync, writeSync };
|
package/dist/fs/index.mjs
CHANGED
|
@@ -3,6 +3,26 @@ import {
|
|
|
3
3
|
} from "../chunk-GXHJCCLG.mjs";
|
|
4
4
|
|
|
5
5
|
// src/fs/common.ts
|
|
6
|
+
var S_IFMT = 61440;
|
|
7
|
+
var S_IFDIR = 16384;
|
|
8
|
+
var S_IFREG = 32768;
|
|
9
|
+
var S_IFLNK = 40960;
|
|
10
|
+
function enrichStats(file) {
|
|
11
|
+
file.atime = new Date(file.atimeMs);
|
|
12
|
+
file.mtime = new Date(file.mtimeMs);
|
|
13
|
+
file.ctime = new Date(file.ctimeMs);
|
|
14
|
+
file.birthtime = new Date(file.birthtimeMs);
|
|
15
|
+
file.isDirectory = function() {
|
|
16
|
+
return (this.mode & S_IFMT) === S_IFDIR;
|
|
17
|
+
};
|
|
18
|
+
file.isFile = function() {
|
|
19
|
+
return (this.mode & S_IFMT) === S_IFREG;
|
|
20
|
+
};
|
|
21
|
+
file.isSymbolicLink = function() {
|
|
22
|
+
return (this.mode & S_IFMT) === S_IFLNK;
|
|
23
|
+
};
|
|
24
|
+
return file;
|
|
25
|
+
}
|
|
6
26
|
async function access(path, mode) {
|
|
7
27
|
return bridge_default.callNative({
|
|
8
28
|
api: "fsAccess",
|
|
@@ -29,6 +49,14 @@ function accessSync(path, mode) {
|
|
|
29
49
|
throw new Error(res.msg ?? "cannot access this file or directory");
|
|
30
50
|
}
|
|
31
51
|
}
|
|
52
|
+
function existsSync(path) {
|
|
53
|
+
try {
|
|
54
|
+
accessSync(path);
|
|
55
|
+
return true;
|
|
56
|
+
} catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
32
60
|
async function unlink(path) {
|
|
33
61
|
await bridge_default.callNative({
|
|
34
62
|
api: "fsUnlink",
|
|
@@ -70,24 +98,7 @@ async function stat(path) {
|
|
|
70
98
|
path
|
|
71
99
|
}
|
|
72
100
|
});
|
|
73
|
-
|
|
74
|
-
file.atime = new Date(file.atimeMs);
|
|
75
|
-
file.mtime = new Date(file.mtimeMs);
|
|
76
|
-
file.ctime = new Date(file.ctimeMs);
|
|
77
|
-
file.birthtime = new Date(file.birthtimeMs);
|
|
78
|
-
const S_IFDIR = 16384;
|
|
79
|
-
const S_IFREG = 32768;
|
|
80
|
-
const S_IFLNK = 40960;
|
|
81
|
-
file.isDirectory = function() {
|
|
82
|
-
return (this.mode & S_IFDIR) === S_IFDIR;
|
|
83
|
-
};
|
|
84
|
-
file.isFile = function() {
|
|
85
|
-
return (this.mode & S_IFREG) === S_IFREG;
|
|
86
|
-
};
|
|
87
|
-
file.isSymbolicLink = function() {
|
|
88
|
-
return (this.mode & S_IFLNK) === S_IFLNK;
|
|
89
|
-
};
|
|
90
|
-
return file;
|
|
101
|
+
return enrichStats(res.data);
|
|
91
102
|
}
|
|
92
103
|
function statSync(path) {
|
|
93
104
|
const res = bridge_default.callNativeSync({
|
|
@@ -96,24 +107,7 @@ function statSync(path) {
|
|
|
96
107
|
path
|
|
97
108
|
}
|
|
98
109
|
});
|
|
99
|
-
|
|
100
|
-
file.atime = new Date(file.atimeMs);
|
|
101
|
-
file.mtime = new Date(file.mtimeMs);
|
|
102
|
-
file.ctime = new Date(file.ctimeMs);
|
|
103
|
-
file.birthtime = new Date(file.birthtimeMs);
|
|
104
|
-
const S_IFDIR = 16384;
|
|
105
|
-
const S_IFREG = 32768;
|
|
106
|
-
const S_IFLNK = 40960;
|
|
107
|
-
file.isDirectory = function() {
|
|
108
|
-
return (this.mode & S_IFDIR) === S_IFDIR;
|
|
109
|
-
};
|
|
110
|
-
file.isFile = function() {
|
|
111
|
-
return (this.mode & S_IFREG) === S_IFREG;
|
|
112
|
-
};
|
|
113
|
-
file.isSymbolicLink = function() {
|
|
114
|
-
return (this.mode & S_IFLNK) === S_IFLNK;
|
|
115
|
-
};
|
|
116
|
-
return file;
|
|
110
|
+
return enrichStats(res.data);
|
|
117
111
|
}
|
|
118
112
|
async function rm(path) {
|
|
119
113
|
await bridge_default.callNative({
|
|
@@ -153,7 +147,7 @@ function cpSync(src, dest, recursive) {
|
|
|
153
147
|
}
|
|
154
148
|
|
|
155
149
|
// src/fs/dir.ts
|
|
156
|
-
async function mkdir(path, recursive =
|
|
150
|
+
async function mkdir(path, recursive = false) {
|
|
157
151
|
await bridge_default.callNative({
|
|
158
152
|
api: "fsMkdir",
|
|
159
153
|
data: {
|
|
@@ -162,7 +156,7 @@ async function mkdir(path, recursive = true) {
|
|
|
162
156
|
}
|
|
163
157
|
});
|
|
164
158
|
}
|
|
165
|
-
function mkdirSync(path, recursive =
|
|
159
|
+
function mkdirSync(path, recursive = false) {
|
|
166
160
|
bridge_default.callNativeSync({
|
|
167
161
|
api: "fsMkdirSync",
|
|
168
162
|
data: {
|
|
@@ -171,160 +165,131 @@ function mkdirSync(path, recursive = true) {
|
|
|
171
165
|
}
|
|
172
166
|
});
|
|
173
167
|
}
|
|
174
|
-
function
|
|
168
|
+
function readdir(path) {
|
|
175
169
|
return bridge_default.callNative({
|
|
176
|
-
api: "
|
|
170
|
+
api: "fsReaddir",
|
|
177
171
|
data: {
|
|
178
172
|
path
|
|
179
173
|
}
|
|
180
174
|
}).then((res) => res).then((res) => res.data);
|
|
181
175
|
}
|
|
182
|
-
function
|
|
176
|
+
function readdirSync(path) {
|
|
183
177
|
const res = bridge_default.callNativeSync({
|
|
184
|
-
api: "
|
|
178
|
+
api: "fsReaddirSync",
|
|
185
179
|
data: {
|
|
186
180
|
path
|
|
187
181
|
}
|
|
188
182
|
});
|
|
189
183
|
return res.data;
|
|
190
184
|
}
|
|
191
|
-
async function rmdir(path,
|
|
185
|
+
async function rmdir(path, recursive) {
|
|
192
186
|
await bridge_default.callNative({
|
|
193
187
|
api: "fsRmdir",
|
|
194
188
|
data: {
|
|
195
189
|
path,
|
|
196
|
-
|
|
190
|
+
recursive
|
|
197
191
|
}
|
|
198
192
|
});
|
|
199
193
|
}
|
|
200
|
-
function rmdirSync(path,
|
|
194
|
+
function rmdirSync(path, recursive) {
|
|
201
195
|
bridge_default.callNativeSync({
|
|
202
196
|
api: "fsRmdirSync",
|
|
203
197
|
data: {
|
|
204
198
|
path,
|
|
205
|
-
|
|
199
|
+
recursive
|
|
206
200
|
}
|
|
207
201
|
});
|
|
208
202
|
}
|
|
209
203
|
|
|
210
204
|
// src/utils/utils.ts
|
|
211
|
-
function
|
|
205
|
+
function uint8ArrayToBase64(data, offset = 0, length = 0) {
|
|
212
206
|
if (length === 0) {
|
|
213
|
-
length =
|
|
207
|
+
length = data.byteLength;
|
|
214
208
|
}
|
|
215
|
-
const
|
|
209
|
+
const slice = offset === 0 && length === data.byteLength ? data : data.subarray(offset, offset + length);
|
|
216
210
|
let binary = "";
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
for (let i = 0; i < len; i++) {
|
|
220
|
-
binary += String.fromCharCode(bytes[i]);
|
|
211
|
+
for (let i = 0; i < slice.byteLength; i++) {
|
|
212
|
+
binary += String.fromCharCode(slice[i]);
|
|
221
213
|
}
|
|
222
214
|
return btoa(binary);
|
|
223
215
|
}
|
|
224
|
-
function
|
|
216
|
+
function base64ToUint8Array(base64) {
|
|
225
217
|
const binaryString = atob(base64);
|
|
226
218
|
const bytes = new Uint8Array(binaryString.length);
|
|
227
219
|
for (let i = 0; i < binaryString.length; i++) {
|
|
228
220
|
bytes[i] = binaryString.charCodeAt(i);
|
|
229
221
|
}
|
|
230
|
-
return bytes
|
|
222
|
+
return bytes;
|
|
231
223
|
}
|
|
232
|
-
function
|
|
224
|
+
function base64WriteToUint8Array(base64, buffer, offset) {
|
|
233
225
|
const binaryString = atob(base64);
|
|
234
|
-
const bytes = new Uint8Array(buffer);
|
|
235
226
|
for (let i = 0; i < binaryString.length; i++) {
|
|
236
|
-
|
|
227
|
+
buffer[offset + i] = binaryString.charCodeAt(i);
|
|
237
228
|
}
|
|
238
229
|
return binaryString.length;
|
|
239
230
|
}
|
|
240
231
|
|
|
241
232
|
// src/fs/file.ts
|
|
242
|
-
function readFile(path) {
|
|
233
|
+
function readFile(path, encoding) {
|
|
243
234
|
return bridge_default.callNative({
|
|
244
235
|
api: "fsReadFile",
|
|
245
236
|
data: {
|
|
246
237
|
path
|
|
247
238
|
}
|
|
248
|
-
}).then((res) => res.data).then((res) =>
|
|
239
|
+
}).then((res) => res.data).then((res) => {
|
|
240
|
+
const bytes = base64ToUint8Array(res);
|
|
241
|
+
return encoding ? new TextDecoder(encoding).decode(bytes) : bytes;
|
|
242
|
+
});
|
|
249
243
|
}
|
|
250
|
-
function readFileSync(path) {
|
|
244
|
+
function readFileSync(path, encoding) {
|
|
251
245
|
const res = bridge_default.callNativeSync({
|
|
252
246
|
api: "fsReadFileSync",
|
|
253
247
|
data: {
|
|
254
248
|
path
|
|
255
249
|
}
|
|
256
250
|
});
|
|
257
|
-
|
|
251
|
+
const bytes = base64ToUint8Array(res.data);
|
|
252
|
+
return encoding ? new TextDecoder(encoding).decode(bytes) : bytes;
|
|
258
253
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
base64 = arrayBufferToBase64(data);
|
|
263
|
-
} else {
|
|
264
|
-
const encoder = new TextEncoder();
|
|
265
|
-
const uint8Array = encoder.encode(data);
|
|
266
|
-
const arrayBuffer = uint8Array.buffer;
|
|
267
|
-
base64 = arrayBufferToBase64(arrayBuffer);
|
|
254
|
+
function toBase64(data) {
|
|
255
|
+
if (data instanceof Uint8Array) {
|
|
256
|
+
return uint8ArrayToBase64(data);
|
|
268
257
|
}
|
|
258
|
+
return uint8ArrayToBase64(new TextEncoder().encode(data));
|
|
259
|
+
}
|
|
260
|
+
async function writeFile(path, data) {
|
|
269
261
|
await bridge_default.callNative({
|
|
270
262
|
api: "fsWriteFile",
|
|
271
263
|
data: {
|
|
272
264
|
path,
|
|
273
|
-
data:
|
|
265
|
+
data: toBase64(data)
|
|
274
266
|
}
|
|
275
267
|
});
|
|
276
268
|
}
|
|
277
269
|
function writeFileSync(path, data) {
|
|
278
|
-
let base64 = "";
|
|
279
|
-
if (data instanceof ArrayBuffer) {
|
|
280
|
-
base64 = arrayBufferToBase64(data);
|
|
281
|
-
} else {
|
|
282
|
-
const encoder = new TextEncoder();
|
|
283
|
-
const uint8Array = encoder.encode(data);
|
|
284
|
-
const arrayBuffer = uint8Array.buffer;
|
|
285
|
-
base64 = arrayBufferToBase64(arrayBuffer);
|
|
286
|
-
}
|
|
287
270
|
bridge_default.callNativeSync({
|
|
288
271
|
api: "fsWriteFileSync",
|
|
289
272
|
data: {
|
|
290
273
|
path,
|
|
291
|
-
data:
|
|
274
|
+
data: toBase64(data)
|
|
292
275
|
}
|
|
293
276
|
});
|
|
294
277
|
}
|
|
295
278
|
async function appendFile(path, data) {
|
|
296
|
-
let base64 = "";
|
|
297
|
-
if (data instanceof ArrayBuffer) {
|
|
298
|
-
base64 = arrayBufferToBase64(data);
|
|
299
|
-
} else {
|
|
300
|
-
const encoder = new TextEncoder();
|
|
301
|
-
const uint8Array = encoder.encode(data);
|
|
302
|
-
const arrayBuffer = uint8Array.buffer;
|
|
303
|
-
base64 = arrayBufferToBase64(arrayBuffer);
|
|
304
|
-
}
|
|
305
279
|
await bridge_default.callNative({
|
|
306
280
|
api: "fsAppendFile",
|
|
307
281
|
data: {
|
|
308
282
|
path,
|
|
309
|
-
data:
|
|
283
|
+
data: toBase64(data)
|
|
310
284
|
}
|
|
311
285
|
});
|
|
312
286
|
}
|
|
313
287
|
function appendFileSync(path, data) {
|
|
314
|
-
let base64 = "";
|
|
315
|
-
if (data instanceof ArrayBuffer) {
|
|
316
|
-
base64 = arrayBufferToBase64(data);
|
|
317
|
-
} else {
|
|
318
|
-
const encoder = new TextEncoder();
|
|
319
|
-
const uint8Array = encoder.encode(data);
|
|
320
|
-
const arrayBuffer = uint8Array.buffer;
|
|
321
|
-
base64 = arrayBufferToBase64(arrayBuffer);
|
|
322
|
-
}
|
|
323
288
|
bridge_default.callNativeSync({
|
|
324
289
|
api: "fsAppendFileSync",
|
|
325
290
|
data: {
|
|
326
291
|
path,
|
|
327
|
-
data:
|
|
292
|
+
data: toBase64(data)
|
|
328
293
|
}
|
|
329
294
|
});
|
|
330
295
|
}
|
|
@@ -346,7 +311,7 @@ function copyFileSync(src, dest) {
|
|
|
346
311
|
}
|
|
347
312
|
});
|
|
348
313
|
}
|
|
349
|
-
async function truncate(path, length) {
|
|
314
|
+
async function truncate(path, length = 0) {
|
|
350
315
|
await bridge_default.callNative({
|
|
351
316
|
api: "fsTruncate",
|
|
352
317
|
data: {
|
|
@@ -355,7 +320,7 @@ async function truncate(path, length) {
|
|
|
355
320
|
}
|
|
356
321
|
});
|
|
357
322
|
}
|
|
358
|
-
function truncateSync(path, length) {
|
|
323
|
+
function truncateSync(path, length = 0) {
|
|
359
324
|
bridge_default.callNativeSync({
|
|
360
325
|
api: "fsTruncateSync",
|
|
361
326
|
data: {
|
|
@@ -420,24 +385,7 @@ async function fstat(fd) {
|
|
|
420
385
|
fd
|
|
421
386
|
}
|
|
422
387
|
});
|
|
423
|
-
|
|
424
|
-
file.atime = new Date(file.atimeMs);
|
|
425
|
-
file.mtime = new Date(file.mtimeMs);
|
|
426
|
-
file.ctime = new Date(file.ctimeMs);
|
|
427
|
-
file.birthtime = new Date(file.birthtimeMs);
|
|
428
|
-
const S_IFDIR = 16384;
|
|
429
|
-
const S_IFREG = 32768;
|
|
430
|
-
const S_IFLNK = 40960;
|
|
431
|
-
file.isDirectory = function() {
|
|
432
|
-
return (this.mode & S_IFDIR) === S_IFDIR;
|
|
433
|
-
};
|
|
434
|
-
file.isFile = function() {
|
|
435
|
-
return (this.mode & S_IFREG) === S_IFREG;
|
|
436
|
-
};
|
|
437
|
-
file.isSymbolicLink = function() {
|
|
438
|
-
return (this.mode & S_IFLNK) === S_IFLNK;
|
|
439
|
-
};
|
|
440
|
-
return file;
|
|
388
|
+
return enrichStats(res.data);
|
|
441
389
|
}
|
|
442
390
|
function fstatSync(fd) {
|
|
443
391
|
const res = bridge_default.callNativeSync({
|
|
@@ -446,26 +394,9 @@ function fstatSync(fd) {
|
|
|
446
394
|
fd
|
|
447
395
|
}
|
|
448
396
|
});
|
|
449
|
-
|
|
450
|
-
file.atime = new Date(file.atimeMs);
|
|
451
|
-
file.mtime = new Date(file.mtimeMs);
|
|
452
|
-
file.ctime = new Date(file.ctimeMs);
|
|
453
|
-
file.birthtime = new Date(file.birthtimeMs);
|
|
454
|
-
const S_IFDIR = 16384;
|
|
455
|
-
const S_IFREG = 32768;
|
|
456
|
-
const S_IFLNK = 40960;
|
|
457
|
-
file.isDirectory = function() {
|
|
458
|
-
return (this.mode & S_IFDIR) === S_IFDIR;
|
|
459
|
-
};
|
|
460
|
-
file.isFile = function() {
|
|
461
|
-
return (this.mode & S_IFREG) === S_IFREG;
|
|
462
|
-
};
|
|
463
|
-
file.isSymbolicLink = function() {
|
|
464
|
-
return (this.mode & S_IFLNK) === S_IFLNK;
|
|
465
|
-
};
|
|
466
|
-
return file;
|
|
397
|
+
return enrichStats(res.data);
|
|
467
398
|
}
|
|
468
|
-
async function ftruncate(fd, length) {
|
|
399
|
+
async function ftruncate(fd, length = 0) {
|
|
469
400
|
await bridge_default.callNative({
|
|
470
401
|
api: "fsFtruncate",
|
|
471
402
|
data: {
|
|
@@ -474,7 +405,7 @@ async function ftruncate(fd, length) {
|
|
|
474
405
|
}
|
|
475
406
|
});
|
|
476
407
|
}
|
|
477
|
-
function ftruncateSync(fd, length) {
|
|
408
|
+
function ftruncateSync(fd, length = 0) {
|
|
478
409
|
bridge_default.callNativeSync({
|
|
479
410
|
api: "fsFtruncateSync",
|
|
480
411
|
data: {
|
|
@@ -492,7 +423,7 @@ async function read(fd, buffer, offset, length, position) {
|
|
|
492
423
|
position
|
|
493
424
|
}
|
|
494
425
|
});
|
|
495
|
-
return
|
|
426
|
+
return base64WriteToUint8Array(res.data, buffer, offset);
|
|
496
427
|
}
|
|
497
428
|
function readSync(fd, buffer, offset, length, position) {
|
|
498
429
|
const res = bridge_default.callNativeSync({
|
|
@@ -503,10 +434,10 @@ function readSync(fd, buffer, offset, length, position) {
|
|
|
503
434
|
position
|
|
504
435
|
}
|
|
505
436
|
});
|
|
506
|
-
return
|
|
437
|
+
return base64WriteToUint8Array(res.data, buffer, offset);
|
|
507
438
|
}
|
|
508
439
|
function write(fd, buffer, offset, length, position) {
|
|
509
|
-
const base64 =
|
|
440
|
+
const base64 = uint8ArrayToBase64(buffer, offset, length);
|
|
510
441
|
return bridge_default.callNative({
|
|
511
442
|
api: "fsWrite",
|
|
512
443
|
data: {
|
|
@@ -517,7 +448,7 @@ function write(fd, buffer, offset, length, position) {
|
|
|
517
448
|
}).then((res) => res.data);
|
|
518
449
|
}
|
|
519
450
|
function writeSync(fd, buffer, offset, length, position) {
|
|
520
|
-
const base64 =
|
|
451
|
+
const base64 = uint8ArrayToBase64(buffer, offset, length);
|
|
521
452
|
return bridge_default.callNativeSync({
|
|
522
453
|
api: "fsWriteSync",
|
|
523
454
|
data: {
|
|
@@ -539,6 +470,8 @@ export {
|
|
|
539
470
|
copyFileSync,
|
|
540
471
|
cp,
|
|
541
472
|
cpSync,
|
|
473
|
+
enrichStats,
|
|
474
|
+
existsSync,
|
|
542
475
|
fstat,
|
|
543
476
|
fstatSync,
|
|
544
477
|
ftruncate,
|
|
@@ -548,11 +481,11 @@ export {
|
|
|
548
481
|
open,
|
|
549
482
|
openSync,
|
|
550
483
|
read,
|
|
551
|
-
readDir,
|
|
552
|
-
readDirSync,
|
|
553
484
|
readFile,
|
|
554
485
|
readFileSync,
|
|
555
486
|
readSync,
|
|
487
|
+
readdir,
|
|
488
|
+
readdirSync,
|
|
556
489
|
rename,
|
|
557
490
|
renameSync,
|
|
558
491
|
rm,
|