@zenfs/core 0.9.6 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backends/AsyncStore.d.ts +3 -2
- package/dist/backends/AsyncStore.js +40 -33
- package/dist/backends/Fetch.d.ts +84 -0
- package/dist/backends/Fetch.js +171 -0
- package/dist/backends/InMemory.d.ts +1 -1
- package/dist/backends/Index.d.ts +7 -10
- package/dist/backends/Index.js +26 -24
- package/dist/backends/Locked.d.ts +11 -11
- package/dist/backends/Locked.js +50 -49
- package/dist/backends/Overlay.js +22 -22
- package/dist/backends/SyncStore.d.ts +6 -6
- package/dist/backends/SyncStore.js +30 -30
- package/dist/backends/backend.d.ts +5 -4
- package/dist/backends/backend.js +6 -6
- package/dist/backends/port/fs.d.ts +124 -0
- package/dist/backends/port/fs.js +241 -0
- package/dist/backends/port/rpc.d.ts +60 -0
- package/dist/backends/port/rpc.js +71 -0
- package/dist/backends/port/store.d.ts +30 -0
- package/dist/backends/port/store.js +142 -0
- package/dist/browser.min.js +4 -4
- package/dist/browser.min.js.map +4 -4
- package/dist/config.d.ts +9 -11
- package/dist/config.js +13 -13
- package/dist/emulation/async.d.ts +76 -77
- package/dist/emulation/async.js +45 -45
- package/dist/emulation/dir.js +8 -7
- package/dist/emulation/index.d.ts +1 -1
- package/dist/emulation/index.js +1 -1
- package/dist/emulation/path.d.ts +3 -2
- package/dist/emulation/path.js +19 -45
- package/dist/emulation/promises.d.ts +112 -113
- package/dist/emulation/promises.js +167 -173
- package/dist/emulation/shared.d.ts +6 -17
- package/dist/emulation/shared.js +9 -9
- package/dist/emulation/streams.js +3 -2
- package/dist/emulation/sync.d.ts +71 -64
- package/dist/emulation/sync.js +62 -63
- package/dist/{ApiError.d.ts → error.d.ts} +15 -15
- package/dist/error.js +292 -0
- package/dist/file.d.ts +6 -4
- package/dist/file.js +17 -9
- package/dist/filesystem.d.ts +1 -1
- package/dist/filesystem.js +18 -15
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/mutex.js +4 -3
- package/dist/stats.d.ts +7 -7
- package/dist/stats.js +50 -10
- package/dist/utils.d.ts +10 -9
- package/dist/utils.js +15 -15
- package/package.json +5 -5
- package/readme.md +19 -11
- package/src/backends/AsyncStore.ts +42 -36
- package/src/backends/Fetch.ts +230 -0
- package/src/backends/Index.ts +33 -29
- package/src/backends/Locked.ts +50 -49
- package/src/backends/Overlay.ts +24 -24
- package/src/backends/SyncStore.ts +34 -34
- package/src/backends/backend.ts +13 -11
- package/src/backends/port/fs.ts +308 -0
- package/src/backends/port/readme.md +59 -0
- package/src/backends/port/rpc.ts +144 -0
- package/src/backends/port/store.ts +187 -0
- package/src/config.ts +25 -29
- package/src/emulation/async.ts +191 -199
- package/src/emulation/dir.ts +8 -8
- package/src/emulation/index.ts +1 -1
- package/src/emulation/path.ts +25 -49
- package/src/emulation/promises.ts +286 -287
- package/src/emulation/shared.ts +14 -23
- package/src/emulation/streams.ts +9 -8
- package/src/emulation/sync.ts +182 -182
- package/src/{ApiError.ts → error.ts} +91 -89
- package/src/file.ts +23 -13
- package/src/filesystem.ts +26 -22
- package/src/index.ts +4 -1
- package/src/mutex.ts +6 -4
- package/src/stats.ts +32 -23
- package/src/utils.ts +23 -24
- package/tsconfig.json +4 -3
- package/dist/ApiError.js +0 -292
package/dist/emulation/sync.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
|
-
import {
|
|
2
|
+
import { ErrnoError, Errno } from '../error.js';
|
|
3
3
|
import { ActionType, isAppendable, isReadable, isWriteable, parseFlag, pathExistsAction, pathNotExistsAction } from '../file.js';
|
|
4
4
|
import { BigIntStats, FileType } from '../stats.js';
|
|
5
5
|
import { normalizeMode, normalizeOptions, normalizePath, normalizeTime } from '../utils.js';
|
|
6
|
-
import { COPYFILE_EXCL, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK } from './constants.js';
|
|
6
|
+
import { COPYFILE_EXCL, F_OK, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK } from './constants.js';
|
|
7
7
|
import { Dir, Dirent } from './dir.js';
|
|
8
8
|
import { dirname, join, parse } from './path.js';
|
|
9
|
-
import { cred, fd2file, fdMap, fixError,
|
|
9
|
+
import { cred, fd2file, fdMap, fixError, file2fd, mounts, resolveMount } from './shared.js';
|
|
10
10
|
function doOp(...[name, resolveSymlinks, path, ...args]) {
|
|
11
11
|
path = normalizePath(path);
|
|
12
12
|
const { fs, path: resolvedPath } = resolveMount(resolveSymlinks && existsSync(path) ? realpathSync(path) : path);
|
|
@@ -52,7 +52,7 @@ export function existsSync(path) {
|
|
|
52
52
|
return fs.existsSync(resolvedPath, cred);
|
|
53
53
|
}
|
|
54
54
|
catch (e) {
|
|
55
|
-
if (e.errno ==
|
|
55
|
+
if (e.errno == Errno.ENOENT) {
|
|
56
56
|
return false;
|
|
57
57
|
}
|
|
58
58
|
throw e;
|
|
@@ -60,12 +60,12 @@ export function existsSync(path) {
|
|
|
60
60
|
}
|
|
61
61
|
existsSync;
|
|
62
62
|
export function statSync(path, options) {
|
|
63
|
-
const stats = doOp('statSync', true, path, cred);
|
|
63
|
+
const stats = doOp('statSync', true, path.toString(), cred);
|
|
64
64
|
return options?.bigint ? new BigIntStats(stats) : stats;
|
|
65
65
|
}
|
|
66
66
|
statSync;
|
|
67
67
|
export function lstatSync(path, options) {
|
|
68
|
-
const stats = doOp('statSync', false, path, cred);
|
|
68
|
+
const stats = doOp('statSync', false, path.toString(), cred);
|
|
69
69
|
return options?.bigint ? new BigIntStats(stats) : stats;
|
|
70
70
|
}
|
|
71
71
|
lstatSync;
|
|
@@ -89,10 +89,10 @@ truncateSync;
|
|
|
89
89
|
* @param path
|
|
90
90
|
*/
|
|
91
91
|
export function unlinkSync(path) {
|
|
92
|
-
return doOp('unlinkSync', false, path, cred);
|
|
92
|
+
return doOp('unlinkSync', false, path.toString(), cred);
|
|
93
93
|
}
|
|
94
94
|
unlinkSync;
|
|
95
|
-
function _openSync(_path, _flag, _mode, resolveSymlinks) {
|
|
95
|
+
function _openSync(_path, _flag, _mode, resolveSymlinks = true) {
|
|
96
96
|
const path = normalizePath(_path), mode = normalizeMode(_mode, 0o644), flag = parseFlag(_flag);
|
|
97
97
|
// Check if the path exists, and is a file.
|
|
98
98
|
let stats;
|
|
@@ -106,22 +106,22 @@ function _openSync(_path, _flag, _mode, resolveSymlinks) {
|
|
|
106
106
|
// Ensure parent exists.
|
|
107
107
|
const parentStats = doOp('statSync', resolveSymlinks, dirname(path), cred);
|
|
108
108
|
if (!parentStats.isDirectory()) {
|
|
109
|
-
throw
|
|
109
|
+
throw ErrnoError.With('ENOTDIR', dirname(path), '_open');
|
|
110
110
|
}
|
|
111
111
|
return doOp('createFileSync', resolveSymlinks, path, flag, mode, cred);
|
|
112
112
|
case ActionType.THROW:
|
|
113
|
-
throw
|
|
113
|
+
throw ErrnoError.With('ENOENT', path, '_open');
|
|
114
114
|
default:
|
|
115
|
-
throw new
|
|
115
|
+
throw new ErrnoError(Errno.EINVAL, 'Invalid FileFlag object.');
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
if (!stats.hasAccess(mode, cred)) {
|
|
119
|
-
throw
|
|
119
|
+
throw ErrnoError.With('EACCES', path, '_open');
|
|
120
120
|
}
|
|
121
121
|
// File exists.
|
|
122
122
|
switch (pathExistsAction(flag)) {
|
|
123
123
|
case ActionType.THROW:
|
|
124
|
-
throw
|
|
124
|
+
throw ErrnoError.With('EEXIST', path, '_open');
|
|
125
125
|
case ActionType.TRUNCATE:
|
|
126
126
|
// Delete file.
|
|
127
127
|
doOp('unlinkSync', resolveSymlinks, path, cred);
|
|
@@ -135,7 +135,7 @@ function _openSync(_path, _flag, _mode, resolveSymlinks) {
|
|
|
135
135
|
case ActionType.NOP:
|
|
136
136
|
return doOp('openFileSync', resolveSymlinks, path, flag, cred);
|
|
137
137
|
default:
|
|
138
|
-
throw new
|
|
138
|
+
throw new ErrnoError(Errno.EINVAL, 'Invalid FileFlag object.');
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
/**
|
|
@@ -146,8 +146,8 @@ function _openSync(_path, _flag, _mode, resolveSymlinks) {
|
|
|
146
146
|
* @param mode Mode to use to open the file. Can be ignored if the
|
|
147
147
|
* filesystem doesn't support permissions.
|
|
148
148
|
*/
|
|
149
|
-
export function openSync(path, flag, mode) {
|
|
150
|
-
return
|
|
149
|
+
export function openSync(path, flag, mode = F_OK) {
|
|
150
|
+
return file2fd(_openSync(path, flag, mode, true));
|
|
151
151
|
}
|
|
152
152
|
openSync;
|
|
153
153
|
/**
|
|
@@ -155,7 +155,7 @@ openSync;
|
|
|
155
155
|
* @internal
|
|
156
156
|
*/
|
|
157
157
|
export function lopenSync(path, flag, mode) {
|
|
158
|
-
return
|
|
158
|
+
return file2fd(_openSync(path, flag, mode, false));
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
161
|
* Synchronously reads the entire contents of a file.
|
|
@@ -175,13 +175,13 @@ function _readFileSync(fname, flag, resolveSymlinks) {
|
|
|
175
175
|
file.closeSync();
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
|
-
export function readFileSync(
|
|
179
|
-
const options = normalizeOptions(
|
|
178
|
+
export function readFileSync(path, _options = {}) {
|
|
179
|
+
const options = normalizeOptions(_options, null, 'r', 0o644);
|
|
180
180
|
const flag = parseFlag(options.flag);
|
|
181
181
|
if (!isReadable(flag)) {
|
|
182
|
-
throw new
|
|
182
|
+
throw new ErrnoError(Errno.EINVAL, 'Flag passed to readFile must allow for reading.');
|
|
183
183
|
}
|
|
184
|
-
const data = Buffer.from(_readFileSync(
|
|
184
|
+
const data = Buffer.from(_readFileSync(typeof path == 'number' ? fd2file(path).path : path.toString(), options.flag, true));
|
|
185
185
|
return options.encoding ? data.toString(options.encoding) : data;
|
|
186
186
|
}
|
|
187
187
|
readFileSync;
|
|
@@ -194,26 +194,26 @@ readFileSync;
|
|
|
194
194
|
function _writeFileSync(fname, data, flag, mode, resolveSymlinks) {
|
|
195
195
|
const file = _openSync(fname, flag, mode, resolveSymlinks);
|
|
196
196
|
try {
|
|
197
|
-
file.writeSync(data, 0, data.
|
|
197
|
+
file.writeSync(data, 0, data.byteLength, 0);
|
|
198
198
|
}
|
|
199
199
|
finally {
|
|
200
200
|
file.closeSync();
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
|
-
export function writeFileSync(
|
|
203
|
+
export function writeFileSync(path, data, _options = {}) {
|
|
204
204
|
const options = normalizeOptions(_options, 'utf8', 'w+', 0o644);
|
|
205
205
|
const flag = parseFlag(options.flag);
|
|
206
206
|
if (!isWriteable(flag)) {
|
|
207
|
-
throw new
|
|
207
|
+
throw new ErrnoError(Errno.EINVAL, 'Flag passed to writeFile must allow for writing.');
|
|
208
208
|
}
|
|
209
209
|
if (typeof data != 'string' && !options.encoding) {
|
|
210
|
-
throw new
|
|
210
|
+
throw new ErrnoError(Errno.EINVAL, 'Encoding not specified');
|
|
211
211
|
}
|
|
212
|
-
const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : data;
|
|
213
|
-
if (encodedData
|
|
214
|
-
throw new
|
|
212
|
+
const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
213
|
+
if (!encodedData) {
|
|
214
|
+
throw new ErrnoError(Errno.EINVAL, 'Data not specified');
|
|
215
215
|
}
|
|
216
|
-
_writeFileSync(
|
|
216
|
+
_writeFileSync(typeof path == 'number' ? fd2file(path).path : path.toString(), encodedData, options.flag, options.mode, true);
|
|
217
217
|
}
|
|
218
218
|
writeFileSync;
|
|
219
219
|
/**
|
|
@@ -223,7 +223,7 @@ writeFileSync;
|
|
|
223
223
|
function _appendFileSync(fname, data, flag, mode, resolveSymlinks) {
|
|
224
224
|
const file = _openSync(fname, flag, mode, resolveSymlinks);
|
|
225
225
|
try {
|
|
226
|
-
file.writeSync(data, 0, data.
|
|
226
|
+
file.writeSync(data, 0, data.byteLength, null);
|
|
227
227
|
}
|
|
228
228
|
finally {
|
|
229
229
|
file.closeSync();
|
|
@@ -240,17 +240,17 @@ function _appendFileSync(fname, data, flag, mode, resolveSymlinks) {
|
|
|
240
240
|
* @option options mode Defaults to `0644`.
|
|
241
241
|
* @option options flag Defaults to `'a'`.
|
|
242
242
|
*/
|
|
243
|
-
export function appendFileSync(filename, data, _options) {
|
|
243
|
+
export function appendFileSync(filename, data, _options = {}) {
|
|
244
244
|
const options = normalizeOptions(_options, 'utf8', 'a', 0o644);
|
|
245
245
|
const flag = parseFlag(options.flag);
|
|
246
246
|
if (!isAppendable(flag)) {
|
|
247
|
-
throw new
|
|
247
|
+
throw new ErrnoError(Errno.EINVAL, 'Flag passed to appendFile must allow for appending.');
|
|
248
248
|
}
|
|
249
249
|
if (typeof data != 'string' && !options.encoding) {
|
|
250
|
-
throw new
|
|
250
|
+
throw new ErrnoError(Errno.EINVAL, 'Encoding not specified');
|
|
251
251
|
}
|
|
252
|
-
const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : data;
|
|
253
|
-
_appendFileSync(filename, encodedData, options.flag, options.mode, true);
|
|
252
|
+
const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
253
|
+
_appendFileSync(typeof filename == 'number' ? fd2file(filename).path : filename.toString(), encodedData, options.flag, options.mode, true);
|
|
254
254
|
}
|
|
255
255
|
appendFileSync;
|
|
256
256
|
export function fstatSync(fd, options) {
|
|
@@ -273,8 +273,9 @@ closeSync;
|
|
|
273
273
|
* @param len
|
|
274
274
|
*/
|
|
275
275
|
export function ftruncateSync(fd, len = 0) {
|
|
276
|
+
len || (len = 0);
|
|
276
277
|
if (len < 0) {
|
|
277
|
-
throw new
|
|
278
|
+
throw new ErrnoError(Errno.EINVAL);
|
|
278
279
|
}
|
|
279
280
|
fd2file(fd).truncateSync(len);
|
|
280
281
|
}
|
|
@@ -296,26 +297,24 @@ export function fdatasyncSync(fd) {
|
|
|
296
297
|
}
|
|
297
298
|
fdatasyncSync;
|
|
298
299
|
export function writeSync(fd, data, posOrOff, lenOrEnc, pos) {
|
|
299
|
-
let buffer, offset
|
|
300
|
+
let buffer, offset, length, position;
|
|
300
301
|
if (typeof data === 'string') {
|
|
301
302
|
// Signature 1: (fd, string, [position?, [encoding?]])
|
|
302
303
|
position = typeof posOrOff === 'number' ? posOrOff : null;
|
|
303
304
|
const encoding = (typeof lenOrEnc === 'string' ? lenOrEnc : 'utf8');
|
|
304
305
|
offset = 0;
|
|
305
306
|
buffer = Buffer.from(data, encoding);
|
|
306
|
-
length = buffer.
|
|
307
|
+
length = buffer.byteLength;
|
|
307
308
|
}
|
|
308
309
|
else {
|
|
309
310
|
// Signature 2: (fd, buffer, offset, length, position?)
|
|
310
|
-
buffer = data;
|
|
311
|
+
buffer = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
311
312
|
offset = posOrOff;
|
|
312
313
|
length = lenOrEnc;
|
|
313
314
|
position = typeof pos === 'number' ? pos : null;
|
|
314
315
|
}
|
|
315
316
|
const file = fd2file(fd);
|
|
316
|
-
|
|
317
|
-
position = file.position;
|
|
318
|
-
}
|
|
317
|
+
position ?? (position = file.position);
|
|
319
318
|
return file.writeSync(buffer, offset, length, position);
|
|
320
319
|
}
|
|
321
320
|
writeSync;
|
|
@@ -351,7 +350,7 @@ fchownSync;
|
|
|
351
350
|
export function fchmodSync(fd, mode) {
|
|
352
351
|
const numMode = normalizeMode(mode, -1);
|
|
353
352
|
if (numMode < 0) {
|
|
354
|
-
throw new
|
|
353
|
+
throw new ErrnoError(Errno.EINVAL, `Invalid mode.`);
|
|
355
354
|
}
|
|
356
355
|
fd2file(fd).chmodSync(numMode);
|
|
357
356
|
}
|
|
@@ -372,13 +371,13 @@ futimesSync;
|
|
|
372
371
|
* @param path
|
|
373
372
|
*/
|
|
374
373
|
export function rmdirSync(path) {
|
|
375
|
-
return doOp('rmdirSync', true, path, cred);
|
|
374
|
+
return doOp('rmdirSync', true, path.toString(), cred);
|
|
376
375
|
}
|
|
377
376
|
rmdirSync;
|
|
378
377
|
export function mkdirSync(path, options) {
|
|
379
378
|
const mode = typeof options == 'number' || typeof options == 'string' ? options : options?.mode;
|
|
380
379
|
const recursive = typeof options == 'object' && options?.recursive;
|
|
381
|
-
doOp('mkdirSync', true, path, normalizeMode(mode, 0o777), cred);
|
|
380
|
+
doOp('mkdirSync', true, path.toString(), normalizeMode(mode, 0o777), cred);
|
|
382
381
|
}
|
|
383
382
|
mkdirSync;
|
|
384
383
|
export function readdirSync(path, options) {
|
|
@@ -397,9 +396,9 @@ export function readdirSync(path, options) {
|
|
|
397
396
|
}
|
|
398
397
|
return entries.map((entry) => {
|
|
399
398
|
if (typeof options == 'object' && options?.withFileTypes) {
|
|
400
|
-
return new Dirent(entry, statSync(join(path, entry)));
|
|
399
|
+
return new Dirent(entry, statSync(join(path.toString(), entry)));
|
|
401
400
|
}
|
|
402
|
-
if (options == 'buffer' || (typeof options == 'object' && options
|
|
401
|
+
if (options == 'buffer' || (typeof options == 'object' && options?.encoding == 'buffer')) {
|
|
403
402
|
return Buffer.from(entry);
|
|
404
403
|
}
|
|
405
404
|
return entry;
|
|
@@ -414,7 +413,7 @@ readdirSync;
|
|
|
414
413
|
*/
|
|
415
414
|
export function linkSync(existing, newpath) {
|
|
416
415
|
newpath = normalizePath(newpath);
|
|
417
|
-
return doOp('linkSync', false, existing, newpath, cred);
|
|
416
|
+
return doOp('linkSync', false, existing.toString(), newpath.toString(), cred);
|
|
418
417
|
}
|
|
419
418
|
linkSync;
|
|
420
419
|
/**
|
|
@@ -425,19 +424,19 @@ linkSync;
|
|
|
425
424
|
*/
|
|
426
425
|
export function symlinkSync(target, path, type = 'file') {
|
|
427
426
|
if (!['file', 'dir', 'junction'].includes(type)) {
|
|
428
|
-
throw new
|
|
427
|
+
throw new ErrnoError(Errno.EINVAL, 'Invalid type: ' + type);
|
|
429
428
|
}
|
|
430
429
|
if (existsSync(path)) {
|
|
431
|
-
throw
|
|
430
|
+
throw ErrnoError.With('EEXIST', path.toString(), 'symlink');
|
|
432
431
|
}
|
|
433
|
-
writeFileSync(path, target);
|
|
432
|
+
writeFileSync(path, target.toString());
|
|
434
433
|
const file = _openSync(path, 'r+', 0o644, false);
|
|
435
434
|
file._setTypeSync(FileType.SYMLINK);
|
|
436
435
|
}
|
|
437
436
|
symlinkSync;
|
|
438
437
|
export function readlinkSync(path, options) {
|
|
439
|
-
const value = Buffer.from(_readFileSync(path, 'r', false));
|
|
440
|
-
const encoding = typeof options == 'object' ? options
|
|
438
|
+
const value = Buffer.from(_readFileSync(path.toString(), 'r', false));
|
|
439
|
+
const encoding = typeof options == 'object' ? options?.encoding : options;
|
|
441
440
|
if (encoding == 'buffer') {
|
|
442
441
|
return value;
|
|
443
442
|
}
|
|
@@ -540,7 +539,7 @@ realpathSync;
|
|
|
540
539
|
export function accessSync(path, mode = 0o600) {
|
|
541
540
|
const stats = statSync(path);
|
|
542
541
|
if (!stats.hasAccess(mode, cred)) {
|
|
543
|
-
throw new
|
|
542
|
+
throw new ErrnoError(Errno.EACCES);
|
|
544
543
|
}
|
|
545
544
|
}
|
|
546
545
|
accessSync;
|
|
@@ -569,12 +568,12 @@ export function rmSync(path, options) {
|
|
|
569
568
|
case S_IFIFO:
|
|
570
569
|
case S_IFSOCK:
|
|
571
570
|
default:
|
|
572
|
-
throw new
|
|
571
|
+
throw new ErrnoError(Errno.EPERM, 'File type not supported', path, 'rm');
|
|
573
572
|
}
|
|
574
573
|
}
|
|
575
574
|
rmSync;
|
|
576
575
|
export function mkdtempSync(prefix, options) {
|
|
577
|
-
const encoding = typeof options === 'object' ? options
|
|
576
|
+
const encoding = typeof options === 'object' ? options?.encoding : options || 'utf8';
|
|
578
577
|
const fsName = `${prefix}${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
579
578
|
const resolvedPath = '/tmp/' + fsName;
|
|
580
579
|
mkdirSync(resolvedPath);
|
|
@@ -592,7 +591,7 @@ export function copyFileSync(src, dest, flags) {
|
|
|
592
591
|
src = normalizePath(src);
|
|
593
592
|
dest = normalizePath(dest);
|
|
594
593
|
if (flags && flags & COPYFILE_EXCL && existsSync(dest)) {
|
|
595
|
-
throw new
|
|
594
|
+
throw new ErrnoError(Errno.EEXIST, 'Destination file already exists.', dest, 'copyFile');
|
|
596
595
|
}
|
|
597
596
|
writeFileSync(dest, readFileSync(src));
|
|
598
597
|
}
|
|
@@ -608,7 +607,7 @@ export function readvSync(fd, buffers, position) {
|
|
|
608
607
|
const file = fd2file(fd);
|
|
609
608
|
let bytesRead = 0;
|
|
610
609
|
for (const buffer of buffers) {
|
|
611
|
-
bytesRead += file.readSync(buffer, 0, buffer.
|
|
610
|
+
bytesRead += file.readSync(buffer, 0, buffer.byteLength, position + bytesRead);
|
|
612
611
|
}
|
|
613
612
|
return bytesRead;
|
|
614
613
|
}
|
|
@@ -624,7 +623,7 @@ export function writevSync(fd, buffers, position) {
|
|
|
624
623
|
const file = fd2file(fd);
|
|
625
624
|
let bytesWritten = 0;
|
|
626
625
|
for (const buffer of buffers) {
|
|
627
|
-
bytesWritten += file.writeSync(buffer, 0, buffer.
|
|
626
|
+
bytesWritten += file.writeSync(new Uint8Array(buffer.buffer), 0, buffer.byteLength, position + bytesWritten);
|
|
628
627
|
}
|
|
629
628
|
return bytesWritten;
|
|
630
629
|
}
|
|
@@ -657,12 +656,12 @@ export function cpSync(source, destination, opts) {
|
|
|
657
656
|
destination = normalizePath(destination);
|
|
658
657
|
const srcStats = lstatSync(source); // Use lstat to follow symlinks if not dereferencing
|
|
659
658
|
if (opts?.errorOnExist && existsSync(destination)) {
|
|
660
|
-
throw new
|
|
659
|
+
throw new ErrnoError(Errno.EEXIST, 'Destination file or directory already exists.', destination, 'cp');
|
|
661
660
|
}
|
|
662
661
|
switch (srcStats.mode & S_IFMT) {
|
|
663
662
|
case S_IFDIR:
|
|
664
663
|
if (!opts?.recursive) {
|
|
665
|
-
throw new
|
|
664
|
+
throw new ErrnoError(Errno.EISDIR, source + ' is a directory (not copied)', source, 'cp');
|
|
666
665
|
}
|
|
667
666
|
mkdirSync(destination, { recursive: true }); // Ensure the destination directory exists
|
|
668
667
|
for (const dirent of readdirSync(source, { withFileTypes: true })) {
|
|
@@ -681,7 +680,7 @@ export function cpSync(source, destination, opts) {
|
|
|
681
680
|
case S_IFIFO:
|
|
682
681
|
case S_IFSOCK:
|
|
683
682
|
default:
|
|
684
|
-
throw new
|
|
683
|
+
throw new ErrnoError(Errno.EPERM, 'File type not supported', source, 'rm');
|
|
685
684
|
}
|
|
686
685
|
// Optionally preserve timestamps
|
|
687
686
|
if (opts?.preserveTimestamps) {
|
|
@@ -690,5 +689,5 @@ export function cpSync(source, destination, opts) {
|
|
|
690
689
|
}
|
|
691
690
|
cpSync;
|
|
692
691
|
export function statfsSync(path, options) {
|
|
693
|
-
throw
|
|
692
|
+
throw ErrnoError.With('ENOSYS', path.toString(), 'statfs');
|
|
694
693
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
/**
|
|
3
|
-
* Standard libc error codes. More will be added to this enum and
|
|
3
|
+
* Standard libc error codes. More will be added to this enum and error strings as they are
|
|
4
4
|
* needed.
|
|
5
5
|
* @url https://en.wikipedia.org/wiki/Errno.h
|
|
6
6
|
*/
|
|
7
|
-
export declare enum
|
|
7
|
+
export declare enum Errno {
|
|
8
8
|
/** Operation not permitted */
|
|
9
9
|
EPERM = 1,
|
|
10
10
|
/** No such file or directory */
|
|
@@ -159,13 +159,13 @@ export declare enum ErrorCode {
|
|
|
159
159
|
* @internal
|
|
160
160
|
*/
|
|
161
161
|
export declare const errorMessages: {
|
|
162
|
-
[K in
|
|
162
|
+
[K in Errno]: string;
|
|
163
163
|
};
|
|
164
|
-
interface
|
|
165
|
-
errno:
|
|
164
|
+
export interface ErrnoErrorJSON {
|
|
165
|
+
errno: Errno;
|
|
166
166
|
message: string;
|
|
167
167
|
path?: string;
|
|
168
|
-
code: keyof typeof
|
|
168
|
+
code: keyof typeof Errno;
|
|
169
169
|
stack: string;
|
|
170
170
|
syscall: string;
|
|
171
171
|
}
|
|
@@ -173,13 +173,14 @@ interface ApiErrorJSON {
|
|
|
173
173
|
* Represents a ZenFS error. Passed back to applications after a failed
|
|
174
174
|
* call to the ZenFS API.
|
|
175
175
|
*/
|
|
176
|
-
export declare class
|
|
177
|
-
errno:
|
|
178
|
-
path?: string;
|
|
176
|
+
export declare class ErrnoError extends Error implements NodeJS.ErrnoException {
|
|
177
|
+
errno: Errno;
|
|
178
|
+
path?: string | undefined;
|
|
179
179
|
syscall: string;
|
|
180
|
-
static fromJSON(json:
|
|
181
|
-
static With(code: keyof typeof
|
|
182
|
-
code: keyof typeof
|
|
180
|
+
static fromJSON(json: ErrnoErrorJSON): ErrnoError;
|
|
181
|
+
static With(code: keyof typeof Errno, path?: string, syscall?: string): ErrnoError;
|
|
182
|
+
code: keyof typeof Errno;
|
|
183
|
+
stack: string;
|
|
183
184
|
/**
|
|
184
185
|
* Represents a ZenFS error. Passed back to applications after a failed
|
|
185
186
|
* call to the ZenFS API.
|
|
@@ -190,15 +191,14 @@ export declare class ApiError extends Error implements NodeJS.ErrnoException {
|
|
|
190
191
|
* @param type The type of the error.
|
|
191
192
|
* @param message A descriptive error message.
|
|
192
193
|
*/
|
|
193
|
-
constructor(errno:
|
|
194
|
+
constructor(errno: Errno, message?: string, path?: string | undefined, syscall?: string);
|
|
194
195
|
/**
|
|
195
196
|
* @return A friendly error message.
|
|
196
197
|
*/
|
|
197
198
|
toString(): string;
|
|
198
|
-
toJSON():
|
|
199
|
+
toJSON(): ErrnoErrorJSON;
|
|
199
200
|
/**
|
|
200
201
|
* The size of the API error in buffer-form in bytes.
|
|
201
202
|
*/
|
|
202
203
|
bufferSize(): number;
|
|
203
204
|
}
|
|
204
|
-
export {};
|