@gjsify/native-fs-bridge 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/index.js +1 -1
- package/package.json +6 -3
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{assertNativeScript as e,isAndroid as t}from"@gjsify/native-platform";function androidIO(){return java.io}function iosFileManager(){return NSFileManager.defaultManager}const n={ENOENT:`no such file or directory`,EEXIST:`file already exists`,EACCES:`permission denied`};function fsError(e,t,r){let i=Error(`${e}: ${n[e]??e}, ${t} '${r}'`);return i.code=e,i.path=r,i.syscall=t,i}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(n,r){e();let i=r==null?null:typeof r==`string`?r:r.encoding??null;return t?androidReadFile(n,i):iosReadFile(n,i)}function writeFile(n,r,i){e();let a=i==null?`utf8`:typeof i==`string`?i:i.encoding??`utf8`;return t?androidWriteFile(n,r,a):iosWriteFile(n,r,a)}function readdir(n,r){return e(),t?androidReaddir(n):iosReaddir(n)}function stat(n){return e(),t?androidStat(n):iosStat(n)}function mkdir(n,r){return e(),t?androidMkdir(n,r):iosMkdir(n,r)}function unlink(n){return e(),t?androidUnlink(n):iosUnlink(n)}function exists(t){return e(),stat(t).then(()=>!0,()=>!1)}export{exists,mkdir,readFile,readdir,stat,unlink,writeFile};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/native-fs-bridge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
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,11 +35,14 @@
|
|
|
35
35
|
"ios"
|
|
36
36
|
],
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@gjsify/cli": "^0.
|
|
39
|
-
"@gjsify/unit": "^0.
|
|
38
|
+
"@gjsify/cli": "^0.7.0",
|
|
39
|
+
"@gjsify/unit": "^0.7.0",
|
|
40
40
|
"@types/node": "^25.9.2",
|
|
41
41
|
"typescript": "^6.0.3"
|
|
42
42
|
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@gjsify/native-platform": "^0.7.0"
|
|
45
|
+
},
|
|
43
46
|
"gjsify": {
|
|
44
47
|
"runtimes": {
|
|
45
48
|
"gjs": "none",
|