@gjsify/native-fs-bridge 0.64.51 → 0.64.53
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{assertNativeScript as e,isAndroid as t}from"@gjsify/native-platform";const n={openRead(e){let t=java,n=new t.io.File(e);if(!n.exists()||!n.isFile())return null;let r=new t.io.RandomAccessFile(e,`r`);return{readAt(e,n){r.seek(e);let i=t.lang.reflect.Array.newInstance(t.lang.Byte.TYPE,n),a=r.read(i,0,n);if(a<=0)return new Uint8Array;let o=new Uint8Array(a);for(let e=0;e<a;e++)o[e]=i[e]&255;return o},close:()=>r.close()}}},r={openRead(e){if(!NSFileManager.defaultManager.fileExistsAtPath_(e))return null;let t=NSFileHandle.fileHandleForReadingAtPath(e);return t===null?null:{readAt(e,n){t.seekToFileOffset(e);let r=t.readDataOfLength(n);return new Uint8Array(r.bytes,0,r.length).slice()},close:()=>t.closeFile()}}};function platformFdBackend(){return e(),t?n:r}export{platformFdBackend};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";function fdError(e,t,n,r){let i=Error(`${e}: ${t}, ${n}${r===void 0?``:` '${r}'`}`);return i.code=e,i.syscall=n,r!==void 0&&(i.path=r),i}function createFdTable(e){let t=new Map,n=3,lookup=(e,n)=>{let r=t.get(e);if(r===void 0)throw fdError(`EBADF`,`bad file descriptor`,n);return r};return{openSync(r,i=`r`){if(i!==`r`&&i!==0)throw fdError(`ENOSYS`,`flags ${String(i)} are not supported, only read-only`,`open`,r);let a=e.openRead(r);if(a===null)throw fdError(`ENOENT`,`no such file or directory`,`open`,r);let o=n++;return t.set(o,{handle:a,cursor:0}),o},readSync(e,t,n,r,i){let a=lookup(e,`read`),o=0,s=t.byteLength,c=null;if(typeof n==`object`&&n?(o=n.offset??0,s=n.length??t.byteLength-o,c=n.position):(o=n??0,s=r??t.byteLength-o,c=i),o<0||o>t.byteLength)throw fdError(`ERR_OUT_OF_RANGE`,`offset is out of range`,`read`);if(s<0||o+s>t.byteLength)throw fdError(`ERR_OUT_OF_RANGE`,`length is out of range`,`read`);if(s===0)return 0;let l=c==null||c===-1?a.cursor:Number(c),u=a.handle.readAt(l,s);return t.set(u,o),(c==null||c===-1)&&(a.cursor+=u.length),u.length},closeSync(e){let n=lookup(e,`close`);t.delete(e),n.handle.close()}}}export{createFdTable,fdError};
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{assertNativeScript as
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{platformFdBackend as e}from"./fd-backend.js";import{createFdTable as t}from"./fd-table.js";import{assertNativeScript as n,isAndroid as r}from"@gjsify/native-platform";function androidIO(){return java.io}function iosFileManager(){return NSFileManager.defaultManager}const i={ENOENT:`no such file or directory`,EEXIST:`file already exists`,EACCES:`permission denied`};function fsError(e,t,n){let r=Error(`${e}: ${i[e]??e}, ${t} '${n}'`);return r.code=e,r.path=n,r.syscall=t,r}function stringToBytes(e,t=`utf8`){let n=[];if(t===`base64`){let t=atob(e);for(let e=0;e<t.length;e++)n.push(t.charCodeAt(e))}else{let t=new TextEncoder().encode(e);for(let e=0;e<t.length;e++)n.push(t[e])}return n}function bytesToString(e,t=`utf8`){let n=new Uint8Array(e);if(t===`base64`){let e=``;for(let t=0;t<n.length;t++)e+=String.fromCharCode(n[t]);return btoa(e)}return new TextDecoder(t).decode(n)}function androidReadFile(e,t){return new Promise((n,r)=>{try{let i=androidIO(),a=new i.File(e);if(!a.exists())return r(fsError(`ENOENT`,`open`,e));let o=new i.FileInputStream(a),s=[],c=Array.from({length:4096}),l;for(;(l=o.read(c))!==-1;)for(let e=0;e<l;e++)s.push(c[e]);o.close(),n(t?bytesToString(s,t):new Uint8Array(s))}catch(e){r(e instanceof Error?e:Error(String(e)))}})}function androidWriteFile(e,t,n=`utf8`){return new Promise((r,i)=>{try{let i=androidIO(),a=new i.File(e),o=a.getParentFile();o!==null&&!o.exists()&&o.mkdirs();let s=new i.FileOutputStream(a,!1),c=typeof t==`string`?stringToBytes(t,n):Array.from(t);s.write(c),s.close(),r()}catch(e){i(e instanceof Error?e:Error(String(e)))}})}function androidReaddir(e){return new Promise((t,n)=>{try{let r=new(androidIO()).File(e);if(!r.exists()||!r.isDirectory())return n(fsError(`ENOENT`,`scandir`,e));let i=r.list();t(i===null?[]:Array.from(i))}catch(e){n(e instanceof Error?e:Error(String(e)))}})}function androidStat(e){return new Promise((t,n)=>{try{let r=new(androidIO()).File(e);if(!r.exists())return n(fsError(`ENOENT`,`stat`,e));let i=r.isFile()?r.length():0,a=new Date(r.lastModified()),o=r.isFile(),s=r.isDirectory();t({size:i,mtime:a,isFile:()=>o,isDirectory:()=>s})}catch(e){n(e instanceof Error?e:Error(String(e)))}})}function androidMkdir(e,t){return new Promise((n,r)=>{try{let i=new(androidIO()).File(e);if(i.exists())return t?.recursive?n():r(fsError(`EEXIST`,`mkdir`,e));if(!i.mkdirs())return r(fsError(`EACCES`,`mkdir`,e));n()}catch(e){r(e instanceof Error?e:Error(String(e)))}})}function androidUnlink(e){return new Promise((t,n)=>{try{let r=new(androidIO()).File(e);if(!r.exists())return n(fsError(`ENOENT`,`unlink`,e));if(!r.delete())return n(fsError(`EACCES`,`unlink`,e));t()}catch(e){n(e instanceof Error?e:Error(String(e)))}})}function iosReadFile(e,t){return new Promise((n,r)=>{try{let i=iosFileManager().contentsAtPath_(e);if(i===null)return r(fsError(`ENOENT`,`open`,e));let a=i.bytes,o=new Uint8Array(a,0,i.length);n(t?bytesToString(Array.from(o),t):new Uint8Array(o))}catch(e){r(e instanceof Error?e:Error(String(e)))}})}function iosWriteFile(e,t,n=`utf8`){return new Promise((r,i)=>{try{let a=typeof t==`string`?new Uint8Array(stringToBytes(t,n)):t,o=a.byteOffset===0&&a.byteLength===a.buffer.byteLength?a:a.slice();if(!globalThis.NSData.dataWithBytesLength_(o.buffer,o.byteLength).writeToFileAtomically_(e,!0))return i(fsError(`EACCES`,`open`,e));r()}catch(e){i(e instanceof Error?e:Error(String(e)))}})}function iosReaddir(e){return new Promise((t,n)=>{try{let r=iosFileManager().contentsOfDirectoryAtPathError_(e,null);if(r===null)return n(fsError(`ENOENT`,`scandir`,e));t(Array.from(r))}catch(e){n(e instanceof Error?e:Error(String(e)))}})}function iosStat(e){return new Promise((t,n)=>{try{let r=iosFileManager().attributesOfItemAtPathError_(e,null);if(r===null)return n(fsError(`ENOENT`,`stat`,e));let i=r.NSFileType,a=i===`NSFileTypeRegular`,o=i===`NSFileTypeDirectory`;t({size:r.NSFileSize??0,mtime:new Date(r.NSFileModificationDate??0),isFile:()=>a,isDirectory:()=>o})}catch(e){n(e instanceof Error?e:Error(String(e)))}})}function iosMkdir(e,t){return new Promise((n,r)=>{try{let i=iosFileManager();if(i.fileExistsAtPath_(e))return t?.recursive?n():r(fsError(`EEXIST`,`mkdir`,e));if(!i.createDirectoryAtPathWithIntermediateDirectoriesAttributesError_(e,t?.recursive??!1,null,null))return r(fsError(`EACCES`,`mkdir`,e));n()}catch(e){r(e instanceof Error?e:Error(String(e)))}})}function iosUnlink(e){return new Promise((t,n)=>{try{let r=iosFileManager();if(!r.fileExistsAtPath_(e))return n(fsError(`ENOENT`,`unlink`,e));if(!r.removeItemAtPathError_(e,null))return n(fsError(`EACCES`,`unlink`,e));t()}catch(e){n(e instanceof Error?e:Error(String(e)))}})}function readFile(e,t){n();let i=t==null?null:typeof t==`string`?t:t.encoding??null;return r?androidReadFile(e,i):iosReadFile(e,i)}function writeFile(e,t,i){n();let a=i==null?`utf8`:typeof i==`string`?i:i.encoding??`utf8`;return r?androidWriteFile(e,t,a):iosWriteFile(e,t,a)}function readdir(e,t){return n(),r?androidReaddir(e):iosReaddir(e)}function stat(e){return n(),r?androidStat(e):iosStat(e)}function mkdir(e,t){return n(),r?androidMkdir(e,t):iosMkdir(e,t)}function unlink(e){return n(),r?androidUnlink(e):iosUnlink(e)}function exists(e){return n(),stat(e).then(()=>!0,()=>!1)}let a;const fds=()=>a??=t(e());function openSync(e,t){return fds().openSync(e,t)}function readSync(e,t,n,r,i){return fds().readSync(e,t,n,r,i)}function closeSync(e){fds().closeSync(e)}export{closeSync,exists,mkdir,openSync,readFile,readSync,readdir,stat,unlink,writeFile};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** One open, read-only file as the platform exposes it. */
|
|
2
|
+
export interface FdHandle {
|
|
3
|
+
/** Read up to `length` bytes starting at absolute `position`; fewer (or 0) at EOF. */
|
|
4
|
+
readAt(position: number, length: number): Uint8Array;
|
|
5
|
+
close(): void;
|
|
6
|
+
}
|
|
7
|
+
export interface FdBackend {
|
|
8
|
+
/** Open `path` for reading; returns `null` when it does not exist. */
|
|
9
|
+
openRead(path: string): FdHandle | null;
|
|
10
|
+
}
|
|
11
|
+
export interface FdFsError extends Error {
|
|
12
|
+
code: string;
|
|
13
|
+
syscall: string;
|
|
14
|
+
path?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function fdError(code: string, message: string, syscall: string, path?: string): FdFsError;
|
|
17
|
+
export interface ReadSyncOptions {
|
|
18
|
+
offset?: number;
|
|
19
|
+
length?: number;
|
|
20
|
+
position?: number | bigint | null;
|
|
21
|
+
}
|
|
22
|
+
export declare function createFdTable(backend: FdBackend): {
|
|
23
|
+
openSync(path: string, flags?: string | number): number;
|
|
24
|
+
readSync(fd: number, buffer: Uint8Array, offsetOrOptions?: number | ReadSyncOptions | null, lengthArg?: number, positionArg?: number | bigint | null): number;
|
|
25
|
+
closeSync(fd: number): void;
|
|
26
|
+
};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -50,3 +50,11 @@ export declare function unlink(path: string): Promise<void>;
|
|
|
50
50
|
* Check whether a path exists (resolves true/false, never rejects).
|
|
51
51
|
*/
|
|
52
52
|
export declare function exists(path: string): Promise<boolean>;
|
|
53
|
+
import { type ReadSyncOptions } from './fd-table.js';
|
|
54
|
+
export type { FdBackend, FdHandle, ReadSyncOptions } from './fd-table.js';
|
|
55
|
+
/** Open a file for reading and return a descriptor. Only the read-only flag `'r'` is supported. */
|
|
56
|
+
export declare function openSync(path: string, flags?: string | number): number;
|
|
57
|
+
/** Read from a descriptor into `buffer`; `position` `null` continues from the descriptor's cursor. */
|
|
58
|
+
export declare function readSync(fd: number, buffer: Uint8Array, offsetOrOptions?: number | ReadSyncOptions | null, length?: number, position?: number | bigint | null): number;
|
|
59
|
+
/** Close a descriptor from {@link openSync}. */
|
|
60
|
+
export declare function closeSync(fd: number): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/native-fs-bridge",
|
|
3
|
-
"version": "0.64.
|
|
3
|
+
"version": "0.64.53",
|
|
4
4
|
"description": "NativeScript native bridge for node:fs/promises — Android (java.io.File) + iOS (NSFileManager)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
"ios"
|
|
36
36
|
],
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@gjsify/cli": "0.64.
|
|
39
|
-
"@gjsify/unit": "0.64.
|
|
38
|
+
"@gjsify/cli": "0.64.53",
|
|
39
|
+
"@gjsify/unit": "0.64.53",
|
|
40
40
|
"@types/node": "^25.9.2",
|
|
41
41
|
"typescript": "^6.0.3"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@gjsify/native-platform": "0.64.
|
|
44
|
+
"@gjsify/native-platform": "0.64.53"
|
|
45
45
|
},
|
|
46
46
|
"gjsify": {
|
|
47
47
|
"runtimes": {
|