@gjsify/fs 0.4.19 → 0.4.21
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/sync.js +1 -1
- package/package.json +8 -8
package/lib/esm/sync.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{decode as e,encodeUint8Array as t,getEncodingFromOptions as n}from"./encoding.js";import{normalizePath as r,tempDirPath as i}from"./utils.js";import{FSWatcher as a}from"./fs-watcher.js";import{Dirent as o}from"./dirent.js";import{BigIntStats as s,STAT_ATTRIBUTES as c,Stats as l}from"./stats.js";import{FileHandle as u}from"./file-handle.js";import{createNodeError as d,isNotFoundError as f}from"./errors.js";import p from"@girs/glib-2.0";import m from"@girs/gio-2.0";import{join as h}from"node:path";import{Buffer as g}from"node:buffer";import{existsSync as _}from"@gjsify/utils";function statSync(e,t){let n=r(e);try{let e=m.File.new_for_path(n).query_info(c,m.FileQueryInfoFlags.NONE,null);return t?.bigint?new s(e,n):new l(e,n)}catch(e){if(t?.throwIfNoEntry===!1&&f(e))return;throw d(e,`stat`,n)}}function lstatSync(e,t){let n=r(e);try{let e=m.File.new_for_path(n).query_info(c,m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);return t?.bigint?new s(e,n):new l(e,n)}catch(e){if(t?.throwIfNoEntry===!1&&f(e))return;throw d(e,`lstat`,n)}}function readdirSync(e,t){let n=r(e),i=m.File.new_for_path(n).enumerate_children(`standard::name,standard::type`,m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null),a=[]
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{decode as e,encodeUint8Array as t,getEncodingFromOptions as n}from"./encoding.js";import{normalizePath as r,tempDirPath as i}from"./utils.js";import{FSWatcher as a}from"./fs-watcher.js";import{Dirent as o}from"./dirent.js";import{BigIntStats as s,STAT_ATTRIBUTES as c,Stats as l}from"./stats.js";import{FileHandle as u}from"./file-handle.js";import{createNodeError as d,isNotFoundError as f}from"./errors.js";import p from"@girs/glib-2.0";import m from"@girs/gio-2.0";import{join as h}from"node:path";import{Buffer as g}from"node:buffer";import{existsSync as _}from"@gjsify/utils";function statSync(e,t){let n=r(e);try{let e=m.File.new_for_path(n).query_info(c,m.FileQueryInfoFlags.NONE,null);return t?.bigint?new s(e,n):new l(e,n)}catch(e){if(t?.throwIfNoEntry===!1&&f(e))return;throw d(e,`stat`,n)}}function lstatSync(e,t){let n=r(e);try{let e=m.File.new_for_path(n).query_info(c,m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);return t?.bigint?new s(e,n):new l(e,n)}catch(e){if(t?.throwIfNoEntry===!1&&f(e))return;throw d(e,`lstat`,n)}}function readdirSync(e,t){let n=r(e),i=m.File.new_for_path(n).enumerate_children(`standard::name,standard::type`,m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null),a=[];try{let e=i.next_file(null);for(;e!==null;)a.push({name:e.get_name(),type:e.get_file_type()}),e=i.next_file(null)}finally{try{i.close(null)}catch{}}let s=[];for(let e of a){let r=h(n,e.name);if(t?.withFileTypes?s.push(new o(r,e.name,e.type)):s.push(e.name),t?.recursive&&e.type===m.FileType.DIRECTORY){let n=readdirSync(r,t);for(let t of n)typeof t==`string`?s.push(h(e.name,t)):s.push(t)}}return s}function realpathSync(e){let t=r(e),n=m.File.new_for_path(t),i=0;for(;;){let e=n.query_info(`standard::is-symlink,standard::symlink-target`,m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);if(!e.get_is_symlink())return n.get_path();let r=e.get_symlink_target(),a=n.get_parent();if(n=a?a.resolve_relative_path(r):m.File.new_for_path(r),++i>40)throw Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`)}}realpathSync.native=realpathSync;function symlinkSync(e,t,n){let i=r(t),a=r(e);m.File.new_for_path(i).make_symbolic_link(a,null)}function readFileSync(e,i={encoding:null,flag:`r`}){let a=r(e),o=m.File.new_for_path(a);try{let[e,r]=o.load_contents(null);if(!e)throw d(Error(`failed to read file`),`read`,a);return t(n(i,`buffer`),r)}catch(e){throw e.code&&typeof e.code==`string`?e:d(e,`read`,a)}}function mkdirSync(e,t){let n=!1,i=511;if(typeof t==`object`?(t?.recursive&&(n=t.recursive),t?.mode&&(i=t.mode)):i=t||511,e=r(e),typeof i==`string`)throw TypeError(`mode as string is currently not supported!`);if(n)return mkdirSyncRecursive(e,i);let a=m.File.new_for_path(e);try{a.make_directory(null)}catch(t){throw d(t,`mkdir`,e)}}function mkdirSyncRecursive(e,t){let n=m.File.new_for_path(e);try{return n.make_directory(null),e}catch(n){let r=n;if(r.code===m.IOErrorEnum.EXISTS)return;if(r.code===m.IOErrorEnum.NOT_FOUND){let r=h(e,`..`),i=m.File.new_for_path(r).get_path();if(i===e)throw d(n,`mkdir`,e);let a=mkdirSyncRecursive(i,t),o=m.File.new_for_path(e);try{o.make_directory(null)}catch(t){throw d(t,`mkdir`,e)}return a??e}throw d(n,`mkdir`,e)}}function rmdirSync(e,t){let n=r(e),i=m.File.new_for_path(n);try{if(i.query_info(`standard::type`,m.FileQueryInfoFlags.NONE,null).get_file_type()!==m.FileType.DIRECTORY)throw d(Object.assign(Error(),{code:4}),`rmdir`,n);if(i.enumerate_children(`standard::name`,m.FileQueryInfoFlags.NONE,null).next_file(null)!==null)throw d(Object.assign(Error(),{code:5}),`rmdir`,n);i.delete(null)}catch(e){throw e.code&&typeof e.code==`string`?e:d(e,`rmdir`,n)}}function unlinkSync(e){let t=r(e),n=m.File.new_for_path(t);try{n.delete(null)}catch(e){throw d(e,`unlink`,t)}}function writeFileSync(e,t){p.file_set_contents(r(e),t)}function renameSync(e,t){let n=r(e),i=r(t),a=m.File.new_for_path(n),o=m.File.new_for_path(i);try{a.move(o,m.FileCopyFlags.OVERWRITE,null,null)}catch(e){throw d(e,`rename`,n,i)}}function copyFileSync(e,t,n){let i=r(e),a=r(t),o=m.File.new_for_path(i),s=m.File.new_for_path(a),c=m.FileCopyFlags.NONE;n&&!(n&1)?c=m.FileCopyFlags.OVERWRITE:n||(c=m.FileCopyFlags.OVERWRITE);try{o.copy(s,c,null,null)}catch(e){throw d(e,`copyfile`,i,a)}}function accessSync(e,t){let n=r(e),i=m.File.new_for_path(n);try{let e=i.query_info(`access::*`,m.FileQueryInfoFlags.NONE,null);if(t!==void 0&&t!==0){let r={code:14,message:`permission denied, access '${n}'`};if(t&4&&!e.get_attribute_boolean(`access::can-read`)||t&2&&!e.get_attribute_boolean(`access::can-write`)||t&1&&!e.get_attribute_boolean(`access::can-execute`))throw d(r,`access`,n)}}catch(e){throw e.code&&typeof e.code==`string`?e:d(e,`access`,n)}}function appendFileSync(e,t,n){let i=r(e),a=m.File.new_for_path(i),o;o=typeof t==`string`?new TextEncoder().encode(t):t;try{let e=a.append_to(m.FileCreateFlags.NONE,null);o.length>0&&e.write_bytes(new p.Bytes(o),null),e.close(null)}catch(e){throw d(e,`appendfile`,i)}}function readlinkSync(e,t){let n=r(e),i=m.File.new_for_path(n);try{let e=i.query_info(`standard::symlink-target`,m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null).get_symlink_target();if(!e)throw Object.assign(Error(`EINVAL: invalid argument, readlink '${n}'`),{code:`EINVAL`,errno:-22,syscall:`readlink`,path:n});return(typeof t==`string`?t:t?.encoding)===`buffer`?g.from(e):e}catch(e){throw typeof e.code==`string`?e:d(e,`readlink`,n)}}function linkSync(e,t){let n=r(e),i=r(t);if(!p.spawn_command_line_sync(`ln ${n} ${i}`)[0])throw Object.assign(Error(`EPERM: operation not permitted, link '${n}' -> '${i}'`),{code:`EPERM`,errno:-1,syscall:`link`,path:n,dest:i})}function truncateSync(e,t){let n=r(e),i=m.File.new_for_path(n);try{let e=i.replace(null,!1,m.FileCreateFlags.NONE,null);if(t&&t>0){let[,n]=i.load_contents(null),r=n.slice(0,t);r.length>0&&e.write_bytes(new p.Bytes(r),null)}e.close(null)}catch(e){throw d(e,`truncate`,n)}}function chmodSync(e,t){let n=r(e),i=typeof t==`string`?parseInt(t,8):t;if(!p.spawn_command_line_sync(`chmod ${i.toString(8)} ${n}`)[0])throw Object.assign(Error(`EPERM: operation not permitted, chmod '${n}'`),{code:`EPERM`,errno:-1,syscall:`chmod`,path:n})}function chownSync(e,t,n){let i=r(e);if(!p.spawn_command_line_sync(`chown ${t}:${n} ${i}`)[0])throw Object.assign(Error(`EPERM: operation not permitted, chown '${i}'`),{code:`EPERM`,errno:-1,syscall:`chown`,path:i})}function watch(e,t,n){return new a(r(e),t,n)}function openSync(e,t,n){return new u({path:e,flags:t,mode:n})}function mkdtempSync(t,r){let a=n(r),o=i(t);return mkdirSync(o,{recursive:!1,mode:511}),e(o,a)}function rmSync(e,t){let n=r(e),i=m.File.new_for_path(n),a=t?.recursive||!1,s=t?.force||!1,c;try{c=new o(n)}catch(t){if(s&&f(t))return;throw d(t,`rm`,e)}if(c.isDirectory()){let r=readdirSync(e);if(!a&&r.length)throw d(Object.assign(Error(),{code:5}),`rm`,e);for(let e of r)rmSync(h(n,e),t)}try{i.delete(null)}catch(t){if(s&&f(t))return;throw d(t,`rm`,e)}}export{accessSync,appendFileSync,chmodSync,chownSync,copyFileSync,_ as existsSync,linkSync,lstatSync,mkdirSync,mkdtempSync,openSync,readFileSync,readdirSync,readlinkSync,realpathSync,renameSync,rmSync,rmdirSync,statSync,symlinkSync,truncateSync,unlinkSync,watch,writeFileSync};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/fs",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.21",
|
|
4
4
|
"description": "Node.js fs module for Gjs",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -37,18 +37,18 @@
|
|
|
37
37
|
"fs"
|
|
38
38
|
],
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@gjsify/cli": "^0.4.
|
|
41
|
-
"@gjsify/unit": "^0.4.
|
|
40
|
+
"@gjsify/cli": "^0.4.21",
|
|
41
|
+
"@gjsify/unit": "^0.4.21",
|
|
42
42
|
"@types/node": "^25.6.2",
|
|
43
43
|
"typescript": "^6.0.3"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@girs/gio-2.0": "2.88.0-4.0.0-rc.15",
|
|
47
47
|
"@girs/glib-2.0": "2.88.0-4.0.0-rc.15",
|
|
48
|
-
"@gjsify/buffer": "^0.4.
|
|
49
|
-
"@gjsify/events": "^0.4.
|
|
50
|
-
"@gjsify/stream": "^0.4.
|
|
51
|
-
"@gjsify/url": "^0.4.
|
|
52
|
-
"@gjsify/utils": "^0.4.
|
|
48
|
+
"@gjsify/buffer": "^0.4.21",
|
|
49
|
+
"@gjsify/events": "^0.4.21",
|
|
50
|
+
"@gjsify/stream": "^0.4.21",
|
|
51
|
+
"@gjsify/url": "^0.4.21",
|
|
52
|
+
"@gjsify/utils": "^0.4.21"
|
|
53
53
|
}
|
|
54
54
|
}
|