@gjsify/fs 0.0.1 → 0.0.2
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/README.md +6 -8
- package/lib/cjs/callback.js +131 -0
- package/lib/cjs/dirent.js +127 -0
- package/lib/cjs/encoding.js +53 -0
- package/lib/cjs/file-handle.js +473 -0
- package/lib/cjs/fs-watcher.js +79 -0
- package/lib/cjs/index.js +95 -0
- package/lib/cjs/promises.js +189 -0
- package/lib/cjs/read-stream.js +107 -0
- package/lib/cjs/stats.js +74 -0
- package/lib/cjs/sync.js +155 -0
- package/lib/cjs/types/encoding-option.js +15 -0
- package/lib/cjs/types/file-read-options.js +15 -0
- package/lib/cjs/types/file-read-result.js +15 -0
- package/lib/cjs/types/flag-and-open-mode.js +15 -0
- package/lib/cjs/types/index.js +22 -0
- package/lib/cjs/types/open-flags.js +15 -0
- package/lib/cjs/types/read-options.js +15 -0
- package/lib/cjs/utils.js +37 -0
- package/lib/cjs/write-stream.js +135 -0
- package/lib/esm/callback.js +112 -0
- package/lib/esm/dirent.js +98 -0
- package/lib/esm/encoding.js +34 -0
- package/lib/esm/file-handle.js +444 -0
- package/lib/esm/fs-watcher.js +50 -0
- package/lib/esm/index.js +95 -0
- package/lib/esm/promises.js +160 -0
- package/lib/esm/read-stream.js +78 -0
- package/lib/esm/stats.js +45 -0
- package/lib/esm/sync.js +126 -0
- package/lib/esm/types/encoding-option.js +0 -0
- package/lib/esm/types/file-read-options.js +0 -0
- package/lib/esm/types/file-read-result.js +0 -0
- package/lib/esm/types/flag-and-open-mode.js +0 -0
- package/lib/esm/types/index.js +6 -0
- package/lib/esm/types/open-flags.js +0 -0
- package/lib/esm/types/read-options.js +0 -0
- package/lib/esm/utils.js +18 -0
- package/lib/esm/write-stream.js +116 -0
- package/package.json +52 -17
- package/src/callback.spec.ts +42 -0
- package/src/callback.ts +362 -0
- package/src/dirent.ts +117 -0
- package/src/encoding.ts +40 -0
- package/src/file-handle.spec.ts +34 -0
- package/src/file-handle.ts +606 -0
- package/{fs-watcher.js → src/fs-watcher.ts} +10 -9
- package/src/index.ts +95 -0
- package/src/promises.spec.ts +172 -0
- package/src/promises.ts +349 -0
- package/src/read-stream.ts +98 -0
- package/src/stat.spec.ts +79 -0
- package/src/stats.ts +106 -0
- package/src/symlink.spec.ts +38 -0
- package/src/sync.spec.ts +205 -0
- package/src/sync.ts +239 -0
- package/src/test.mts +11 -0
- package/src/types/encoding-option.ts +3 -0
- package/src/types/file-read-options.ts +15 -0
- package/src/types/file-read-result.ts +4 -0
- package/src/types/flag-and-open-mode.ts +6 -0
- package/src/types/index.ts +6 -0
- package/src/types/open-flags.ts +14 -0
- package/src/types/read-options.ts +9 -0
- package/src/utils.ts +19 -0
- package/src/write-stream.ts +143 -0
- package/test/file.txt +1 -0
- package/test/watch.js +1 -0
- package/test.gjs.js +35359 -0
- package/test.gjs.js.map +7 -0
- package/test.gjs.mjs +40570 -0
- package/test.gjs.mjs.meta.json +1 -0
- package/test.node.js +1479 -0
- package/test.node.js.map +7 -0
- package/test.node.mjs +710 -0
- package/tsconfig.json +18 -0
- package/tsconfig.types.json +8 -0
- package/index.js +0 -114
- package/test/index.js +0 -90
- package/test/resources/file.txt +0 -1
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var promises_exports = {};
|
|
29
|
+
__export(promises_exports, {
|
|
30
|
+
default: () => promises_default,
|
|
31
|
+
lstat: () => import_fs_lstat.lstatPromise,
|
|
32
|
+
mkdir: () => mkdir,
|
|
33
|
+
mkdtemp: () => mkdtemp,
|
|
34
|
+
open: () => open,
|
|
35
|
+
readFile: () => readFile,
|
|
36
|
+
readdir: () => import_fs_readdir.readdirPromise,
|
|
37
|
+
realpath: () => import_fs_realpath.realpathPromise,
|
|
38
|
+
rm: () => rm,
|
|
39
|
+
rmdir: () => rmdir,
|
|
40
|
+
stat: () => import_fs_stat.statPromise,
|
|
41
|
+
symlink: () => import_fs_symlink.symlinkPromise,
|
|
42
|
+
unlink: () => unlink,
|
|
43
|
+
write: () => write,
|
|
44
|
+
writeFile: () => writeFile
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(promises_exports);
|
|
47
|
+
var import_gio_2 = __toESM(require("@girs/gio-2.0"), 1);
|
|
48
|
+
var import_glib_2 = __toESM(require("@girs/glib-2.0"), 1);
|
|
49
|
+
var import_utils = require("@gjsify/utils");
|
|
50
|
+
var import_path = require("path");
|
|
51
|
+
var import_encoding = require("./encoding.js");
|
|
52
|
+
var import_sync = require("./sync.js");
|
|
53
|
+
var import_file_handle = require("./file-handle.js");
|
|
54
|
+
var import_utils2 = require("./utils.js");
|
|
55
|
+
var import_dirent = require("./dirent.js");
|
|
56
|
+
var import_fs_realpath = require("@gjsify/deno_std/node/_fs/_fs_realpath");
|
|
57
|
+
var import_fs_readdir = require("@gjsify/deno_std/node/_fs/_fs_readdir");
|
|
58
|
+
var import_fs_symlink = require("@gjsify/deno_std/node/_fs/_fs_symlink");
|
|
59
|
+
var import_fs_lstat = require("@gjsify/deno_std/node/_fs/_fs_lstat");
|
|
60
|
+
var import_fs_stat = require("@gjsify/deno_std/node/_fs/_fs_stat");
|
|
61
|
+
async function mkdir(path, options) {
|
|
62
|
+
let recursive;
|
|
63
|
+
let mode = 511;
|
|
64
|
+
if (typeof options === "object") {
|
|
65
|
+
if (options.recursive)
|
|
66
|
+
recursive = options.recursive;
|
|
67
|
+
if (options.mode)
|
|
68
|
+
mode = options.mode;
|
|
69
|
+
} else {
|
|
70
|
+
mode = options;
|
|
71
|
+
}
|
|
72
|
+
const firstPath = (0, import_sync.mkdirSync)(path, {
|
|
73
|
+
recursive,
|
|
74
|
+
mode
|
|
75
|
+
});
|
|
76
|
+
return firstPath;
|
|
77
|
+
}
|
|
78
|
+
async function readFile(path, options = { encoding: null, flag: "r" }) {
|
|
79
|
+
const file = import_gio_2.default.File.new_for_path(path.toString());
|
|
80
|
+
const [ok, data] = await new Promise((resolve, reject) => {
|
|
81
|
+
file.load_contents_async(null, (self, res) => {
|
|
82
|
+
try {
|
|
83
|
+
resolve(file.load_contents_finish(res));
|
|
84
|
+
} catch (error) {
|
|
85
|
+
reject(error);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
if (!ok) {
|
|
90
|
+
throw new Error("failed to read file");
|
|
91
|
+
}
|
|
92
|
+
return (0, import_encoding.encodeUint8Array)((0, import_encoding.getEncodingFromOptions)(options, "buffer"), data);
|
|
93
|
+
}
|
|
94
|
+
async function mkdtemp(prefix, options) {
|
|
95
|
+
const encoding = (0, import_encoding.getEncodingFromOptions)(options);
|
|
96
|
+
const path = (0, import_utils2.tempDirPath)(prefix);
|
|
97
|
+
await mkdir(
|
|
98
|
+
path,
|
|
99
|
+
{ recursive: false, mode: 448 }
|
|
100
|
+
);
|
|
101
|
+
return (0, import_encoding.decode)(path, encoding);
|
|
102
|
+
}
|
|
103
|
+
async function writeFile(path, data) {
|
|
104
|
+
return (0, import_sync.writeFileSync)(path, data);
|
|
105
|
+
}
|
|
106
|
+
async function rmdir(path, options) {
|
|
107
|
+
return (0, import_sync.rmdirSync)(path, options);
|
|
108
|
+
}
|
|
109
|
+
async function unlink(path) {
|
|
110
|
+
return (0, import_sync.unlinkSync)(path);
|
|
111
|
+
}
|
|
112
|
+
async function open(path, flags, mode) {
|
|
113
|
+
return new import_file_handle.FileHandle({
|
|
114
|
+
path,
|
|
115
|
+
flags,
|
|
116
|
+
mode
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async function write(fd, data, positionOrOffset, encodingOrLength, position) {
|
|
120
|
+
if (typeof data === "string") {
|
|
121
|
+
return _writeStr(fd, data, positionOrOffset, encodingOrLength);
|
|
122
|
+
}
|
|
123
|
+
return _writeBuf(fd, data, positionOrOffset, encodingOrLength, position);
|
|
124
|
+
}
|
|
125
|
+
async function _writeBuf(fd, buffer, offset, length, position) {
|
|
126
|
+
(0, import_utils.warnNotImplemented)("fs.promises.write");
|
|
127
|
+
return {
|
|
128
|
+
bytesWritten: 0,
|
|
129
|
+
buffer
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
async function _writeStr(fd, data, position, encoding) {
|
|
133
|
+
(0, import_utils.warnNotImplemented)("fs.promises.write");
|
|
134
|
+
return {
|
|
135
|
+
bytesWritten: 0,
|
|
136
|
+
buffer: data
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
async function rm(path, options) {
|
|
140
|
+
const file = import_gio_2.default.File.new_for_path(path.toString());
|
|
141
|
+
const recursive = options?.recursive || false;
|
|
142
|
+
const dirent = new import_dirent.Dirent(path.toString());
|
|
143
|
+
if (dirent.isDirectory()) {
|
|
144
|
+
const childFiles = await (0, import_fs_readdir.readdirPromise)(path, { withFileTypes: true });
|
|
145
|
+
if (!recursive && childFiles.length) {
|
|
146
|
+
throw new Error("Dir is not empty!");
|
|
147
|
+
}
|
|
148
|
+
for (const childFile of childFiles) {
|
|
149
|
+
if (childFile.isDirectory()) {
|
|
150
|
+
await rmdir((0, import_path.join)(path.toString(), childFile.name), options);
|
|
151
|
+
} else if (childFile.isFile()) {
|
|
152
|
+
await rm((0, import_path.join)(path.toString(), childFile.name), options);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const ok = await new Promise((resolve, reject) => {
|
|
157
|
+
try {
|
|
158
|
+
file.delete_async(import_glib_2.default.PRIORITY_DEFAULT, null, (self, res) => {
|
|
159
|
+
try {
|
|
160
|
+
resolve(file.delete_finish(res));
|
|
161
|
+
} catch (error) {
|
|
162
|
+
reject(error);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
} catch (error) {
|
|
166
|
+
reject(error);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
if (!ok) {
|
|
170
|
+
const err = new Error("failed to remove file " + path);
|
|
171
|
+
throw err;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
var promises_default = {
|
|
175
|
+
readFile,
|
|
176
|
+
mkdir,
|
|
177
|
+
mkdtemp,
|
|
178
|
+
realpath: import_fs_realpath.realpathPromise,
|
|
179
|
+
readdir: import_fs_readdir.readdirPromise,
|
|
180
|
+
writeFile,
|
|
181
|
+
rmdir,
|
|
182
|
+
unlink,
|
|
183
|
+
open,
|
|
184
|
+
write,
|
|
185
|
+
rm,
|
|
186
|
+
lstat: import_fs_lstat.lstatPromise,
|
|
187
|
+
symlink: import_fs_symlink.symlinkPromise,
|
|
188
|
+
stat: import_fs_stat.statPromise
|
|
189
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var read_stream_exports = {};
|
|
29
|
+
__export(read_stream_exports, {
|
|
30
|
+
ReadStream: () => ReadStream,
|
|
31
|
+
createReadStream: () => createReadStream,
|
|
32
|
+
fromFileUrl: () => fromFileUrl
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(read_stream_exports);
|
|
35
|
+
var import_glib_2 = __toESM(require("@girs/glib-2.0"), 1);
|
|
36
|
+
var import_utils = require("@gjsify/utils");
|
|
37
|
+
var import_buffer = require("buffer");
|
|
38
|
+
var import_stream = require("stream");
|
|
39
|
+
var import_url = require("url");
|
|
40
|
+
function fromFileUrl(url) {
|
|
41
|
+
url = url instanceof import_url.URL ? url : new import_url.URL(url);
|
|
42
|
+
if (url.protocol != "file:") {
|
|
43
|
+
throw new TypeError("Must be a file URL.");
|
|
44
|
+
}
|
|
45
|
+
return decodeURIComponent(
|
|
46
|
+
url.pathname.replace(/%(?![0-9A-Fa-f]{2})/g, "%25")
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
class ReadStream extends import_stream.Readable {
|
|
50
|
+
close(callback) {
|
|
51
|
+
callback((0, import_utils.notImplemented)("ReadStream.close"));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The number of bytes that have been read so far.
|
|
55
|
+
* @since v6.4.0
|
|
56
|
+
*/
|
|
57
|
+
bytesRead;
|
|
58
|
+
/**
|
|
59
|
+
* The path to the file the stream is reading from as specified in the first
|
|
60
|
+
* argument to `fs.createReadStream()`. If `path` is passed as a string, then`readStream.path` will be a string. If `path` is passed as a `Buffer`, then`readStream.path` will be a
|
|
61
|
+
* `Buffer`. If `fd` is specified, then`readStream.path` will be `undefined`.
|
|
62
|
+
* @since v0.1.93
|
|
63
|
+
*/
|
|
64
|
+
path;
|
|
65
|
+
/**
|
|
66
|
+
* This property is `true` if the underlying file has not been opened yet,
|
|
67
|
+
* i.e. before the `'ready'` event is emitted.
|
|
68
|
+
* @since v11.2.0, v10.16.0
|
|
69
|
+
*/
|
|
70
|
+
pending;
|
|
71
|
+
constructor(path, opts) {
|
|
72
|
+
path = path instanceof import_url.URL ? fromFileUrl(path) : path;
|
|
73
|
+
const hasBadOptions = opts && (opts.start || opts.end);
|
|
74
|
+
if (hasBadOptions) {
|
|
75
|
+
(0, import_utils.notImplemented)(
|
|
76
|
+
`fs.ReadStream.prototype.constructor with unsupported options (${JSON.stringify(opts)})`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
const file = import_glib_2.default.IOChannel.new_file(path.toString(), "r");
|
|
80
|
+
const buffer = "";
|
|
81
|
+
super({
|
|
82
|
+
autoDestroy: true,
|
|
83
|
+
emitClose: true,
|
|
84
|
+
objectMode: false,
|
|
85
|
+
read: async function(_size) {
|
|
86
|
+
try {
|
|
87
|
+
let n = 0;
|
|
88
|
+
file.read(buffer, 16 * 1024, n);
|
|
89
|
+
this.push(n ? import_buffer.Buffer.from(buffer.slice(0, n)) : null);
|
|
90
|
+
} catch (err) {
|
|
91
|
+
this.destroy(err);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
destroy: (err, cb) => {
|
|
95
|
+
try {
|
|
96
|
+
file.close();
|
|
97
|
+
} catch {
|
|
98
|
+
}
|
|
99
|
+
cb(err);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
this.path = path.toString();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function createReadStream(path, options) {
|
|
106
|
+
return new ReadStream(path, options);
|
|
107
|
+
}
|
package/lib/cjs/stats.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var stats_exports = {};
|
|
29
|
+
__export(stats_exports, {
|
|
30
|
+
Stats: () => Stats
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(stats_exports);
|
|
33
|
+
var import_gio_2 = __toESM(require("@girs/gio-2.0"), 1);
|
|
34
|
+
var import_dirent = require("./dirent.js");
|
|
35
|
+
var import_path = require("path");
|
|
36
|
+
class Stats extends import_dirent.Dirent {
|
|
37
|
+
dev;
|
|
38
|
+
ino;
|
|
39
|
+
mode;
|
|
40
|
+
nlink;
|
|
41
|
+
uid;
|
|
42
|
+
gid;
|
|
43
|
+
rdev;
|
|
44
|
+
size;
|
|
45
|
+
blksize;
|
|
46
|
+
blocks;
|
|
47
|
+
atimeMs;
|
|
48
|
+
mtimeMs;
|
|
49
|
+
ctimeMs;
|
|
50
|
+
/** The timestamp indicating the creation time of this file expressed in milliseconds since the POSIX Epoch. */
|
|
51
|
+
get birthtimeMs() {
|
|
52
|
+
const creationDateTime = this._info.get_creation_date_time();
|
|
53
|
+
return creationDateTime.get_microsecond() * 1e3;
|
|
54
|
+
}
|
|
55
|
+
atime;
|
|
56
|
+
mtime;
|
|
57
|
+
ctime;
|
|
58
|
+
/** The timestamp indicating the creation time of this file. */
|
|
59
|
+
get birthtime() {
|
|
60
|
+
const creationDateTime = this._info.get_creation_date_time();
|
|
61
|
+
return new Date(creationDateTime.format_iso8601());
|
|
62
|
+
}
|
|
63
|
+
_info;
|
|
64
|
+
constructor(path, filename) {
|
|
65
|
+
const pathStr = path.toString();
|
|
66
|
+
if (!filename)
|
|
67
|
+
filename = (0, import_path.basename)(pathStr);
|
|
68
|
+
super(pathStr, filename);
|
|
69
|
+
if (!this._file) {
|
|
70
|
+
throw new TypeError("this._file is not defined!");
|
|
71
|
+
}
|
|
72
|
+
this._info = this._file.query_info("standard::", import_gio_2.default.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
|
|
73
|
+
}
|
|
74
|
+
}
|
package/lib/cjs/sync.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var sync_exports = {};
|
|
29
|
+
__export(sync_exports, {
|
|
30
|
+
existsSync: () => import_utils.existsSync,
|
|
31
|
+
lstatSync: () => import_fs_lstat.lstatSync,
|
|
32
|
+
mkdirSync: () => mkdirSync,
|
|
33
|
+
mkdtempSync: () => mkdtempSync,
|
|
34
|
+
openSync: () => openSync,
|
|
35
|
+
readFileSync: () => readFileSync,
|
|
36
|
+
readdirSync: () => import_fs_readdir.readdirSync,
|
|
37
|
+
realpathSync: () => import_fs_realpath.realpathSync,
|
|
38
|
+
rmSync: () => rmSync,
|
|
39
|
+
rmdirSync: () => rmdirSync,
|
|
40
|
+
statSync: () => import_fs_stat.statSync,
|
|
41
|
+
symlinkSync: () => import_fs_symlink.symlinkSync,
|
|
42
|
+
unlinkSync: () => unlinkSync,
|
|
43
|
+
watch: () => watch,
|
|
44
|
+
writeFileSync: () => writeFileSync
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(sync_exports);
|
|
47
|
+
var import_glib_2 = __toESM(require("@girs/glib-2.0"), 1);
|
|
48
|
+
var import_gio_2 = __toESM(require("@girs/gio-2.0"), 1);
|
|
49
|
+
var import_utils = require("@gjsify/utils");
|
|
50
|
+
var import_path = require("path");
|
|
51
|
+
var import_fs_watcher = __toESM(require("./fs-watcher.js"), 1);
|
|
52
|
+
var import_encoding = require("./encoding.js");
|
|
53
|
+
var import_file_handle = require("./file-handle.js");
|
|
54
|
+
var import_dirent = require("./dirent.js");
|
|
55
|
+
var import_utils2 = require("./utils.js");
|
|
56
|
+
var import_fs_realpath = require("@gjsify/deno_std/node/_fs/_fs_realpath");
|
|
57
|
+
var import_fs_readdir = require("@gjsify/deno_std/node/_fs/_fs_readdir");
|
|
58
|
+
var import_fs_symlink = require("@gjsify/deno_std/node/_fs/_fs_symlink");
|
|
59
|
+
var import_fs_lstat = require("@gjsify/deno_std/node/_fs/_fs_lstat");
|
|
60
|
+
var import_fs_stat = require("@gjsify/deno_std/node/_fs/_fs_stat");
|
|
61
|
+
function readFileSync(path, options = { encoding: null, flag: "r" }) {
|
|
62
|
+
const file = import_gio_2.default.File.new_for_path(path);
|
|
63
|
+
const [ok, data] = file.load_contents(null);
|
|
64
|
+
if (!ok) {
|
|
65
|
+
throw new Error("failed to read file");
|
|
66
|
+
}
|
|
67
|
+
return (0, import_encoding.encodeUint8Array)((0, import_encoding.getEncodingFromOptions)(options, "buffer"), data);
|
|
68
|
+
}
|
|
69
|
+
function mkdirSync(path, options) {
|
|
70
|
+
let recursive = false;
|
|
71
|
+
let mode = 511;
|
|
72
|
+
if (typeof options === "object") {
|
|
73
|
+
if (options?.recursive)
|
|
74
|
+
recursive = options.recursive;
|
|
75
|
+
if (options?.mode)
|
|
76
|
+
mode = options.mode;
|
|
77
|
+
} else {
|
|
78
|
+
mode = options || 511;
|
|
79
|
+
}
|
|
80
|
+
if (typeof path !== "string") {
|
|
81
|
+
path = path.toString();
|
|
82
|
+
}
|
|
83
|
+
if (typeof mode === "string") {
|
|
84
|
+
throw new TypeError("mode as string is currently not supported!");
|
|
85
|
+
}
|
|
86
|
+
if (import_glib_2.default.mkdir_with_parents(path, mode) !== 0) {
|
|
87
|
+
throw new Error(`failed to make ${path} directory`);
|
|
88
|
+
}
|
|
89
|
+
if (recursive) {
|
|
90
|
+
return path.split("/")[0];
|
|
91
|
+
}
|
|
92
|
+
return void 0;
|
|
93
|
+
}
|
|
94
|
+
function rmdirSync(path, options) {
|
|
95
|
+
const recursive = options?.recursive || false;
|
|
96
|
+
const childFiles = (0, import_fs_readdir.readdirSync)(path, { withFileTypes: true });
|
|
97
|
+
if (!recursive && childFiles.length) {
|
|
98
|
+
throw new Error("Dir is not empty!");
|
|
99
|
+
}
|
|
100
|
+
for (const childFile of childFiles) {
|
|
101
|
+
if (childFile.isDirectory()) {
|
|
102
|
+
rmdirSync((0, import_path.join)(path.toString(), childFile.name));
|
|
103
|
+
} else if (childFile.isFile()) {
|
|
104
|
+
rmSync((0, import_path.join)(path.toString(), childFile.name));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const result = import_glib_2.default.rmdir(path.toString());
|
|
108
|
+
if (result !== 0) {
|
|
109
|
+
throw new Error(`Failed to remove ${path} directory`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function unlinkSync(path) {
|
|
113
|
+
import_glib_2.default.unlink(path);
|
|
114
|
+
}
|
|
115
|
+
function writeFileSync(path, data) {
|
|
116
|
+
import_glib_2.default.file_set_contents(path, data);
|
|
117
|
+
}
|
|
118
|
+
function watch(filename, options, listener) {
|
|
119
|
+
return new import_fs_watcher.default(filename, options, listener);
|
|
120
|
+
}
|
|
121
|
+
function openSync(path, flags, mode) {
|
|
122
|
+
return new import_file_handle.FileHandle({ path, flags, mode });
|
|
123
|
+
}
|
|
124
|
+
function mkdtempSync(prefix, options) {
|
|
125
|
+
const encoding = (0, import_encoding.getEncodingFromOptions)(options);
|
|
126
|
+
const path = (0, import_utils2.tempDirPath)(prefix);
|
|
127
|
+
mkdirSync(
|
|
128
|
+
path,
|
|
129
|
+
{ recursive: false, mode: 511 }
|
|
130
|
+
);
|
|
131
|
+
return (0, import_encoding.decode)(path, encoding);
|
|
132
|
+
}
|
|
133
|
+
function rmSync(path, options) {
|
|
134
|
+
const file = import_gio_2.default.File.new_for_path(path.toString());
|
|
135
|
+
const recursive = options?.recursive || false;
|
|
136
|
+
const dirent = new import_dirent.Dirent(path.toString());
|
|
137
|
+
if (dirent.isDirectory()) {
|
|
138
|
+
const childFiles = (0, import_fs_readdir.readdirSync)(path, { withFileTypes: true });
|
|
139
|
+
if (!recursive && childFiles.length) {
|
|
140
|
+
throw new Error("Dir is not empty!");
|
|
141
|
+
}
|
|
142
|
+
for (const childFile of childFiles) {
|
|
143
|
+
if (childFile.isDirectory()) {
|
|
144
|
+
rmdirSync((0, import_path.join)(path.toString(), childFile.name), options);
|
|
145
|
+
} else if (childFile.isFile()) {
|
|
146
|
+
rmSync((0, import_path.join)(path.toString(), childFile.name), options);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const ok = file.delete(null);
|
|
151
|
+
if (!ok) {
|
|
152
|
+
const err = new Error("failed to remove file " + path);
|
|
153
|
+
throw err;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var encoding_option_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(encoding_option_exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var file_read_options_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(file_read_options_exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var file_read_result_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(file_read_result_exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var flag_and_open_mode_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(flag_and_open_mode_exports);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
17
|
+
__reExport(types_exports, require("./encoding-option.js"), module.exports);
|
|
18
|
+
__reExport(types_exports, require("./file-read-options.js"), module.exports);
|
|
19
|
+
__reExport(types_exports, require("./file-read-result.js"), module.exports);
|
|
20
|
+
__reExport(types_exports, require("./flag-and-open-mode.js"), module.exports);
|
|
21
|
+
__reExport(types_exports, require("./open-flags.js"), module.exports);
|
|
22
|
+
__reExport(types_exports, require("./read-options.js"), module.exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var open_flags_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(open_flags_exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var read_options_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(read_options_exports);
|