@zenfs/core 0.9.2 → 0.9.3
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/package.json +2 -9
- package/src/ApiError.ts +310 -0
- package/src/backends/AsyncStore.ts +635 -0
- package/src/backends/InMemory.ts +56 -0
- package/src/backends/Index.ts +500 -0
- package/src/backends/Locked.ts +181 -0
- package/src/backends/Overlay.ts +591 -0
- package/src/backends/SyncStore.ts +589 -0
- package/src/backends/backend.ts +152 -0
- package/src/config.ts +101 -0
- package/src/cred.ts +21 -0
- package/src/emulation/async.ts +910 -0
- package/src/emulation/constants.ts +176 -0
- package/src/emulation/dir.ts +139 -0
- package/src/emulation/index.ts +8 -0
- package/src/emulation/path.ts +468 -0
- package/src/emulation/promises.ts +1071 -0
- package/src/emulation/shared.ts +128 -0
- package/src/emulation/streams.ts +33 -0
- package/src/emulation/sync.ts +898 -0
- package/src/file.ts +721 -0
- package/src/filesystem.ts +546 -0
- package/src/index.ts +21 -0
- package/src/inode.ts +229 -0
- package/src/mutex.ts +52 -0
- package/src/stats.ts +385 -0
- package/src/utils.ts +287 -0
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenfs/core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "A filesystem in your browser",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"types": "
|
|
6
|
+
"types": "src/index.ts",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"filesystem",
|
|
9
9
|
"node",
|
|
@@ -35,13 +35,6 @@
|
|
|
35
35
|
"./*": "./dist/*",
|
|
36
36
|
"./promises": "./dist/emulations/promises.js"
|
|
37
37
|
},
|
|
38
|
-
"typesVersions": {
|
|
39
|
-
"*": {
|
|
40
|
-
"*": [
|
|
41
|
-
"./dist/*"
|
|
42
|
-
]
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
38
|
"scripts": {
|
|
46
39
|
"format": "prettier --write .",
|
|
47
40
|
"format:check": "prettier --check .",
|
package/src/ApiError.ts
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard libc error codes. More will be added to this enum and ErrorStrings as they are
|
|
3
|
+
* needed.
|
|
4
|
+
* @url https://en.wikipedia.org/wiki/Errno.h
|
|
5
|
+
*/
|
|
6
|
+
export enum ErrorCode {
|
|
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 ErrorCode]: string } = {
|
|
161
|
+
[ErrorCode.EPERM]: 'Operation not permitted',
|
|
162
|
+
[ErrorCode.ENOENT]: 'No such file or directory',
|
|
163
|
+
[ErrorCode.EINTR]: 'Interrupted system call',
|
|
164
|
+
[ErrorCode.EIO]: 'Input/output error',
|
|
165
|
+
[ErrorCode.ENXIO]: 'No such device or address',
|
|
166
|
+
[ErrorCode.EBADF]: 'Bad file descriptor',
|
|
167
|
+
[ErrorCode.EAGAIN]: 'Resource temporarily unavailable',
|
|
168
|
+
[ErrorCode.ENOMEM]: 'Cannot allocate memory',
|
|
169
|
+
[ErrorCode.EACCES]: 'Permission denied',
|
|
170
|
+
[ErrorCode.EFAULT]: 'Bad address',
|
|
171
|
+
[ErrorCode.ENOTBLK]: 'Block device required',
|
|
172
|
+
[ErrorCode.EBUSY]: 'Resource busy or locked',
|
|
173
|
+
[ErrorCode.EEXIST]: 'File exists',
|
|
174
|
+
[ErrorCode.EXDEV]: 'Invalid cross-device link',
|
|
175
|
+
[ErrorCode.ENODEV]: 'No such device',
|
|
176
|
+
[ErrorCode.ENOTDIR]: 'File is not a directory',
|
|
177
|
+
[ErrorCode.EISDIR]: 'File is a directory',
|
|
178
|
+
[ErrorCode.EINVAL]: 'Invalid argument',
|
|
179
|
+
[ErrorCode.ENFILE]: 'Too many open files in system',
|
|
180
|
+
[ErrorCode.EMFILE]: 'Too many open files',
|
|
181
|
+
[ErrorCode.ETXTBSY]: 'Text file busy',
|
|
182
|
+
[ErrorCode.EFBIG]: 'File is too big',
|
|
183
|
+
[ErrorCode.ENOSPC]: 'No space left on disk',
|
|
184
|
+
[ErrorCode.ESPIPE]: 'Illegal seek',
|
|
185
|
+
[ErrorCode.EROFS]: 'Cannot modify a read-only file system',
|
|
186
|
+
[ErrorCode.EMLINK]: 'Too many links',
|
|
187
|
+
[ErrorCode.EPIPE]: 'Broken pipe',
|
|
188
|
+
[ErrorCode.EDOM]: 'Numerical argument out of domain',
|
|
189
|
+
[ErrorCode.ERANGE]: 'Numerical result out of range',
|
|
190
|
+
[ErrorCode.EDEADLK]: 'Resource deadlock would occur',
|
|
191
|
+
[ErrorCode.ENAMETOOLONG]: 'File name too long',
|
|
192
|
+
[ErrorCode.ENOLCK]: 'No locks available',
|
|
193
|
+
[ErrorCode.ENOSYS]: 'Function not implemented',
|
|
194
|
+
[ErrorCode.ENOTEMPTY]: 'Directory is not empty',
|
|
195
|
+
[ErrorCode.ELOOP]: 'Too many levels of symbolic links',
|
|
196
|
+
[ErrorCode.ENOMSG]: 'No message of desired type',
|
|
197
|
+
[ErrorCode.EBADE]: 'Invalid exchange',
|
|
198
|
+
[ErrorCode.EBADR]: 'Invalid request descriptor',
|
|
199
|
+
[ErrorCode.EXFULL]: 'Exchange full',
|
|
200
|
+
[ErrorCode.ENOANO]: 'No anode',
|
|
201
|
+
[ErrorCode.EBADRQC]: 'Invalid request code',
|
|
202
|
+
[ErrorCode.ENOSTR]: 'Device not a stream',
|
|
203
|
+
[ErrorCode.ENODATA]: 'No data available',
|
|
204
|
+
[ErrorCode.ETIME]: 'Timer expired',
|
|
205
|
+
[ErrorCode.ENOSR]: 'Out of streams resources',
|
|
206
|
+
[ErrorCode.ENONET]: 'Machine is not on the network',
|
|
207
|
+
[ErrorCode.EREMOTE]: 'Object is remote',
|
|
208
|
+
[ErrorCode.ENOLINK]: 'Link has been severed',
|
|
209
|
+
[ErrorCode.ECOMM]: 'Communication error on send',
|
|
210
|
+
[ErrorCode.EPROTO]: 'Protocol error',
|
|
211
|
+
[ErrorCode.EBADMSG]: 'Bad message',
|
|
212
|
+
[ErrorCode.EOVERFLOW]: 'Value too large for defined data type',
|
|
213
|
+
[ErrorCode.EBADFD]: 'File descriptor in bad state',
|
|
214
|
+
[ErrorCode.ESTRPIPE]: 'Streams pipe error',
|
|
215
|
+
[ErrorCode.ENOTSOCK]: 'Socket operation on non-socket',
|
|
216
|
+
[ErrorCode.EDESTADDRREQ]: 'Destination address required',
|
|
217
|
+
[ErrorCode.EMSGSIZE]: 'Message too long',
|
|
218
|
+
[ErrorCode.EPROTOTYPE]: 'Protocol wrong type for socket',
|
|
219
|
+
[ErrorCode.ENOPROTOOPT]: 'Protocol not available',
|
|
220
|
+
[ErrorCode.EPROTONOSUPPORT]: 'Protocol not supported',
|
|
221
|
+
[ErrorCode.ESOCKTNOSUPPORT]: 'Socket type not supported',
|
|
222
|
+
[ErrorCode.ENOTSUP]: 'Operation is not supported',
|
|
223
|
+
[ErrorCode.ENETDOWN]: 'Network is down',
|
|
224
|
+
[ErrorCode.ENETUNREACH]: 'Network is unreachable',
|
|
225
|
+
[ErrorCode.ENETRESET]: 'Network dropped connection on reset',
|
|
226
|
+
[ErrorCode.ETIMEDOUT]: 'Connection timed out',
|
|
227
|
+
[ErrorCode.ECONNREFUSED]: 'Connection refused',
|
|
228
|
+
[ErrorCode.EHOSTDOWN]: 'Host is down',
|
|
229
|
+
[ErrorCode.EHOSTUNREACH]: 'No route to host',
|
|
230
|
+
[ErrorCode.EALREADY]: 'Operation already in progress',
|
|
231
|
+
[ErrorCode.EINPROGRESS]: 'Operation now in progress',
|
|
232
|
+
[ErrorCode.ESTALE]: 'Stale file handle',
|
|
233
|
+
[ErrorCode.EREMOTEIO]: 'Remote I/O error',
|
|
234
|
+
[ErrorCode.EDQUOT]: 'Disk quota exceeded',
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
interface ApiErrorJSON {
|
|
238
|
+
errno: ErrorCode;
|
|
239
|
+
message: string;
|
|
240
|
+
path?: string;
|
|
241
|
+
code: keyof typeof ErrorCode;
|
|
242
|
+
stack: string;
|
|
243
|
+
syscall: string;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Represents a ZenFS error. Passed back to applications after a failed
|
|
248
|
+
* call to the ZenFS API.
|
|
249
|
+
*/
|
|
250
|
+
export class ApiError extends Error implements NodeJS.ErrnoException {
|
|
251
|
+
public static fromJSON(json: ApiErrorJSON): ApiError {
|
|
252
|
+
const err = new ApiError(json.errno, json.message, json.path, json.syscall);
|
|
253
|
+
err.code = json.code;
|
|
254
|
+
err.stack = json.stack;
|
|
255
|
+
return err;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
public static With(code: keyof typeof ErrorCode, path: string, syscall?: string): ApiError {
|
|
259
|
+
return new ApiError(ErrorCode[code], errorMessages[ErrorCode[code]], path, syscall);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
public code: keyof typeof ErrorCode;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Represents a ZenFS error. Passed back to applications after a failed
|
|
266
|
+
* call to the ZenFS API.
|
|
267
|
+
*
|
|
268
|
+
* Error codes mirror those returned by regular Unix file operations, which is
|
|
269
|
+
* what Node returns.
|
|
270
|
+
* @constructor ApiError
|
|
271
|
+
* @param type The type of the error.
|
|
272
|
+
* @param message A descriptive error message.
|
|
273
|
+
*/
|
|
274
|
+
constructor(
|
|
275
|
+
public errno: ErrorCode,
|
|
276
|
+
message: string = errorMessages[errno],
|
|
277
|
+
public path?: string,
|
|
278
|
+
public syscall: string = ''
|
|
279
|
+
) {
|
|
280
|
+
super(message);
|
|
281
|
+
this.code = <keyof typeof ErrorCode>ErrorCode[errno];
|
|
282
|
+
this.message = `${this.code}: ${message}${this.path ? `, '${this.path}'` : ''}`;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* @return A friendly error message.
|
|
287
|
+
*/
|
|
288
|
+
public toString(): string {
|
|
289
|
+
return this.message;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
public toJSON(): ApiErrorJSON {
|
|
293
|
+
return {
|
|
294
|
+
errno: this.errno,
|
|
295
|
+
code: this.code,
|
|
296
|
+
path: this.path,
|
|
297
|
+
stack: this.stack,
|
|
298
|
+
message: this.message,
|
|
299
|
+
syscall: this.syscall,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* The size of the API error in buffer-form in bytes.
|
|
305
|
+
*/
|
|
306
|
+
public bufferSize(): number {
|
|
307
|
+
// 4 bytes for string length.
|
|
308
|
+
return 4 + JSON.stringify(this.toJSON()).length;
|
|
309
|
+
}
|
|
310
|
+
}
|