@gjsify/fs 0.3.15 → 0.3.17

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/dir.js CHANGED
@@ -1,152 +1 @@
1
- import { normalizePath } from "./utils.js";
2
- import { Dirent } from "./dirent.js";
3
- import { createNodeError } from "./errors.js";
4
- import GLib from "@girs/glib-2.0";
5
- import Gio from "@girs/gio-2.0";
6
-
7
- //#region src/dir.ts
8
- const DIR_ATTRS = "standard::name,standard::type,standard::is-symlink,standard::size,standard::symlink-target,unix::uid,unix::gid,unix::mode,time::modified,time::access,time::created";
9
- var Dir = class {
10
- path;
11
- _enumerator;
12
- _closed = false;
13
- constructor(path, enumerator) {
14
- this.path = path;
15
- this._enumerator = enumerator;
16
- }
17
- _assertOpen() {
18
- if (this._closed) {
19
- const err = new Error("Directory handle was closed");
20
- err.code = "ERR_DIR_CLOSED";
21
- throw err;
22
- }
23
- }
24
- readSync() {
25
- this._assertOpen();
26
- try {
27
- const info = this._enumerator.next_file(null);
28
- if (info === null) return null;
29
- const name = info.get_name();
30
- const fileType = info.get_file_type();
31
- const childPath = this.path.endsWith("/") ? this.path + name : this.path + "/" + name;
32
- return new Dirent(childPath, name, fileType);
33
- } catch (err) {
34
- throw createNodeError(err, "readdir", this.path);
35
- }
36
- }
37
- read(callback) {
38
- if (callback !== undefined) {
39
- if (typeof callback !== "function") {
40
- throw new TypeError("The \"callback\" argument must be of type function");
41
- }
42
- try {
43
- this._assertOpen();
44
- const dirent = this.readSync();
45
- Promise.resolve().then(() => callback(null, dirent));
46
- } catch (err) {
47
- Promise.resolve().then(() => callback(err, null));
48
- }
49
- return;
50
- }
51
- return new Promise((resolve, reject) => {
52
- try {
53
- this._assertOpen();
54
- resolve(this.readSync());
55
- } catch (err) {
56
- reject(err);
57
- }
58
- });
59
- }
60
- closeSync() {
61
- this._assertOpen();
62
- this._closed = true;
63
- try {
64
- this._enumerator.close(null);
65
- } catch {}
66
- this._enumerator = null;
67
- }
68
- close(callback) {
69
- if (callback !== undefined) {
70
- if (typeof callback !== "function") {
71
- throw new TypeError("The \"callback\" argument must be of type function");
72
- }
73
- try {
74
- this.closeSync();
75
- Promise.resolve().then(() => callback(null));
76
- } catch (err) {
77
- Promise.resolve().then(() => callback(err));
78
- }
79
- return;
80
- }
81
- return new Promise((resolve, reject) => {
82
- try {
83
- this.closeSync();
84
- resolve();
85
- } catch (err) {
86
- reject(err);
87
- }
88
- });
89
- }
90
- async *[Symbol.asyncIterator]() {
91
- try {
92
- while (true) {
93
- const dirent = await this.read();
94
- if (dirent === null) break;
95
- yield dirent;
96
- }
97
- } finally {
98
- if (!this._closed) {
99
- await this.close();
100
- }
101
- }
102
- }
103
- };
104
- function _openDir(pathStr) {
105
- const file = Gio.File.new_for_path(pathStr);
106
- let enumerator;
107
- try {
108
- enumerator = file.enumerate_children(DIR_ATTRS, Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
109
- } catch (err) {
110
- throw createNodeError(err, "opendir", pathStr);
111
- }
112
- return new Dir(pathStr, enumerator);
113
- }
114
- function opendirSync(path) {
115
- return _openDir(normalizePath(path));
116
- }
117
- function opendir(path, optionsOrCallback, callback) {
118
- let cb;
119
- if (typeof optionsOrCallback === "function") {
120
- cb = optionsOrCallback;
121
- } else {
122
- cb = callback;
123
- }
124
- if (typeof cb !== "function") {
125
- throw new TypeError("The \"callback\" argument must be of type function");
126
- }
127
- Promise.resolve().then(() => {
128
- try {
129
- const dir = opendirSync(path);
130
- cb(null, dir);
131
- } catch (err) {
132
- cb(err, null);
133
- }
134
- });
135
- }
136
- async function opendirAsync(path, _options) {
137
- return new Promise((resolve, reject) => {
138
- const pathStr = normalizePath(path);
139
- const file = Gio.File.new_for_path(pathStr);
140
- file.enumerate_children_async(DIR_ATTRS, Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, GLib.PRIORITY_DEFAULT, null, (_source, result) => {
141
- try {
142
- const enumerator = file.enumerate_children_finish(result);
143
- resolve(new Dir(pathStr, enumerator));
144
- } catch (err) {
145
- reject(createNodeError(err, "opendir", pathStr));
146
- }
147
- });
148
- });
149
- }
150
-
151
- //#endregion
152
- export { Dir, opendir, opendirAsync, opendirSync };
1
+ import{normalizePath as e}from"./utils.js";import{Dirent as t}from"./dirent.js";import{createNodeError as n}from"./errors.js";import r from"@girs/glib-2.0";import i from"@girs/gio-2.0";const a=`standard::name,standard::type,standard::is-symlink,standard::size,standard::symlink-target,unix::uid,unix::gid,unix::mode,time::modified,time::access,time::created`;var o=class{path;_enumerator;_closed=!1;constructor(e,t){this.path=e,this._enumerator=t}_assertOpen(){if(this._closed){let e=Error(`Directory handle was closed`);throw e.code=`ERR_DIR_CLOSED`,e}}readSync(){this._assertOpen();try{let e=this._enumerator.next_file(null);if(e===null)return null;let n=e.get_name(),r=e.get_file_type();return new t(this.path.endsWith(`/`)?this.path+n:this.path+`/`+n,n,r)}catch(e){throw n(e,`readdir`,this.path)}}read(e){if(e!==void 0){if(typeof e!=`function`)throw TypeError(`The "callback" argument must be of type function`);try{this._assertOpen();let t=this.readSync();Promise.resolve().then(()=>e(null,t))}catch(t){Promise.resolve().then(()=>e(t,null))}return}return new Promise((e,t)=>{try{this._assertOpen(),e(this.readSync())}catch(e){t(e)}})}closeSync(){this._assertOpen(),this._closed=!0;try{this._enumerator.close(null)}catch{}this._enumerator=null}close(e){if(e!==void 0){if(typeof e!=`function`)throw TypeError(`The "callback" argument must be of type function`);try{this.closeSync(),Promise.resolve().then(()=>e(null))}catch(t){Promise.resolve().then(()=>e(t))}return}return new Promise((e,t)=>{try{this.closeSync(),e()}catch(e){t(e)}})}async*[Symbol.asyncIterator](){try{for(;;){let e=await this.read();if(e===null)break;yield e}}finally{this._closed||await this.close()}}};function s(e){let t=i.File.new_for_path(e),r;try{r=t.enumerate_children(a,i.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(t){throw n(t,`opendir`,e)}return new o(e,r)}function c(t){return s(e(t))}function l(e,t,n){let r;if(r=typeof t==`function`?t:n,typeof r!=`function`)throw TypeError(`The "callback" argument must be of type function`);Promise.resolve().then(()=>{try{let t=c(e);r(null,t)}catch(e){r(e,null)}})}async function u(t,s){return new Promise((s,c)=>{let l=e(t),u=i.File.new_for_path(l);u.enumerate_children_async(a,i.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,r.PRIORITY_DEFAULT,null,(e,t)=>{try{s(new o(l,u.enumerate_children_finish(t)))}catch(e){c(n(e,`opendir`,l))}})})}export{o as Dir,l as opendir,u as opendirAsync,c as opendirSync};
package/lib/esm/dirent.js CHANGED
@@ -1,148 +1 @@
1
- import Gio from "@girs/gio-2.0";
2
- import { basename, dirname } from "node:path";
3
-
4
- //#region src/dirent.ts
5
- const S_IFMT = 61440;
6
- const S_IFSOCK = 49152;
7
- const S_IFLNK = 40960;
8
- const S_IFREG = 32768;
9
- const S_IFBLK = 24576;
10
- const S_IFDIR = 16384;
11
- const S_IFCHR = 8192;
12
- const S_IFIFO = 4096;
13
- /**
14
- * A representation of a directory entry, which can be a file or a subdirectory
15
- * within the directory, as returned by reading from an `fs.Dir`. The
16
- * directory entry is a combination of the file name and file type pairs.
17
- *
18
- * Additionally, when {@link readdir} or {@link readdirSync} is called with
19
- * the `withFileTypes` option set to `true`, the resulting array is filled with `fs.Dirent` objects, rather than strings or `Buffer` s.
20
- * @since v10.10.0
21
- */
22
- var Dirent = class {
23
- /**
24
- * The file name that this `fs.Dirent` object refers to. The type of this
25
- * value is determined by the `options.encoding` passed to {@link readdir} or {@link readdirSync}.
26
- * @since v10.10.0
27
- */
28
- name;
29
- /**
30
- * The path to the parent directory of the file this `fs.Dirent` object refers to.
31
- * @since v20.12.0, v18.20.0
32
- */
33
- parentPath;
34
- _isFile = false;
35
- _isDirectory = false;
36
- _isBlockDevice = false;
37
- _isCharacterDevice = false;
38
- _isSymbolicLink = false;
39
- _isFIFO = false;
40
- _isSocket = false;
41
- /** This is not part of node.fs and is used internal by gjsify */
42
- _file;
43
- /** This is not part of node.fs and is used internal by gjsify */
44
- constructor(path, filename, fileType) {
45
- if (!filename) filename = basename(path);
46
- this.name = filename;
47
- this.parentPath = dirname(path);
48
- this._file = Gio.File.new_for_path(path);
49
- const type = fileType ?? this._file.query_file_type(Gio.FileQueryInfoFlags.NONE, null);
50
- switch (type) {
51
- case Gio.FileType.DIRECTORY:
52
- this._isDirectory = true;
53
- break;
54
- case Gio.FileType.MOUNTABLE: break;
55
- case Gio.FileType.REGULAR:
56
- this._isFile = true;
57
- break;
58
- case Gio.FileType.SYMBOLIC_LINK:
59
- case Gio.FileType.SHORTCUT:
60
- this._isSymbolicLink = true;
61
- break;
62
- case Gio.FileType.SPECIAL:
63
- this._classifySpecialFile(path);
64
- break;
65
- }
66
- }
67
- /**
68
- * Classify a SPECIAL file type using the unix::mode attribute from Gio.FileInfo.
69
- * Falls back to marking nothing if the mode attribute is unavailable.
70
- */
71
- _classifySpecialFile(path) {
72
- try {
73
- const file = Gio.File.new_for_path(path);
74
- const info = file.query_info("unix::mode", Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
75
- const mode = info.get_attribute_uint32("unix::mode");
76
- if (mode === 0) return;
77
- const fmt = mode & S_IFMT;
78
- switch (fmt) {
79
- case S_IFBLK:
80
- this._isBlockDevice = true;
81
- break;
82
- case S_IFCHR:
83
- this._isCharacterDevice = true;
84
- break;
85
- case S_IFSOCK:
86
- this._isSocket = true;
87
- break;
88
- case S_IFIFO:
89
- this._isFIFO = true;
90
- break;
91
- }
92
- } catch {}
93
- }
94
- /**
95
- * Returns `true` if the `fs.Dirent` object describes a regular file.
96
- * @since v10.10.0
97
- */
98
- isFile() {
99
- return this._isFile;
100
- }
101
- /**
102
- * Returns `true` if the `fs.Dirent` object describes a file system
103
- * directory.
104
- * @since v10.10.0
105
- */
106
- isDirectory() {
107
- return this._isDirectory;
108
- }
109
- /**
110
- * Returns `true` if the `fs.Dirent` object describes a block device.
111
- * @since v10.10.0
112
- */
113
- isBlockDevice() {
114
- return this._isBlockDevice;
115
- }
116
- /**
117
- * Returns `true` if the `fs.Dirent` object describes a character device.
118
- * @since v10.10.0
119
- */
120
- isCharacterDevice() {
121
- return this._isCharacterDevice;
122
- }
123
- /**
124
- * Returns `true` if the `fs.Dirent` object describes a symbolic link.
125
- * @since v10.10.0
126
- */
127
- isSymbolicLink() {
128
- return this._isSymbolicLink;
129
- }
130
- /**
131
- * Returns `true` if the `fs.Dirent` object describes a first-in-first-out
132
- * (FIFO) pipe.
133
- * @since v10.10.0
134
- */
135
- isFIFO() {
136
- return this._isFIFO;
137
- }
138
- /**
139
- * Returns `true` if the `fs.Dirent` object describes a socket.
140
- * @since v10.10.0
141
- */
142
- isSocket() {
143
- return this._isSocket;
144
- }
145
- };
146
-
147
- //#endregion
148
- export { Dirent };
1
+ import e from"@girs/gio-2.0";import{basename as t,dirname as n}from"node:path";var r=class{name;parentPath;_isFile=!1;_isDirectory=!1;_isBlockDevice=!1;_isCharacterDevice=!1;_isSymbolicLink=!1;_isFIFO=!1;_isSocket=!1;_file;constructor(r,i,a){switch(i||=t(r),this.name=i,this.parentPath=n(r),this._file=e.File.new_for_path(r),a??this._file.query_file_type(e.FileQueryInfoFlags.NONE,null)){case e.FileType.DIRECTORY:this._isDirectory=!0;break;case e.FileType.MOUNTABLE:break;case e.FileType.REGULAR:this._isFile=!0;break;case e.FileType.SYMBOLIC_LINK:case e.FileType.SHORTCUT:this._isSymbolicLink=!0;break;case e.FileType.SPECIAL:this._classifySpecialFile(r);break}}_classifySpecialFile(t){try{let n=e.File.new_for_path(t).query_info(`unix::mode`,e.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null).get_attribute_uint32(`unix::mode`);if(n===0)return;switch(n&61440){case 24576:this._isBlockDevice=!0;break;case 8192:this._isCharacterDevice=!0;break;case 49152:this._isSocket=!0;break;case 4096:this._isFIFO=!0;break}}catch{}}isFile(){return this._isFile}isDirectory(){return this._isDirectory}isBlockDevice(){return this._isBlockDevice}isCharacterDevice(){return this._isCharacterDevice}isSymbolicLink(){return this._isSymbolicLink}isFIFO(){return this._isFIFO}isSocket(){return this._isSocket}};export{r as Dirent};
@@ -1,36 +1 @@
1
- import { Buffer } from "node:buffer";
2
-
3
- //#region src/encoding.ts
4
- function getEncodingFromOptions(options = {
5
- encoding: null,
6
- flag: "r"
7
- }, defaultEncoding = "utf8") {
8
- if (options === null) {
9
- return defaultEncoding;
10
- }
11
- if (typeof options === "string") {
12
- return options;
13
- }
14
- if (typeof options === "object" && typeof options.encoding === "string") {
15
- return options.encoding;
16
- }
17
- return defaultEncoding;
18
- }
19
- function encodeUint8Array(encoding, data) {
20
- if (encoding === "buffer") {
21
- return Buffer.from(data);
22
- }
23
- const decoder = new TextDecoder(encoding);
24
- return decoder.decode(data);
25
- }
26
- function decode(str, encoding) {
27
- if (!encoding) return str;
28
- else {
29
- const decoder = new TextDecoder(encoding);
30
- const encoder = new TextEncoder();
31
- return decoder.decode(encoder.encode(str));
32
- }
33
- }
34
-
35
- //#endregion
36
- export { decode, encodeUint8Array, getEncodingFromOptions };
1
+ import{Buffer as e}from"node:buffer";function t(e={encoding:null,flag:`r`},t=`utf8`){return e===null?t:typeof e==`string`?e:typeof e==`object`&&typeof e.encoding==`string`?e.encoding:t}function n(t,n){return t===`buffer`?e.from(n):new TextDecoder(t).decode(n)}function r(e,t){if(t){let n=new TextDecoder(t),r=new TextEncoder;return n.decode(r.encode(e))}else return e}export{r as decode,n as encodeUint8Array,t as getEncodingFromOptions};
package/lib/esm/errors.js CHANGED
@@ -1,17 +1 @@
1
- import { createNodeError as createNodeError$1, isNotFoundError } from "@gjsify/utils";
2
-
3
- //#region src/errors.ts
4
- /**
5
- * Create a Node.js-style ErrnoException from a Gio error, with fs-specific path/dest fields.
6
- */
7
- function createNodeError(err, syscall, path, dest) {
8
- const pathStr = path.toString();
9
- const error = createNodeError$1(err, syscall, {
10
- path: pathStr,
11
- dest: dest?.toString()
12
- });
13
- return error;
14
- }
15
-
16
- //#endregion
17
- export { createNodeError, isNotFoundError };
1
+ import{createNodeError as e,isNotFoundError as t}from"@gjsify/utils";function n(t,n,r,i){return e(t,n,{path:r.toString(),dest:i?.toString()})}export{n as createNodeError,t as isNotFoundError};
package/lib/esm/fd-ops.js CHANGED
@@ -1,172 +1 @@
1
- import { normalizePath } from "./utils.js";
2
- import { FileHandle } from "./file-handle.js";
3
- import { chmodSync, chownSync, readFileSync, statSync, truncateSync } from "./sync.js";
4
- import { utimesSync } from "./utimes.js";
5
-
6
- //#region src/fd-ops.ts
7
- function getFH(fd) {
8
- if (fd instanceof FileHandle) return FileHandle.getInstance(fd.fd);
9
- return FileHandle.getInstance(fd);
10
- }
11
- function fstatSync(fd, options) {
12
- return statSync(normalizePath(getFH(fd).options.path), options);
13
- }
14
- function fstat(fd, optionsOrCb, callback) {
15
- if (typeof optionsOrCb === "function") {
16
- callback = optionsOrCb;
17
- optionsOrCb = {};
18
- }
19
- Promise.resolve().then(() => fstatSync(fd, optionsOrCb)).then((s) => callback(null, s), callback);
20
- }
21
- async function fstatAsync(fd, options) {
22
- return fstatSync(fd, options);
23
- }
24
- function ftruncateSync(fd, len = 0) {
25
- truncateSync(normalizePath(getFH(fd).options.path), len);
26
- }
27
- function ftruncate(fd, lenOrCb, callback) {
28
- if (typeof lenOrCb === "function") {
29
- callback = lenOrCb;
30
- lenOrCb = 0;
31
- }
32
- Promise.resolve().then(() => ftruncateSync(fd, lenOrCb)).then(() => callback(null), callback);
33
- }
34
- async function ftruncateAsync(fd, len = 0) {
35
- ftruncateSync(fd, len);
36
- }
37
- function fdatasyncSync(fd) {
38
- getFH(fd)._flushSync();
39
- }
40
- function fdatasync(fd, callback) {
41
- Promise.resolve().then(() => fdatasyncSync(fd)).then(() => callback(null), callback);
42
- }
43
- async function fdatasyncAsync(fd) {
44
- fdatasyncSync(fd);
45
- }
46
- function fsyncSync(fd) {
47
- getFH(fd)._flushSync();
48
- }
49
- function fsync(fd, callback) {
50
- Promise.resolve().then(() => fsyncSync(fd)).then(() => callback(null), callback);
51
- }
52
- async function fsyncAsync(fd) {
53
- fsyncSync(fd);
54
- }
55
- function fchmodSync(fd, mode) {
56
- chmodSync(normalizePath(getFH(fd).options.path), mode);
57
- }
58
- function fchmod(fd, mode, callback) {
59
- Promise.resolve().then(() => fchmodSync(fd, mode)).then(() => callback(null), callback);
60
- }
61
- async function fchmodAsync(fd, mode) {
62
- fchmodSync(fd, mode);
63
- }
64
- function fchownSync(fd, uid, gid) {
65
- chownSync(normalizePath(getFH(fd).options.path), uid, gid);
66
- }
67
- function fchown(fd, uid, gid, callback) {
68
- Promise.resolve().then(() => fchownSync(fd, uid, gid)).then(() => callback(null), callback);
69
- }
70
- async function fchownAsync(fd, uid, gid) {
71
- fchownSync(fd, uid, gid);
72
- }
73
- function futimesSync(fd, atime, mtime) {
74
- utimesSync(normalizePath(getFH(fd).options.path), atime, mtime);
75
- }
76
- function futimes(fd, atime, mtime, callback) {
77
- Promise.resolve().then(() => futimesSync(fd, atime, mtime)).then(() => callback(null), callback);
78
- }
79
- async function futimesAsync(fd, atime, mtime) {
80
- futimesSync(fd, atime, mtime);
81
- }
82
- function closeSync(fd) {
83
- getFH(fd)._closeSync();
84
- }
85
- function readSync(fd, buffer, offsetOrOptions, length, position) {
86
- let offset = 0;
87
- if (offsetOrOptions !== null && typeof offsetOrOptions === "object") {
88
- offset = offsetOrOptions.offset ?? 0;
89
- length = offsetOrOptions.length ?? buffer.byteLength;
90
- position = offsetOrOptions.position ?? null;
91
- } else {
92
- offset = offsetOrOptions ?? 0;
93
- length = length ?? buffer.byteLength - offset;
94
- }
95
- return getFH(fd)._readSync(buffer, offset, length, position ?? null);
96
- }
97
- function writeSync(fd, bufferOrString, offsetOrPosition, lengthOrEncoding, position) {
98
- let data;
99
- if (typeof bufferOrString === "string") {
100
- data = new TextEncoder().encode(bufferOrString);
101
- if (typeof offsetOrPosition === "number") position = offsetOrPosition;
102
- } else {
103
- const offset = typeof offsetOrPosition === "number" ? offsetOrPosition : 0;
104
- const len = typeof lengthOrEncoding === "number" ? lengthOrEncoding : bufferOrString.byteLength - offset;
105
- data = new Uint8Array(bufferOrString.buffer, bufferOrString.byteOffset + offset, len);
106
- }
107
- return getFH(fd)._writeSync(data, position ?? null);
108
- }
109
- function readvSync(fd, buffers, position) {
110
- let bytesRead = 0;
111
- for (const buf of buffers) {
112
- const n = readSync(fd, buf, 0, buf.byteLength, position != null ? position + bytesRead : null);
113
- bytesRead += n;
114
- if (n < buf.byteLength) break;
115
- }
116
- return bytesRead;
117
- }
118
- function readv(fd, buffers, positionOrCb, callback) {
119
- if (typeof positionOrCb === "function") {
120
- callback = positionOrCb;
121
- positionOrCb = null;
122
- }
123
- Promise.resolve().then(() => ({
124
- bytesRead: readvSync(fd, buffers, positionOrCb),
125
- buffers
126
- })).then((r) => callback(null, r.bytesRead, r.buffers), callback);
127
- }
128
- async function readvAsync(fd, buffers, position) {
129
- return {
130
- bytesRead: readvSync(fd, buffers, position),
131
- buffers
132
- };
133
- }
134
- function writevSync(fd, buffers, position) {
135
- let bytesWritten = 0;
136
- for (const buf of buffers) {
137
- const n = writeSync(fd, buf, 0, buf.byteLength, position != null ? position + bytesWritten : null);
138
- bytesWritten += n;
139
- }
140
- return bytesWritten;
141
- }
142
- function writev(fd, buffers, positionOrCb, callback) {
143
- if (typeof positionOrCb === "function") {
144
- callback = positionOrCb;
145
- positionOrCb = null;
146
- }
147
- Promise.resolve().then(() => ({
148
- bytesWritten: writevSync(fd, buffers, positionOrCb),
149
- buffers
150
- })).then((r) => callback(null, r.bytesWritten, r.buffers), callback);
151
- }
152
- async function writevAsync(fd, buffers, position) {
153
- return {
154
- bytesWritten: writevSync(fd, buffers, position),
155
- buffers
156
- };
157
- }
158
- function exists(path, callback) {
159
- try {
160
- statSync(normalizePath(path));
161
- callback(true);
162
- } catch {
163
- callback(false);
164
- }
165
- }
166
- async function openAsBlob(path, options) {
167
- const data = readFileSync(normalizePath(path));
168
- return new Blob([data], { type: options?.type ?? "" });
169
- }
170
-
171
- //#endregion
172
- export { closeSync, exists, fchmod, fchmodAsync, fchmodSync, fchown, fchownAsync, fchownSync, fdatasync, fdatasyncAsync, fdatasyncSync, fstat, fstatAsync, fstatSync, fsync, fsyncAsync, fsyncSync, ftruncate, ftruncateAsync, ftruncateSync, futimes, futimesAsync, futimesSync, openAsBlob, readSync, readv, readvAsync, readvSync, writeSync, writev, writevAsync, writevSync };
1
+ import{normalizePath as e}from"./utils.js";import{FileHandle as t}from"./file-handle.js";import{chmodSync as n,chownSync as r,readFileSync as i,statSync as a,truncateSync as o}from"./sync.js";import{utimesSync as s}from"./utimes.js";function c(e){return e instanceof t?t.getInstance(e.fd):t.getInstance(e)}function l(t,n){return a(e(c(t).options.path),n)}function u(e,t,n){typeof t==`function`&&(n=t,t={}),Promise.resolve().then(()=>l(e,t)).then(e=>n(null,e),n)}async function d(e,t){return l(e,t)}function f(t,n=0){o(e(c(t).options.path),n)}function p(e,t,n){typeof t==`function`&&(n=t,t=0),Promise.resolve().then(()=>f(e,t)).then(()=>n(null),n)}async function m(e,t=0){f(e,t)}function h(e){c(e)._flushSync()}function g(e,t){Promise.resolve().then(()=>h(e)).then(()=>t(null),t)}async function _(e){h(e)}function v(e){c(e)._flushSync()}function y(e,t){Promise.resolve().then(()=>v(e)).then(()=>t(null),t)}async function b(e){v(e)}function x(t,r){n(e(c(t).options.path),r)}function S(e,t,n){Promise.resolve().then(()=>x(e,t)).then(()=>n(null),n)}async function C(e,t){x(e,t)}function w(t,n,i){r(e(c(t).options.path),n,i)}function T(e,t,n,r){Promise.resolve().then(()=>w(e,t,n)).then(()=>r(null),r)}async function E(e,t,n){w(e,t,n)}function D(t,n,r){s(e(c(t).options.path),n,r)}function O(e,t,n,r){Promise.resolve().then(()=>D(e,t,n)).then(()=>r(null),r)}async function k(e,t,n){D(e,t,n)}function A(e){c(e)._closeSync()}function j(e,t,n,r,i){let a=0;return typeof n==`object`&&n?(a=n.offset??0,r=n.length??t.byteLength,i=n.position??null):(a=n??0,r??=t.byteLength-a),c(e)._readSync(t,a,r,i??null)}function M(e,t,n,r,i){let a;if(typeof t==`string`)a=new TextEncoder().encode(t),typeof n==`number`&&(i=n);else{let e=typeof n==`number`?n:0,i=typeof r==`number`?r:t.byteLength-e;a=new Uint8Array(t.buffer,t.byteOffset+e,i)}return c(e)._writeSync(a,i??null)}function N(e,t,n){let r=0;for(let i of t){let t=j(e,i,0,i.byteLength,n==null?null:n+r);if(r+=t,t<i.byteLength)break}return r}function P(e,t,n,r){typeof n==`function`&&(r=n,n=null),Promise.resolve().then(()=>({bytesRead:N(e,t,n),buffers:t})).then(e=>r(null,e.bytesRead,e.buffers),r)}async function F(e,t,n){return{bytesRead:N(e,t,n),buffers:t}}function I(e,t,n){let r=0;for(let i of t){let t=M(e,i,0,i.byteLength,n==null?null:n+r);r+=t}return r}function L(e,t,n,r){typeof n==`function`&&(r=n,n=null),Promise.resolve().then(()=>({bytesWritten:I(e,t,n),buffers:t})).then(e=>r(null,e.bytesWritten,e.buffers),r)}async function R(e,t,n){return{bytesWritten:I(e,t,n),buffers:t}}function z(t,n){try{a(e(t)),n(!0)}catch{n(!1)}}async function B(t,n){let r=i(e(t));return new Blob([r],{type:n?.type??``})}export{A as closeSync,z as exists,S as fchmod,C as fchmodAsync,x as fchmodSync,T as fchown,E as fchownAsync,w as fchownSync,g as fdatasync,_ as fdatasyncAsync,h as fdatasyncSync,u as fstat,d as fstatAsync,l as fstatSync,y as fsync,b as fsyncAsync,v as fsyncSync,p as ftruncate,m as ftruncateAsync,f as ftruncateSync,O as futimes,k as futimesAsync,D as futimesSync,B as openAsBlob,j as readSync,P as readv,F as readvAsync,N as readvSync,M as writeSync,L as writev,R as writevAsync,I as writevSync};