@zenfs/core 1.3.6 → 1.4.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/memory.d.ts +4 -4
- package/dist/backends/memory.js +4 -4
- package/dist/backends/overlay.d.ts +5 -2
- package/dist/backends/overlay.js +7 -10
- package/dist/backends/port/fs.js +1 -4
- package/dist/config.js +4 -8
- package/dist/context.d.ts +32 -0
- package/dist/context.js +23 -0
- package/dist/credentials.d.ts +5 -5
- package/dist/credentials.js +10 -6
- package/dist/emulation/async.d.ts +90 -89
- package/dist/emulation/async.js +76 -75
- package/dist/emulation/dir.d.ts +3 -1
- package/dist/emulation/dir.js +6 -7
- package/dist/emulation/index.d.ts +1 -1
- package/dist/emulation/index.js +1 -1
- package/dist/emulation/promises.d.ts +50 -48
- package/dist/emulation/promises.js +78 -77
- package/dist/emulation/shared.d.ts +35 -8
- package/dist/emulation/shared.js +37 -11
- package/dist/emulation/sync.d.ts +63 -62
- package/dist/emulation/sync.js +72 -73
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/stats.d.ts +2 -1
- package/dist/stats.js +5 -4
- package/package.json +3 -5
- package/scripts/test.js +78 -17
- package/tests/assignment.ts +1 -1
- package/tests/common/context.test.ts +19 -0
- package/tests/{devices.test.ts → common/devices.test.ts} +3 -3
- package/tests/{handle.test.ts → common/handle.test.ts} +1 -1
- package/tests/common/mounts.test.ts +36 -0
- package/tests/{mutex.test.ts → common/mutex.test.ts} +3 -3
- package/tests/common/path.test.ts +34 -0
- package/tests/common.ts +4 -3
- package/tests/fs/dir.test.ts +11 -11
- package/tests/fs/directory.test.ts +17 -17
- package/tests/fs/errors.test.ts +29 -39
- package/tests/fs/watch.test.ts +2 -2
- package/tests/setup/context.ts +9 -0
- package/tests/setup/cow+fetch.ts +1 -1
- package/tests/setup/memory.ts +1 -1
- package/tests/{setup/common.ts → setup.ts} +6 -5
- package/src/backends/backend.ts +0 -161
- package/src/backends/fetch.ts +0 -180
- package/src/backends/file_index.ts +0 -206
- package/src/backends/memory.ts +0 -45
- package/src/backends/overlay.ts +0 -560
- package/src/backends/port/fs.ts +0 -329
- package/src/backends/port/readme.md +0 -54
- package/src/backends/port/rpc.ts +0 -167
- package/src/backends/readme.md +0 -3
- package/src/backends/store/fs.ts +0 -667
- package/src/backends/store/readme.md +0 -9
- package/src/backends/store/simple.ts +0 -154
- package/src/backends/store/store.ts +0 -189
- package/src/config.ts +0 -227
- package/src/credentials.ts +0 -49
- package/src/devices.ts +0 -521
- package/src/emulation/async.ts +0 -834
- package/src/emulation/cache.ts +0 -86
- package/src/emulation/config.ts +0 -21
- package/src/emulation/constants.ts +0 -182
- package/src/emulation/dir.ts +0 -138
- package/src/emulation/index.ts +0 -8
- package/src/emulation/path.ts +0 -440
- package/src/emulation/promises.ts +0 -1140
- package/src/emulation/shared.ts +0 -172
- package/src/emulation/streams.ts +0 -34
- package/src/emulation/sync.ts +0 -863
- package/src/emulation/watchers.ts +0 -194
- package/src/error.ts +0 -307
- package/src/file.ts +0 -631
- package/src/filesystem.ts +0 -174
- package/src/index.ts +0 -35
- package/src/inode.ts +0 -128
- package/src/mixins/async.ts +0 -230
- package/src/mixins/index.ts +0 -5
- package/src/mixins/mutexed.ts +0 -257
- package/src/mixins/readonly.ts +0 -96
- package/src/mixins/shared.ts +0 -25
- package/src/mixins/sync.ts +0 -58
- package/src/polyfills.ts +0 -21
- package/src/stats.ts +0 -405
- package/src/utils.ts +0 -276
- package/tests/mounts.test.ts +0 -18
- package/tests/path.test.ts +0 -34
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'eventemitter3';
|
|
2
|
-
import type { EventEmitter as NodeEventEmitter } from 'node:events';
|
|
3
|
-
import type * as fs from 'node:fs';
|
|
4
|
-
import { ErrnoError } from '../error.js';
|
|
5
|
-
import { isStatsEqual, type Stats } from '../stats.js';
|
|
6
|
-
import { normalizePath } from '../utils.js';
|
|
7
|
-
import { basename, dirname } from './path.js';
|
|
8
|
-
import { statSync } from './sync.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Base class for file system watchers.
|
|
12
|
-
* Provides event handling capabilities for watching file system changes.
|
|
13
|
-
*
|
|
14
|
-
* @template TEvents The type of events emitted by the watcher.
|
|
15
|
-
*/
|
|
16
|
-
class Watcher<TEvents extends Record<string, unknown[]> = Record<string, unknown[]>> extends EventEmitter<TEvents> implements NodeEventEmitter {
|
|
17
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
18
|
-
public off<T extends EventEmitter.EventNames<TEvents>>(event: T, fn?: (...args: any[]) => void, context?: any, once?: boolean): this {
|
|
19
|
-
return super.off<T>(event, fn as EventEmitter.EventListener<TEvents, T>, context, once);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public removeListener<T extends EventEmitter.EventNames<TEvents>>(event: T, fn?: (...args: any[]) => void, context?: any, once?: boolean): this {
|
|
23
|
-
return super.removeListener<T>(event, fn as EventEmitter.EventListener<TEvents, T>, context, once);
|
|
24
|
-
}
|
|
25
|
-
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
26
|
-
|
|
27
|
-
public constructor(public readonly path: string) {
|
|
28
|
-
super();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public setMaxListeners(): never {
|
|
32
|
-
throw ErrnoError.With('ENOSYS', this.path, 'Watcher.setMaxListeners');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public getMaxListeners(): never {
|
|
36
|
-
throw ErrnoError.With('ENOSYS', this.path, 'Watcher.getMaxListeners');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public prependListener(): never {
|
|
40
|
-
throw ErrnoError.With('ENOSYS', this.path, 'Watcher.prependListener');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public prependOnceListener(): never {
|
|
44
|
-
throw ErrnoError.With('ENOSYS', this.path, 'Watcher.prependOnceListener');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public rawListeners(): never {
|
|
48
|
-
throw ErrnoError.With('ENOSYS', this.path, 'Watcher.rawListeners');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public ref(): this {
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public unref(): this {
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Watches for changes on the file system.
|
|
62
|
-
*
|
|
63
|
-
* @template T The type of the filename, either `string` or `Buffer`.
|
|
64
|
-
*/
|
|
65
|
-
export class FSWatcher<T extends string | Buffer = string | Buffer>
|
|
66
|
-
extends Watcher<{
|
|
67
|
-
change: [eventType: fs.WatchEventType, filename: T];
|
|
68
|
-
close: [];
|
|
69
|
-
error: [error: Error];
|
|
70
|
-
}>
|
|
71
|
-
implements fs.FSWatcher
|
|
72
|
-
{
|
|
73
|
-
public constructor(
|
|
74
|
-
path: string,
|
|
75
|
-
public readonly options: fs.WatchOptions
|
|
76
|
-
) {
|
|
77
|
-
super(path);
|
|
78
|
-
addWatcher(path.toString(), this);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public close(): void {
|
|
82
|
-
super.emit('close');
|
|
83
|
-
removeWatcher(this.path.toString(), this);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public [Symbol.dispose](): void {
|
|
87
|
-
this.close();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Watches for changes to a file's stats.
|
|
93
|
-
*
|
|
94
|
-
* Instances of `StatWatcher` are used by `fs.watchFile()` to monitor changes to a file's statistics.
|
|
95
|
-
*/
|
|
96
|
-
export class StatWatcher
|
|
97
|
-
extends Watcher<{
|
|
98
|
-
change: [current: Stats, previous: Stats];
|
|
99
|
-
close: [];
|
|
100
|
-
error: [error: Error];
|
|
101
|
-
}>
|
|
102
|
-
implements fs.StatWatcher
|
|
103
|
-
{
|
|
104
|
-
private intervalId?: NodeJS.Timeout | number;
|
|
105
|
-
private previous?: Stats;
|
|
106
|
-
|
|
107
|
-
public constructor(
|
|
108
|
-
path: string,
|
|
109
|
-
private options: { persistent?: boolean; interval?: number }
|
|
110
|
-
) {
|
|
111
|
-
super(path);
|
|
112
|
-
this.start();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
protected onInterval() {
|
|
116
|
-
try {
|
|
117
|
-
const current = statSync(this.path);
|
|
118
|
-
if (!isStatsEqual(this.previous!, current)) {
|
|
119
|
-
this.emit('change', current, this.previous!);
|
|
120
|
-
this.previous = current;
|
|
121
|
-
}
|
|
122
|
-
} catch (e) {
|
|
123
|
-
this.emit('error', e as Error);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
protected start() {
|
|
128
|
-
const interval = this.options.interval || 5000;
|
|
129
|
-
try {
|
|
130
|
-
this.previous = statSync(this.path);
|
|
131
|
-
} catch (e) {
|
|
132
|
-
this.emit('error', e as Error);
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
this.intervalId = setInterval(this.onInterval.bind(this), interval);
|
|
136
|
-
if (!this.options.persistent && typeof this.intervalId == 'object') {
|
|
137
|
-
this.intervalId.unref();
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* @internal
|
|
143
|
-
*/
|
|
144
|
-
public stop() {
|
|
145
|
-
if (this.intervalId) {
|
|
146
|
-
clearInterval(this.intervalId);
|
|
147
|
-
this.intervalId = undefined;
|
|
148
|
-
}
|
|
149
|
-
this.removeAllListeners();
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const watchers: Map<string, Set<FSWatcher>> = new Map();
|
|
154
|
-
|
|
155
|
-
export function addWatcher(path: string, watcher: FSWatcher) {
|
|
156
|
-
const normalizedPath = normalizePath(path);
|
|
157
|
-
if (!watchers.has(normalizedPath)) {
|
|
158
|
-
watchers.set(normalizedPath, new Set());
|
|
159
|
-
}
|
|
160
|
-
watchers.get(normalizedPath)!.add(watcher);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export function removeWatcher(path: string, watcher: FSWatcher) {
|
|
164
|
-
const normalizedPath = normalizePath(path);
|
|
165
|
-
if (watchers.has(normalizedPath)) {
|
|
166
|
-
watchers.get(normalizedPath)!.delete(watcher);
|
|
167
|
-
if (watchers.get(normalizedPath)!.size === 0) {
|
|
168
|
-
watchers.delete(normalizedPath);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export function emitChange(eventType: fs.WatchEventType, filename: string) {
|
|
174
|
-
filename = normalizePath(filename);
|
|
175
|
-
// Notify watchers on the specific file
|
|
176
|
-
if (watchers.has(filename)) {
|
|
177
|
-
for (const watcher of watchers.get(filename)!) {
|
|
178
|
-
watcher.emit('change', eventType, basename(filename));
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// Notify watchers on parent directories if they are watching recursively
|
|
183
|
-
let parent = filename,
|
|
184
|
-
normalizedFilename;
|
|
185
|
-
while (parent !== normalizedFilename) {
|
|
186
|
-
normalizedFilename = parent;
|
|
187
|
-
parent = dirname(parent);
|
|
188
|
-
if (watchers.has(parent)) {
|
|
189
|
-
for (const watcher of watchers.get(parent)!) {
|
|
190
|
-
watcher.emit('change', eventType, filename.slice(parent.length + (parent == '/' ? 0 : 1)));
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
package/src/error.ts
DELETED
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Standard libc error codes. More will be added to this enum and error strings as they are
|
|
3
|
-
* needed.
|
|
4
|
-
* @see https://en.wikipedia.org/wiki/Errno.h
|
|
5
|
-
*/
|
|
6
|
-
export enum Errno {
|
|
7
|
-
/** Operation not permitted */
|
|
8
|
-
EPERM = 1,
|
|
9
|
-
/** No such file or directory */
|
|
10
|
-
ENOENT = 2,
|
|
11
|
-
/** Interrupted system call */
|
|
12
|
-
EINTR = 4,
|
|
13
|
-
/** Input/output error */
|
|
14
|
-
EIO = 5,
|
|
15
|
-
/** No such device or address */
|
|
16
|
-
ENXIO = 6,
|
|
17
|
-
/** Bad file descriptor */
|
|
18
|
-
EBADF = 9,
|
|
19
|
-
/** Resource temporarily unavailable */
|
|
20
|
-
EAGAIN = 11,
|
|
21
|
-
/** Cannot allocate memory */
|
|
22
|
-
ENOMEM = 12,
|
|
23
|
-
/** Permission denied */
|
|
24
|
-
EACCES = 13,
|
|
25
|
-
/** Bad address */
|
|
26
|
-
EFAULT = 14,
|
|
27
|
-
/** Block device required */
|
|
28
|
-
ENOTBLK = 15,
|
|
29
|
-
/** Resource busy or locked */
|
|
30
|
-
EBUSY = 16,
|
|
31
|
-
/** File exists */
|
|
32
|
-
EEXIST = 17,
|
|
33
|
-
/** Invalid cross-device link */
|
|
34
|
-
EXDEV = 18,
|
|
35
|
-
/** No such device */
|
|
36
|
-
ENODEV = 19,
|
|
37
|
-
/** File is not a directory */
|
|
38
|
-
ENOTDIR = 20,
|
|
39
|
-
/** File is a directory */
|
|
40
|
-
EISDIR = 21,
|
|
41
|
-
/** Invalid argument */
|
|
42
|
-
EINVAL = 22,
|
|
43
|
-
/** Too many open files in system */
|
|
44
|
-
ENFILE = 23,
|
|
45
|
-
/** Too many open files */
|
|
46
|
-
EMFILE = 24,
|
|
47
|
-
/** Text file busy */
|
|
48
|
-
ETXTBSY = 26,
|
|
49
|
-
/** File is too big */
|
|
50
|
-
EFBIG = 27,
|
|
51
|
-
/** No space left on disk */
|
|
52
|
-
ENOSPC = 28,
|
|
53
|
-
/** Illegal seek */
|
|
54
|
-
ESPIPE = 29,
|
|
55
|
-
/** Cannot modify a read-only file system */
|
|
56
|
-
EROFS = 30,
|
|
57
|
-
/** Too many links */
|
|
58
|
-
EMLINK = 31,
|
|
59
|
-
/** Broken pipe */
|
|
60
|
-
EPIPE = 32,
|
|
61
|
-
/** Numerical argument out of domain */
|
|
62
|
-
EDOM = 33,
|
|
63
|
-
/** Numerical result out of range */
|
|
64
|
-
ERANGE = 34,
|
|
65
|
-
/** Resource deadlock would occur */
|
|
66
|
-
EDEADLK = 35,
|
|
67
|
-
/** File name too long */
|
|
68
|
-
ENAMETOOLONG = 36,
|
|
69
|
-
/** No locks available */
|
|
70
|
-
ENOLCK = 37,
|
|
71
|
-
/** Function not implemented */
|
|
72
|
-
ENOSYS = 38,
|
|
73
|
-
/** Directory is not empty */
|
|
74
|
-
ENOTEMPTY = 39,
|
|
75
|
-
/** Too many levels of symbolic links */
|
|
76
|
-
ELOOP = 40,
|
|
77
|
-
/** No message of desired type */
|
|
78
|
-
ENOMSG = 42,
|
|
79
|
-
/** Invalid exchange */
|
|
80
|
-
EBADE = 52,
|
|
81
|
-
/** Invalid request descriptor */
|
|
82
|
-
EBADR = 53,
|
|
83
|
-
/** Exchange full */
|
|
84
|
-
EXFULL = 54,
|
|
85
|
-
/** No anode */
|
|
86
|
-
ENOANO = 55,
|
|
87
|
-
/** Invalid request code */
|
|
88
|
-
EBADRQC = 56,
|
|
89
|
-
/** Device not a stream */
|
|
90
|
-
ENOSTR = 60,
|
|
91
|
-
/** No data available */
|
|
92
|
-
ENODATA = 61,
|
|
93
|
-
/** Timer expired */
|
|
94
|
-
ETIME = 62,
|
|
95
|
-
/** Out of streams resources */
|
|
96
|
-
ENOSR = 63,
|
|
97
|
-
/** Machine is not on the network */
|
|
98
|
-
ENONET = 64,
|
|
99
|
-
/** Object is remote */
|
|
100
|
-
EREMOTE = 66,
|
|
101
|
-
/** Link has been severed */
|
|
102
|
-
ENOLINK = 67,
|
|
103
|
-
/** Communication error on send */
|
|
104
|
-
ECOMM = 70,
|
|
105
|
-
/** Protocol error */
|
|
106
|
-
EPROTO = 71,
|
|
107
|
-
/** Bad message */
|
|
108
|
-
EBADMSG = 74,
|
|
109
|
-
/** Value too large for defined data type */
|
|
110
|
-
EOVERFLOW = 75,
|
|
111
|
-
/** File descriptor in bad state */
|
|
112
|
-
EBADFD = 77,
|
|
113
|
-
/** Streams pipe error */
|
|
114
|
-
ESTRPIPE = 86,
|
|
115
|
-
/** Socket operation on non-socket */
|
|
116
|
-
ENOTSOCK = 88,
|
|
117
|
-
/** Destination address required */
|
|
118
|
-
EDESTADDRREQ = 89,
|
|
119
|
-
/** Message too long */
|
|
120
|
-
EMSGSIZE = 90,
|
|
121
|
-
/** Protocol wrong type for socket */
|
|
122
|
-
EPROTOTYPE = 91,
|
|
123
|
-
/** Protocol not available */
|
|
124
|
-
ENOPROTOOPT = 92,
|
|
125
|
-
/** Protocol not supported */
|
|
126
|
-
EPROTONOSUPPORT = 93,
|
|
127
|
-
/** Socket type not supported */
|
|
128
|
-
ESOCKTNOSUPPORT = 94,
|
|
129
|
-
/** Operation is not supported */
|
|
130
|
-
ENOTSUP = 95,
|
|
131
|
-
/** Network is down */
|
|
132
|
-
ENETDOWN = 100,
|
|
133
|
-
/** Network is unreachable */
|
|
134
|
-
ENETUNREACH = 101,
|
|
135
|
-
/** Network dropped connection on reset */
|
|
136
|
-
ENETRESET = 102,
|
|
137
|
-
/** Connection timed out */
|
|
138
|
-
ETIMEDOUT = 110,
|
|
139
|
-
/** Connection refused */
|
|
140
|
-
ECONNREFUSED = 111,
|
|
141
|
-
/** Host is down */
|
|
142
|
-
EHOSTDOWN = 112,
|
|
143
|
-
/** No route to host */
|
|
144
|
-
EHOSTUNREACH = 113,
|
|
145
|
-
/** Operation already in progress */
|
|
146
|
-
EALREADY = 114,
|
|
147
|
-
/** Operation now in progress */
|
|
148
|
-
EINPROGRESS = 115,
|
|
149
|
-
/** Stale file handle */
|
|
150
|
-
ESTALE = 116,
|
|
151
|
-
/** Remote I/O error */
|
|
152
|
-
EREMOTEIO = 121,
|
|
153
|
-
/** Disk quota exceeded */
|
|
154
|
-
EDQUOT = 122,
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Strings associated with each error code.
|
|
158
|
-
* @internal
|
|
159
|
-
*/
|
|
160
|
-
export const errorMessages: { [K in Errno]: string } = {
|
|
161
|
-
[Errno.EPERM]: 'Operation not permitted',
|
|
162
|
-
[Errno.ENOENT]: 'No such file or directory',
|
|
163
|
-
[Errno.EINTR]: 'Interrupted system call',
|
|
164
|
-
[Errno.EIO]: 'Input/output error',
|
|
165
|
-
[Errno.ENXIO]: 'No such device or address',
|
|
166
|
-
[Errno.EBADF]: 'Bad file descriptor',
|
|
167
|
-
[Errno.EAGAIN]: 'Resource temporarily unavailable',
|
|
168
|
-
[Errno.ENOMEM]: 'Cannot allocate memory',
|
|
169
|
-
[Errno.EACCES]: 'Permission denied',
|
|
170
|
-
[Errno.EFAULT]: 'Bad address',
|
|
171
|
-
[Errno.ENOTBLK]: 'Block device required',
|
|
172
|
-
[Errno.EBUSY]: 'Resource busy or locked',
|
|
173
|
-
[Errno.EEXIST]: 'File exists',
|
|
174
|
-
[Errno.EXDEV]: 'Invalid cross-device link',
|
|
175
|
-
[Errno.ENODEV]: 'No such device',
|
|
176
|
-
[Errno.ENOTDIR]: 'File is not a directory',
|
|
177
|
-
[Errno.EISDIR]: 'File is a directory',
|
|
178
|
-
[Errno.EINVAL]: 'Invalid argument',
|
|
179
|
-
[Errno.ENFILE]: 'Too many open files in system',
|
|
180
|
-
[Errno.EMFILE]: 'Too many open files',
|
|
181
|
-
[Errno.ETXTBSY]: 'Text file busy',
|
|
182
|
-
[Errno.EFBIG]: 'File is too big',
|
|
183
|
-
[Errno.ENOSPC]: 'No space left on disk',
|
|
184
|
-
[Errno.ESPIPE]: 'Illegal seek',
|
|
185
|
-
[Errno.EROFS]: 'Cannot modify a read-only file system',
|
|
186
|
-
[Errno.EMLINK]: 'Too many links',
|
|
187
|
-
[Errno.EPIPE]: 'Broken pipe',
|
|
188
|
-
[Errno.EDOM]: 'Numerical argument out of domain',
|
|
189
|
-
[Errno.ERANGE]: 'Numerical result out of range',
|
|
190
|
-
[Errno.EDEADLK]: 'Resource deadlock would occur',
|
|
191
|
-
[Errno.ENAMETOOLONG]: 'File name too long',
|
|
192
|
-
[Errno.ENOLCK]: 'No locks available',
|
|
193
|
-
[Errno.ENOSYS]: 'Function not implemented',
|
|
194
|
-
[Errno.ENOTEMPTY]: 'Directory is not empty',
|
|
195
|
-
[Errno.ELOOP]: 'Too many levels of symbolic links',
|
|
196
|
-
[Errno.ENOMSG]: 'No message of desired type',
|
|
197
|
-
[Errno.EBADE]: 'Invalid exchange',
|
|
198
|
-
[Errno.EBADR]: 'Invalid request descriptor',
|
|
199
|
-
[Errno.EXFULL]: 'Exchange full',
|
|
200
|
-
[Errno.ENOANO]: 'No anode',
|
|
201
|
-
[Errno.EBADRQC]: 'Invalid request code',
|
|
202
|
-
[Errno.ENOSTR]: 'Device not a stream',
|
|
203
|
-
[Errno.ENODATA]: 'No data available',
|
|
204
|
-
[Errno.ETIME]: 'Timer expired',
|
|
205
|
-
[Errno.ENOSR]: 'Out of streams resources',
|
|
206
|
-
[Errno.ENONET]: 'Machine is not on the network',
|
|
207
|
-
[Errno.EREMOTE]: 'Object is remote',
|
|
208
|
-
[Errno.ENOLINK]: 'Link has been severed',
|
|
209
|
-
[Errno.ECOMM]: 'Communication error on send',
|
|
210
|
-
[Errno.EPROTO]: 'Protocol error',
|
|
211
|
-
[Errno.EBADMSG]: 'Bad message',
|
|
212
|
-
[Errno.EOVERFLOW]: 'Value too large for defined data type',
|
|
213
|
-
[Errno.EBADFD]: 'File descriptor in bad state',
|
|
214
|
-
[Errno.ESTRPIPE]: 'Streams pipe error',
|
|
215
|
-
[Errno.ENOTSOCK]: 'Socket operation on non-socket',
|
|
216
|
-
[Errno.EDESTADDRREQ]: 'Destination address required',
|
|
217
|
-
[Errno.EMSGSIZE]: 'Message too long',
|
|
218
|
-
[Errno.EPROTOTYPE]: 'Protocol wrong type for socket',
|
|
219
|
-
[Errno.ENOPROTOOPT]: 'Protocol not available',
|
|
220
|
-
[Errno.EPROTONOSUPPORT]: 'Protocol not supported',
|
|
221
|
-
[Errno.ESOCKTNOSUPPORT]: 'Socket type not supported',
|
|
222
|
-
[Errno.ENOTSUP]: 'Operation is not supported',
|
|
223
|
-
[Errno.ENETDOWN]: 'Network is down',
|
|
224
|
-
[Errno.ENETUNREACH]: 'Network is unreachable',
|
|
225
|
-
[Errno.ENETRESET]: 'Network dropped connection on reset',
|
|
226
|
-
[Errno.ETIMEDOUT]: 'Connection timed out',
|
|
227
|
-
[Errno.ECONNREFUSED]: 'Connection refused',
|
|
228
|
-
[Errno.EHOSTDOWN]: 'Host is down',
|
|
229
|
-
[Errno.EHOSTUNREACH]: 'No route to host',
|
|
230
|
-
[Errno.EALREADY]: 'Operation already in progress',
|
|
231
|
-
[Errno.EINPROGRESS]: 'Operation now in progress',
|
|
232
|
-
[Errno.ESTALE]: 'Stale file handle',
|
|
233
|
-
[Errno.EREMOTEIO]: 'Remote I/O error',
|
|
234
|
-
[Errno.EDQUOT]: 'Disk quota exceeded',
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
export interface ErrnoErrorJSON {
|
|
238
|
-
errno: Errno;
|
|
239
|
-
message: string;
|
|
240
|
-
path?: string;
|
|
241
|
-
code: keyof typeof Errno;
|
|
242
|
-
stack: string;
|
|
243
|
-
syscall: string;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* An error with additional information about what happened
|
|
248
|
-
*/
|
|
249
|
-
export class ErrnoError extends Error implements NodeJS.ErrnoException {
|
|
250
|
-
public static fromJSON(json: ErrnoErrorJSON): ErrnoError {
|
|
251
|
-
const err = new ErrnoError(json.errno, json.message, json.path, json.syscall);
|
|
252
|
-
err.code = json.code;
|
|
253
|
-
err.stack = json.stack;
|
|
254
|
-
return err;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
public static With(code: keyof typeof Errno, path?: string, syscall?: string): ErrnoError {
|
|
258
|
-
return new ErrnoError(Errno[code], errorMessages[Errno[code]], path, syscall);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
public code: keyof typeof Errno;
|
|
262
|
-
|
|
263
|
-
public declare stack: string;
|
|
264
|
-
|
|
265
|
-
public constructor(
|
|
266
|
-
/**
|
|
267
|
-
* The kind of error
|
|
268
|
-
*/
|
|
269
|
-
public errno: Errno,
|
|
270
|
-
/**
|
|
271
|
-
* A descriptive error message
|
|
272
|
-
*/
|
|
273
|
-
message: string = errorMessages[errno],
|
|
274
|
-
public path?: string,
|
|
275
|
-
public syscall: string = ''
|
|
276
|
-
) {
|
|
277
|
-
super(message);
|
|
278
|
-
this.code = Errno[errno] as keyof typeof Errno;
|
|
279
|
-
this.message = this.code + ': ' + message + (this.path ? `, '${this.path}'` : '');
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* @returns A friendly error message.
|
|
284
|
-
*/
|
|
285
|
-
public toString(): string {
|
|
286
|
-
return this.message;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
public toJSON(): ErrnoErrorJSON {
|
|
290
|
-
return {
|
|
291
|
-
errno: this.errno,
|
|
292
|
-
code: this.code,
|
|
293
|
-
path: this.path,
|
|
294
|
-
stack: this.stack,
|
|
295
|
-
message: this.message,
|
|
296
|
-
syscall: this.syscall,
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* The size of the API error in buffer-form in bytes.
|
|
302
|
-
*/
|
|
303
|
-
public bufferSize(): number {
|
|
304
|
-
// 4 bytes for string length.
|
|
305
|
-
return 4 + JSON.stringify(this.toJSON()).length;
|
|
306
|
-
}
|
|
307
|
-
}
|