core-3nweb-client-lib 0.44.6 → 0.44.8
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/build/api-defs/files.d.ts +1 -0
- package/build/api-defs/web3n.d.ts +2 -1
- package/build/core/asmail/inbox/inbox-events.d.ts +0 -1
- package/build/core/asmail/inbox/inbox-events.js +3 -5
- package/build/core/asmail/inbox/index.js +1 -1
- package/build/core/asmail/inbox/msg-downloader.d.ts +1 -2
- package/build/core/asmail/inbox/msg-downloader.js +3 -4
- package/build/core/storage/synced/obj-files.js +1 -1
- package/build/core/storage/synced/obj-status.d.ts +2 -0
- package/build/core/storage/synced/obj-status.js +9 -5
- package/build/core/storage/synced/remote-events.d.ts +0 -1
- package/build/core/storage/synced/remote-events.js +5 -7
- package/build/core/storage/synced/storage.js +2 -2
- package/build/core/storage/synced/upsyncer.d.ts +1 -2
- package/build/core/storage/synced/upsyncer.js +49 -25
- package/build/lib-client/3nstorage/storage-owner.js +1 -1
- package/build/lib-client/asmail/recipient.js +8 -4
- package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
- package/build/lib-client/cryptor/cryptor.wasm +0 -0
- package/build/lib-client/cryptor/worker-js.js +4 -2
- package/build/lib-client/local-files/dev-file-sink.js +30 -28
- package/build/lib-client/local-files/dev-file-src.js +7 -6
- package/build/lib-client/local-files/device-fs.js +23 -23
- package/build/lib-client/objs-on-disk/obj-folders.js +6 -3
- package/build/lib-client/request-utils.d.ts +2 -1
- package/build/lib-client/request-utils.js +8 -19
- package/build/lib-client/user-with-mid-session.d.ts +2 -0
- package/build/lib-client/user-with-mid-session.js +33 -22
- package/build/lib-client/xsp-fs/attrs.js +4 -2
- package/build/lib-client/xsp-fs/exceptions.js +5 -2
- package/build/lib-client/xsp-fs/folder-node-serialization.js +4 -2
- package/build/lib-client/xsp-fs/node-in-fs.js +2 -5
- package/build/lib-common/async-fs-node.d.ts +30 -46
- package/build/lib-common/async-fs-node.js +71 -309
- package/build/lib-common/awaitable-state.js +3 -1
- package/build/lib-common/exceptions/file.d.ts +1 -1
- package/build/lib-common/exceptions/file.js +11 -6
- package/build/lib-common/exceptions/runtime.d.ts +7 -1
- package/build/lib-common/exceptions/runtime.js +16 -2
- package/build/lib-common/objs-on-disk/obj-version-file.d.ts +1 -1
- package/build/lib-common/objs-on-disk/obj-version-file.js +35 -33
- package/build/lib-index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2019, 2021 - 2022 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2015 - 2019, 2021 - 2022, 2026 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -16,24 +16,7 @@
|
|
|
16
16
|
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.
|
|
20
|
-
exports.readFile = readFile;
|
|
21
|
-
exports.writeFile = writeFile;
|
|
22
|
-
exports.appendFile = appendFile;
|
|
23
|
-
exports.mkdir = mkdir;
|
|
24
|
-
exports.open = open;
|
|
25
|
-
exports.close = close;
|
|
26
|
-
exports.symlink = symlink;
|
|
27
|
-
exports.readlink = readlink;
|
|
28
|
-
exports.lstat = lstat;
|
|
29
|
-
exports.stat = stat;
|
|
30
|
-
exports.fstat = fstat;
|
|
31
|
-
exports.readdir = readdir;
|
|
32
|
-
exports.rmdir = rmdir;
|
|
33
|
-
exports.unlink = unlink;
|
|
34
|
-
exports.rename = rename;
|
|
35
|
-
exports.truncate = truncate;
|
|
36
|
-
exports.ftruncate = ftruncate;
|
|
19
|
+
exports.truncate = exports.rename = exports.unlink = exports.rmdir = exports.readdir = exports.stat = exports.lstat = exports.readlink = exports.symlink = exports.open = exports.mkdir = exports.appendFile = exports.writeFile = exports.readFile = void 0;
|
|
37
20
|
exports.readToBuf = readToBuf;
|
|
38
21
|
exports.writeFromBuf = writeFromBuf;
|
|
39
22
|
exports.createEmptyFile = createEmptyFile;
|
|
@@ -59,254 +42,31 @@ const deferred_1 = require("./processes/deferred");
|
|
|
59
42
|
const bytes_fifo_buffer_1 = require("./byte-streaming/bytes-fifo-buffer");
|
|
60
43
|
const buffer_utils_1 = require("./buffer-utils");
|
|
61
44
|
const path_1 = require("path");
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
function makeFileExceptionFromNodes(nodeExc) {
|
|
65
|
-
return (0, file_1.makeFileExceptionFromCode)(nodeExc.code, nodeExc.path);
|
|
45
|
+
function makeFileExceptionFromNodesAndThrow(nodeExc) {
|
|
46
|
+
throw (0, file_1.makeFileExceptionFromCode)(nodeExc.code, nodeExc.path, undefined, 1);
|
|
66
47
|
}
|
|
67
|
-
function
|
|
68
|
-
return
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
reject(makeFileExceptionFromNodes(err));
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
resolve(data);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
if (options) {
|
|
78
|
-
fs.readFile(path, options, cb);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
fs.readFile(path, cb);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
function writeFile(path, data, options = {}) {
|
|
86
|
-
return new Promise((resolve, reject) => {
|
|
87
|
-
fs.writeFile(path, data, options, err => {
|
|
88
|
-
if (err) {
|
|
89
|
-
reject(makeFileExceptionFromNodes(err));
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
resolve();
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
function appendFile(path, data, options = {}) {
|
|
98
|
-
return new Promise((resolve, reject) => {
|
|
99
|
-
fs.appendFile(path, data, options, err => {
|
|
100
|
-
if (err) {
|
|
101
|
-
reject(makeFileExceptionFromNodes(err));
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
resolve();
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
function mkdir(path, options) {
|
|
110
|
-
return new Promise((resolve, reject) => {
|
|
111
|
-
fs.mkdir(path, options, (err) => {
|
|
112
|
-
if (err) {
|
|
113
|
-
reject(makeFileExceptionFromNodes(err));
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
resolve();
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
function open(path, flags) {
|
|
122
|
-
return new Promise((resolve, reject) => {
|
|
123
|
-
fs.open(path, flags, (err, df) => {
|
|
124
|
-
if (err) {
|
|
125
|
-
reject(makeFileExceptionFromNodes(err));
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
resolve(df);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
function writeOrig(fd, buffer, offset, length, position) {
|
|
134
|
-
return new Promise((resolve, reject) => {
|
|
135
|
-
const cb = (err, written) => {
|
|
136
|
-
if (err) {
|
|
137
|
-
reject(makeFileExceptionFromNodes(err));
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
resolve(written);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
if (typeof position === 'number') {
|
|
144
|
-
fs.write(fd, buffer, offset, length, position, cb);
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
fs.write(fd, buffer, offset, length, cb);
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
function readOrig(fd, buffer, offset, length, position) {
|
|
152
|
-
return new Promise((resolve, reject) => {
|
|
153
|
-
fs.read(fd, buffer, offset, length, position, (err, bytesRead) => {
|
|
154
|
-
if (err) {
|
|
155
|
-
reject(makeFileExceptionFromNodes(err));
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
resolve(bytesRead);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
function close(fd) {
|
|
164
|
-
return new Promise((resolve, reject) => {
|
|
165
|
-
fs.close(fd, (err) => {
|
|
166
|
-
if (err) {
|
|
167
|
-
reject(makeFileExceptionFromNodes(err));
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
resolve();
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
function symlink(target, path, type) {
|
|
176
|
-
return new Promise((resolve, reject) => {
|
|
177
|
-
fs.symlink(target, path, type, (err) => {
|
|
178
|
-
if (err) {
|
|
179
|
-
reject(makeFileExceptionFromNodes(err));
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
resolve();
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
function readlink(path) {
|
|
188
|
-
return new Promise((resolve, reject) => {
|
|
189
|
-
fs.readlink(path, (err, targetPath) => {
|
|
190
|
-
if (err) {
|
|
191
|
-
reject(makeFileExceptionFromNodes(err));
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
resolve(targetPath);
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
function lstat(path) {
|
|
200
|
-
return new Promise((resolve, reject) => {
|
|
201
|
-
fs.lstat(path, (err, stat) => {
|
|
202
|
-
if (err) {
|
|
203
|
-
reject(makeFileExceptionFromNodes(err));
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
resolve(stat);
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
function stat(path) {
|
|
212
|
-
return new Promise((resolve, reject) => {
|
|
213
|
-
fs.stat(path, (err, stat) => {
|
|
214
|
-
if (err) {
|
|
215
|
-
reject(makeFileExceptionFromNodes(err));
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
resolve(stat);
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
function fstat(fd) {
|
|
224
|
-
return new Promise((resolve, reject) => {
|
|
225
|
-
// from some moment, typing of fs.fstat is broken
|
|
226
|
-
fs.fstat(fd, (err, stat) => {
|
|
227
|
-
if (err) {
|
|
228
|
-
reject(makeFileExceptionFromNodes(err));
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
resolve(stat);
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
function readdir(path) {
|
|
237
|
-
return new Promise((resolve, reject) => {
|
|
238
|
-
fs.readdir(path, (err, list) => {
|
|
239
|
-
if (err) {
|
|
240
|
-
reject(makeFileExceptionFromNodes(err));
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
resolve(list);
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
function rmdir(path) {
|
|
249
|
-
return new Promise((resolve, reject) => {
|
|
250
|
-
fs.rmdir(path, (err) => {
|
|
251
|
-
if (err) {
|
|
252
|
-
reject(makeFileExceptionFromNodes(err));
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
resolve();
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
function unlink(path) {
|
|
261
|
-
return new Promise((resolve, reject) => {
|
|
262
|
-
fs.unlink(path, (err) => {
|
|
263
|
-
if (err) {
|
|
264
|
-
reject(makeFileExceptionFromNodes(err));
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
resolve();
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
function rename(oldPath, newPath) {
|
|
273
|
-
return new Promise((resolve, reject) => {
|
|
274
|
-
fs.rename(oldPath, newPath, (err) => {
|
|
275
|
-
if (err) {
|
|
276
|
-
reject(makeFileExceptionFromNodes(err));
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
resolve();
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
function truncate(path, size) {
|
|
285
|
-
return new Promise((resolve, reject) => {
|
|
286
|
-
fs.truncate(path, size, (err) => {
|
|
287
|
-
if (err) {
|
|
288
|
-
reject(makeFileExceptionFromNodes(err));
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
resolve();
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
function ftruncate(fd, size) {
|
|
297
|
-
return new Promise((resolve, reject) => {
|
|
298
|
-
fs.ftruncate(fd, size, (err) => {
|
|
299
|
-
if (err) {
|
|
300
|
-
reject(makeFileExceptionFromNodes(err));
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
resolve();
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
});
|
|
48
|
+
function wrapNodeFn(nodePromisingFn) {
|
|
49
|
+
return function wrapOfNodePromisingFn(...args) {
|
|
50
|
+
return nodePromisingFn.call(undefined, ...args).catch(makeFileExceptionFromNodesAndThrow);
|
|
51
|
+
};
|
|
307
52
|
}
|
|
53
|
+
function noop() { }
|
|
54
|
+
exports.readFile = wrapNodeFn(fs.promises.readFile);
|
|
55
|
+
exports.writeFile = wrapNodeFn(fs.promises.writeFile);
|
|
56
|
+
exports.appendFile = wrapNodeFn(fs.promises.appendFile);
|
|
57
|
+
exports.mkdir = wrapNodeFn(fs.promises.mkdir);
|
|
58
|
+
exports.open = wrapNodeFn(fs.promises.open);
|
|
59
|
+
exports.symlink = wrapNodeFn(fs.promises.symlink);
|
|
60
|
+
exports.readlink = wrapNodeFn(fs.promises.readlink);
|
|
61
|
+
exports.lstat = wrapNodeFn(fs.promises.lstat);
|
|
62
|
+
exports.stat = wrapNodeFn(fs.promises.stat);
|
|
63
|
+
exports.readdir = wrapNodeFn(fs.promises.readdir);
|
|
64
|
+
exports.rmdir = wrapNodeFn(fs.promises.rmdir);
|
|
65
|
+
exports.unlink = wrapNodeFn(fs.promises.unlink);
|
|
66
|
+
exports.rename = wrapNodeFn(fs.promises.rename);
|
|
67
|
+
exports.truncate = wrapNodeFn(fs.promises.truncate);
|
|
308
68
|
/**
|
|
309
|
-
* @param
|
|
69
|
+
* @param fh is an open file handle
|
|
310
70
|
* @param pos is a position in the file, from which reading should start
|
|
311
71
|
* @param buf is a buffer, into which bytes should be read from start to
|
|
312
72
|
* the end, i.e. number of bytes that must be read is equal to the buffer's
|
|
@@ -316,13 +76,13 @@ function ftruncate(fd, size) {
|
|
|
316
76
|
* The promise fails, if an end of file is encountered before entire buffer is
|
|
317
77
|
* filled up with bytes.
|
|
318
78
|
*/
|
|
319
|
-
async function readToBuf(
|
|
79
|
+
async function readToBuf(fh, pos, buf) {
|
|
320
80
|
if ((typeof pos !== 'number') || (pos < 0)) {
|
|
321
|
-
throw new
|
|
81
|
+
throw new RangeError('Illegal file position given: ' + pos);
|
|
322
82
|
}
|
|
323
83
|
let bytesRead = 0;
|
|
324
84
|
while (bytesRead < buf.length) {
|
|
325
|
-
const bNum = await
|
|
85
|
+
const { bytesRead: bNum } = await fh.read(buf, bytesRead, buf.length - bytesRead, pos);
|
|
326
86
|
if (bNum === 0) {
|
|
327
87
|
throw (0, file_1.makeFileException)('endOfFile', '<file descriptor>');
|
|
328
88
|
}
|
|
@@ -331,18 +91,18 @@ async function readToBuf(fd, pos, buf) {
|
|
|
331
91
|
}
|
|
332
92
|
}
|
|
333
93
|
/**
|
|
334
|
-
* @param
|
|
94
|
+
* @param fh is an open file handle
|
|
335
95
|
* @param pos is a position in the file, from which writing should start
|
|
336
96
|
* @param buf is a buffer, from which all bytes should be written into the file.
|
|
337
97
|
* @returns a promise, resolvable when all bytes were written to the file.
|
|
338
98
|
*/
|
|
339
|
-
async function writeFromBuf(
|
|
99
|
+
async function writeFromBuf(fh, pos, buf) {
|
|
340
100
|
if ((typeof pos !== 'number') || (pos < 0)) {
|
|
341
101
|
throw new Error('Illegal file position given: ' + pos);
|
|
342
102
|
}
|
|
343
103
|
let bytesWritten = 0;
|
|
344
104
|
while (bytesWritten < buf.length) {
|
|
345
|
-
const bNum = await
|
|
105
|
+
const { bytesWritten: bNum } = await fh.write(buf, bytesWritten, buf.length - bytesWritten, pos);
|
|
346
106
|
bytesWritten += bNum;
|
|
347
107
|
pos += bNum;
|
|
348
108
|
}
|
|
@@ -356,27 +116,28 @@ SINGLE_BYTE_BUF[0] = 0;
|
|
|
356
116
|
* @param fileSize
|
|
357
117
|
* @param keepFileOpen
|
|
358
118
|
* @returns a promise, resolvable, when a new empty file has been created.
|
|
359
|
-
* When keep open flag was passed, live
|
|
119
|
+
* When keep open flag was passed, live file handle is returned,
|
|
360
120
|
* else return value is undefined and should be ignored.
|
|
361
121
|
*/
|
|
362
122
|
async function createEmptyFile(filePath, fileSize, keepFileOpen) {
|
|
363
123
|
if ((typeof fileSize !== 'number') || (fileSize < 0)) {
|
|
364
|
-
throw new
|
|
124
|
+
throw new RangeError('Illegal file size given: ' + fileSize);
|
|
365
125
|
}
|
|
366
126
|
let fileDescr;
|
|
367
127
|
try {
|
|
368
|
-
fileDescr = await open(filePath, 'wx');
|
|
128
|
+
fileDescr = await (0, exports.open)(filePath, 'wx');
|
|
129
|
+
fileDescr.close();
|
|
369
130
|
if (fileSize > 0) {
|
|
370
|
-
await
|
|
131
|
+
await fileDescr.write(SINGLE_BYTE_BUF, 0, 1, fileSize - 1);
|
|
371
132
|
}
|
|
372
133
|
if (keepFileOpen) {
|
|
373
134
|
return fileDescr;
|
|
374
135
|
}
|
|
375
|
-
await close(
|
|
136
|
+
await fileDescr.close();
|
|
376
137
|
}
|
|
377
138
|
catch (exc) {
|
|
378
139
|
if (fileDescr) {
|
|
379
|
-
close(
|
|
140
|
+
fileDescr.close().catch(noop);
|
|
380
141
|
}
|
|
381
142
|
throw exc;
|
|
382
143
|
}
|
|
@@ -388,7 +149,7 @@ async function createEmptyFile(filePath, fileSize, keepFileOpen) {
|
|
|
388
149
|
*/
|
|
389
150
|
async function existsFolder(path) {
|
|
390
151
|
try {
|
|
391
|
-
const stats = await stat(path);
|
|
152
|
+
const stats = await (0, exports.stat)(path);
|
|
392
153
|
if (stats.isDirectory()) {
|
|
393
154
|
return true;
|
|
394
155
|
}
|
|
@@ -448,7 +209,7 @@ function existsFileSync(path) {
|
|
|
448
209
|
* @return a promise, resolvable to file's size.
|
|
449
210
|
*/
|
|
450
211
|
async function getFileSize(filePath) {
|
|
451
|
-
const st = await stat(filePath);
|
|
212
|
+
const st = await (0, exports.stat)(filePath);
|
|
452
213
|
return st.size;
|
|
453
214
|
}
|
|
454
215
|
/**
|
|
@@ -457,11 +218,11 @@ async function getFileSize(filePath) {
|
|
|
457
218
|
* @param folderPath
|
|
458
219
|
*/
|
|
459
220
|
async function getFolderContentSize(folderPath) {
|
|
460
|
-
const list = await readdir(folderPath);
|
|
221
|
+
const list = await (0, exports.readdir)(folderPath);
|
|
461
222
|
let size = 0;
|
|
462
223
|
for (const childName of list) {
|
|
463
224
|
const childPath = `${folderPath}/${childName}`;
|
|
464
|
-
const childStats = await stat(childPath);
|
|
225
|
+
const childStats = await (0, exports.stat)(childPath);
|
|
465
226
|
if (childStats.isFile()) {
|
|
466
227
|
size += childStats.size;
|
|
467
228
|
}
|
|
@@ -472,31 +233,32 @@ async function getFolderContentSize(folderPath) {
|
|
|
472
233
|
return size;
|
|
473
234
|
}
|
|
474
235
|
/**
|
|
475
|
-
* @param
|
|
236
|
+
* @param fh is an open file handle
|
|
476
237
|
* @param pos is a position in the file, from which writing should start
|
|
477
238
|
* @param buf is a buffer, from which all bytes should be written into the file.
|
|
478
239
|
* @returns a promise, resolvable when all bytes were written to it.
|
|
479
240
|
*/
|
|
480
|
-
async function write(
|
|
241
|
+
async function write(fh, pos, buf) {
|
|
481
242
|
if ((typeof pos !== 'number') || (pos < 0)) {
|
|
482
|
-
throw new
|
|
243
|
+
throw new RangeError('Illegal file position given: ' + pos);
|
|
483
244
|
}
|
|
484
245
|
let bytesWritten = 0;
|
|
485
246
|
while (bytesWritten < buf.length) {
|
|
486
|
-
const bNum = await
|
|
247
|
+
const { bytesWritten: bNum } = await fh.write(buf, bytesWritten, buf.length - bytesWritten, pos);
|
|
487
248
|
bytesWritten += bNum;
|
|
488
249
|
pos += bNum;
|
|
489
250
|
}
|
|
251
|
+
await fh.sync();
|
|
490
252
|
}
|
|
491
253
|
/**
|
|
492
|
-
* @param
|
|
254
|
+
* @param fh is an open file handle in append mode.
|
|
493
255
|
* @param buf is a buffer, from which all bytes should be written into the file.
|
|
494
256
|
* @returns a promise, resolvable when all bytes were written to it.
|
|
495
257
|
*/
|
|
496
|
-
async function append(
|
|
258
|
+
async function append(fh, buf) {
|
|
497
259
|
let bytesWritten = 0;
|
|
498
260
|
while (bytesWritten < buf.length) {
|
|
499
|
-
const bNum = await
|
|
261
|
+
const { bytesWritten: bNum } = await fh.write(buf, bytesWritten, buf.length - bytesWritten);
|
|
500
262
|
bytesWritten += bNum;
|
|
501
263
|
}
|
|
502
264
|
}
|
|
@@ -507,12 +269,12 @@ async function append(fd, buf) {
|
|
|
507
269
|
* @returns a promise, resolvable when all bytes were written to it.
|
|
508
270
|
*/
|
|
509
271
|
async function writeToExistingFile(filePath, pos, buf) {
|
|
510
|
-
const
|
|
272
|
+
const fh = await (0, exports.open)(filePath, 'r+');
|
|
511
273
|
try {
|
|
512
|
-
await write(
|
|
274
|
+
await write(fh, pos, buf);
|
|
513
275
|
}
|
|
514
276
|
finally {
|
|
515
|
-
await close(
|
|
277
|
+
await fh.close();
|
|
516
278
|
}
|
|
517
279
|
}
|
|
518
280
|
/**
|
|
@@ -527,10 +289,10 @@ async function writeToExistingFile(filePath, pos, buf) {
|
|
|
527
289
|
*/
|
|
528
290
|
async function streamToExistingFile(filePath, pos, len, src, bufSize) {
|
|
529
291
|
if ((typeof pos !== 'number') || (pos < 0)) {
|
|
530
|
-
throw new
|
|
292
|
+
throw new RangeError('Illegal file position given: ' + pos);
|
|
531
293
|
}
|
|
532
294
|
if ((typeof len !== 'number') || (len < 1)) {
|
|
533
|
-
throw new
|
|
295
|
+
throw new RangeError('Illegal length given: ' + len);
|
|
534
296
|
}
|
|
535
297
|
if ((typeof bufSize !== 'number') || (bufSize < 1024)) {
|
|
536
298
|
throw new Error('Illegal buffer size given: ' + bufSize);
|
|
@@ -602,7 +364,7 @@ async function streamToExistingFile(filePath, pos, len, src, bufSize) {
|
|
|
602
364
|
return deferred.promise;
|
|
603
365
|
}
|
|
604
366
|
/**
|
|
605
|
-
* @param
|
|
367
|
+
* @param fh is an open file handle
|
|
606
368
|
* @param pos is a position in the file, from which reading should start
|
|
607
369
|
* @param buf is a buffer, into which bytes should be read from start to
|
|
608
370
|
* the end, i.e. number of bytes that must be read is equal to the buffer's
|
|
@@ -612,13 +374,13 @@ async function streamToExistingFile(filePath, pos, len, src, bufSize) {
|
|
|
612
374
|
* The promise fails, if an end of file is encountered before entire buffer is
|
|
613
375
|
* filled up with bytes.
|
|
614
376
|
*/
|
|
615
|
-
async function read(
|
|
377
|
+
async function read(fh, pos, buf) {
|
|
616
378
|
if ((typeof pos !== 'number') || (pos < 0)) {
|
|
617
|
-
throw new
|
|
379
|
+
throw new RangeError('Illegal file position given: ' + pos);
|
|
618
380
|
}
|
|
619
381
|
let bytesRead = 0;
|
|
620
382
|
while (bytesRead < buf.length) {
|
|
621
|
-
const bNum = await
|
|
383
|
+
const { bytesRead: bNum } = await fh.read(buf, bytesRead, buf.length - bytesRead, pos);
|
|
622
384
|
if (bNum === 0) {
|
|
623
385
|
throw (0, file_1.makeFileException)('endOfFile', '<file descriptor>');
|
|
624
386
|
}
|
|
@@ -638,12 +400,12 @@ async function read(fd, pos, buf) {
|
|
|
638
400
|
* filled up with bytes.
|
|
639
401
|
*/
|
|
640
402
|
async function readFromFile(filePath, pos, buf) {
|
|
641
|
-
const
|
|
403
|
+
const fh = await (0, exports.open)(filePath, 'r');
|
|
642
404
|
try {
|
|
643
|
-
return read(
|
|
405
|
+
return read(fh, pos, buf);
|
|
644
406
|
}
|
|
645
407
|
finally {
|
|
646
|
-
return close(
|
|
408
|
+
return fh.close();
|
|
647
409
|
}
|
|
648
410
|
}
|
|
649
411
|
/**
|
|
@@ -652,27 +414,27 @@ async function readFromFile(filePath, pos, buf) {
|
|
|
652
414
|
* @returns a promise, resolvable, when a folder has been recursively removed.
|
|
653
415
|
*/
|
|
654
416
|
async function rmDirWithContent(folder) {
|
|
655
|
-
const files = await readdir(folder);
|
|
417
|
+
const files = await (0, exports.readdir)(folder);
|
|
656
418
|
if (files.length === 0) {
|
|
657
|
-
await rmdir(folder);
|
|
419
|
+
await (0, exports.rmdir)(folder);
|
|
658
420
|
return;
|
|
659
421
|
}
|
|
660
422
|
const rmTasks = [];
|
|
661
423
|
for (const name of files) {
|
|
662
424
|
const innerPath = `${folder}/${name}`;
|
|
663
|
-
const task = lstat(innerPath)
|
|
425
|
+
const task = (0, exports.lstat)(innerPath)
|
|
664
426
|
.then((st) => {
|
|
665
427
|
if (st.isDirectory()) {
|
|
666
428
|
return rmDirWithContent(innerPath);
|
|
667
429
|
}
|
|
668
430
|
else {
|
|
669
|
-
return unlink(innerPath);
|
|
431
|
+
return (0, exports.unlink)(innerPath);
|
|
670
432
|
}
|
|
671
433
|
});
|
|
672
434
|
rmTasks.push(task);
|
|
673
435
|
}
|
|
674
436
|
await Promise.all(rmTasks);
|
|
675
|
-
await rmdir(folder);
|
|
437
|
+
await (0, exports.rmdir)(folder);
|
|
676
438
|
}
|
|
677
439
|
/**
|
|
678
440
|
* @param w is a writable stream
|
|
@@ -765,19 +527,19 @@ function copyFile(src, dst, overwrite = false, dstMode = '660') {
|
|
|
765
527
|
*/
|
|
766
528
|
async function copyTree(src, dst, fileOverwrite = false) {
|
|
767
529
|
// destination folder, non-exclusively
|
|
768
|
-
await mkdir(dst, { recursive: true })
|
|
530
|
+
await (0, exports.mkdir)(dst, { recursive: true })
|
|
769
531
|
.catch(async (exc) => {
|
|
770
532
|
if (!exc.alreadyExists) {
|
|
771
533
|
throw exc;
|
|
772
534
|
}
|
|
773
535
|
});
|
|
774
536
|
// copy files and folders from src folder
|
|
775
|
-
const srcFNames = await readdir(src);
|
|
537
|
+
const srcFNames = await (0, exports.readdir)(src);
|
|
776
538
|
const cpTasks = [];
|
|
777
539
|
for (const fName of srcFNames) {
|
|
778
540
|
const srcPath = (0, path_1.join)(src, fName);
|
|
779
541
|
const dstPath = (0, path_1.join)(dst, fName);
|
|
780
|
-
const task = stat(srcPath)
|
|
542
|
+
const task = (0, exports.stat)(srcPath)
|
|
781
543
|
.then((stats) => {
|
|
782
544
|
if (stats.isFile()) {
|
|
783
545
|
return copyFile(srcPath, dstPath, fileOverwrite);
|
|
@@ -797,11 +559,11 @@ async function copyTree(src, dst, fileOverwrite = false) {
|
|
|
797
559
|
* @param path is a folder path
|
|
798
560
|
*/
|
|
799
561
|
async function ensureFolderExists(path) {
|
|
800
|
-
await stat(path).catch(async (exc) => {
|
|
562
|
+
await (0, exports.stat)(path).catch(async (exc) => {
|
|
801
563
|
if (!exc.notFound) {
|
|
802
564
|
throw exc;
|
|
803
565
|
}
|
|
804
|
-
await mkdir(path, { recursive: true })
|
|
566
|
+
await (0, exports.mkdir)(path, { recursive: true })
|
|
805
567
|
.catch(async (exc) => {
|
|
806
568
|
if (!exc.alreadyExists) {
|
|
807
569
|
throw exc;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C)
|
|
3
|
+
Copyright (C) 2026 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -40,4 +40,6 @@ class AwaitableState {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
exports.AwaitableState = AwaitableState;
|
|
43
|
+
Object.freeze(AwaitableState.prototype);
|
|
44
|
+
Object.freeze(AwaitableState);
|
|
43
45
|
Object.freeze(exports);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type FileException = web3n.files.FileException;
|
|
2
2
|
export type FileExceptionFlag = web3n.files.FileExceptionFlag;
|
|
3
3
|
export declare const Code: web3n.files.exceptionCode;
|
|
4
|
-
export declare function makeFileExceptionFromCode(code: string | undefined, path: string, cause?: any): FileException;
|
|
4
|
+
export declare function makeFileExceptionFromCode(code: string | undefined, path: string, cause?: any, numOfTopLayersToRemove?: number): FileException;
|
|
5
5
|
export declare function makeFileException(flag: keyof FileExceptionFlag, path: string, cause?: any): FileException;
|
|
6
6
|
export declare function maskPathInExc(pathPrefixMaskLen: number, exc: any): FileException;
|
|
7
7
|
export declare function ensureCorrectFS(fs: web3n.files.FS, type: web3n.files.FSType, writable: boolean): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2018, 2020 - 2022 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2015 - 2018, 2020 - 2022, 2026 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -23,6 +23,7 @@ exports.maskPathInExc = maskPathInExc;
|
|
|
23
23
|
exports.ensureCorrectFS = ensureCorrectFS;
|
|
24
24
|
exports.makeNoAttrsExc = makeNoAttrsExc;
|
|
25
25
|
exports.makeVersionMismatchExc = makeVersionMismatchExc;
|
|
26
|
+
const runtime_1 = require("./runtime");
|
|
26
27
|
exports.Code = {
|
|
27
28
|
notFound: 'ENOENT',
|
|
28
29
|
alreadyExists: 'EEXIST',
|
|
@@ -41,13 +42,14 @@ const codeToFlag = {};
|
|
|
41
42
|
for (const [flag, code] of Object.entries(exports.Code)) {
|
|
42
43
|
codeToFlag[code] = flag;
|
|
43
44
|
}
|
|
44
|
-
function makeFileExceptionFromCode(code, path, cause) {
|
|
45
|
+
function makeFileExceptionFromCode(code, path, cause, numOfTopLayersToRemove = 0) {
|
|
45
46
|
const err = {
|
|
46
47
|
runtimeException: true,
|
|
47
48
|
type: 'file',
|
|
48
49
|
code,
|
|
49
50
|
path,
|
|
50
|
-
cause
|
|
51
|
+
cause,
|
|
52
|
+
stack: (0, runtime_1.getStackHere)(1 + numOfTopLayersToRemove)
|
|
51
53
|
};
|
|
52
54
|
if (code) {
|
|
53
55
|
const flag = codeToFlag[code];
|
|
@@ -64,7 +66,8 @@ function makeFileException(flag, path, cause) {
|
|
|
64
66
|
type: 'file',
|
|
65
67
|
code,
|
|
66
68
|
path,
|
|
67
|
-
cause
|
|
69
|
+
cause,
|
|
70
|
+
stack: (0, runtime_1.getStackHere)(1)
|
|
68
71
|
};
|
|
69
72
|
err[flag] = true;
|
|
70
73
|
return err;
|
|
@@ -95,7 +98,8 @@ function makeNoAttrsExc(path) {
|
|
|
95
98
|
type: 'file',
|
|
96
99
|
code: undefined,
|
|
97
100
|
path,
|
|
98
|
-
attrsNotEnabledInFS: true
|
|
101
|
+
attrsNotEnabledInFS: true,
|
|
102
|
+
stack: (0, runtime_1.getStackHere)(1)
|
|
99
103
|
};
|
|
100
104
|
}
|
|
101
105
|
function makeVersionMismatchExc(path, message) {
|
|
@@ -105,7 +109,8 @@ function makeVersionMismatchExc(path, message) {
|
|
|
105
109
|
code: undefined,
|
|
106
110
|
path,
|
|
107
111
|
versionMismatch: true,
|
|
108
|
-
message
|
|
112
|
+
message,
|
|
113
|
+
stack: (0, runtime_1.getStackHere)(1)
|
|
109
114
|
};
|
|
110
115
|
}
|
|
111
116
|
Object.freeze(exports);
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
export declare function makeRuntimeException<T extends web3n.RuntimeException>(type: NonNullable<T['type']>, params: Partial<T>, flags: Partial<T
|
|
1
|
+
export declare function makeRuntimeException<T extends web3n.RuntimeException>(type: NonNullable<T['type']>, params: Partial<T>, flags: Partial<T>, addStack?: boolean): T;
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param numOfTopLayersToRemove
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare function getStackHere(numOfTopLayersToRemove?: number): string | undefined;
|