@zenfs/core 1.11.4 → 2.1.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.
Files changed (135) hide show
  1. package/dist/backends/backend.d.ts +19 -15
  2. package/dist/backends/backend.js +36 -19
  3. package/dist/backends/cow.d.ts +20 -30
  4. package/dist/backends/cow.js +83 -192
  5. package/dist/backends/fetch.d.ts +1 -0
  6. package/dist/backends/fetch.js +30 -30
  7. package/dist/backends/index.d.ts +1 -1
  8. package/dist/backends/index.js +1 -1
  9. package/dist/backends/memory.d.ts +5 -7
  10. package/dist/backends/memory.js +2 -3
  11. package/dist/backends/passthrough.d.ts +19 -23
  12. package/dist/backends/passthrough.js +98 -288
  13. package/dist/backends/port.d.ts +220 -0
  14. package/dist/backends/port.js +328 -0
  15. package/dist/backends/single_buffer.d.ts +59 -47
  16. package/dist/backends/single_buffer.js +468 -219
  17. package/dist/backends/store/fs.d.ts +25 -35
  18. package/dist/backends/store/fs.js +276 -315
  19. package/dist/backends/store/store.d.ts +10 -15
  20. package/dist/backends/store/store.js +11 -10
  21. package/dist/config.d.ts +3 -12
  22. package/dist/config.js +17 -19
  23. package/dist/context.d.ts +8 -21
  24. package/dist/context.js +33 -10
  25. package/dist/index.d.ts +2 -1
  26. package/dist/index.js +2 -1
  27. package/dist/internal/contexts.d.ts +63 -0
  28. package/dist/internal/contexts.js +15 -0
  29. package/dist/internal/credentials.d.ts +2 -11
  30. package/dist/internal/credentials.js +0 -19
  31. package/dist/internal/devices.d.ts +18 -80
  32. package/dist/internal/devices.js +103 -316
  33. package/dist/internal/error.d.ts +9 -204
  34. package/dist/internal/error.js +19 -288
  35. package/dist/internal/file_index.d.ts +1 -1
  36. package/dist/internal/file_index.js +11 -11
  37. package/dist/internal/filesystem.d.ts +51 -94
  38. package/dist/internal/filesystem.js +21 -20
  39. package/dist/internal/index.d.ts +1 -2
  40. package/dist/internal/index.js +1 -2
  41. package/dist/internal/index_fs.d.ts +12 -30
  42. package/dist/internal/index_fs.js +37 -69
  43. package/dist/internal/inode.d.ts +140 -24
  44. package/dist/internal/inode.js +515 -66
  45. package/dist/mixins/async.js +52 -112
  46. package/dist/mixins/mutexed.d.ts +19 -18
  47. package/dist/mixins/mutexed.js +62 -64
  48. package/dist/mixins/readonly.d.ts +7 -6
  49. package/dist/mixins/readonly.js +24 -18
  50. package/dist/mixins/sync.js +8 -8
  51. package/dist/{vfs/path.d.ts → path.d.ts} +3 -4
  52. package/dist/{vfs/path.js → path.js} +6 -9
  53. package/dist/polyfills.js +1 -1
  54. package/dist/readline.d.ts +134 -0
  55. package/dist/readline.js +623 -0
  56. package/dist/utils.d.ts +9 -37
  57. package/dist/utils.js +17 -85
  58. package/dist/vfs/acl.d.ts +42 -0
  59. package/dist/vfs/acl.js +268 -0
  60. package/dist/vfs/async.d.ts +9 -23
  61. package/dist/vfs/async.js +25 -27
  62. package/dist/vfs/config.d.ts +6 -18
  63. package/dist/vfs/config.js +8 -18
  64. package/dist/vfs/dir.d.ts +3 -3
  65. package/dist/vfs/dir.js +12 -12
  66. package/dist/vfs/file.d.ts +106 -0
  67. package/dist/vfs/file.js +244 -0
  68. package/dist/vfs/flags.d.ts +19 -0
  69. package/dist/vfs/flags.js +62 -0
  70. package/dist/vfs/index.d.ts +4 -10
  71. package/dist/vfs/index.js +4 -13
  72. package/dist/vfs/ioctl.d.ts +88 -0
  73. package/dist/vfs/ioctl.js +409 -0
  74. package/dist/vfs/promises.d.ts +81 -19
  75. package/dist/vfs/promises.js +404 -288
  76. package/dist/vfs/shared.d.ts +7 -37
  77. package/dist/vfs/shared.js +29 -85
  78. package/dist/{stats.d.ts → vfs/stats.d.ts} +14 -28
  79. package/dist/{stats.js → vfs/stats.js} +11 -66
  80. package/dist/vfs/streams.d.ts +1 -0
  81. package/dist/vfs/streams.js +32 -27
  82. package/dist/vfs/sync.d.ts +3 -3
  83. package/dist/vfs/sync.js +263 -260
  84. package/dist/vfs/watchers.d.ts +2 -2
  85. package/dist/vfs/watchers.js +12 -12
  86. package/dist/vfs/xattr.d.ts +116 -0
  87. package/dist/vfs/xattr.js +201 -0
  88. package/package.json +5 -3
  89. package/readme.md +1 -1
  90. package/scripts/test.js +2 -2
  91. package/tests/assignment.ts +1 -1
  92. package/tests/backend/config.worker.js +4 -1
  93. package/tests/backend/fetch.test.ts +3 -0
  94. package/tests/backend/port.test.ts +19 -33
  95. package/tests/backend/remote.worker.js +4 -1
  96. package/tests/backend/single-buffer.test.ts +53 -0
  97. package/tests/backend/single-buffer.worker.js +30 -0
  98. package/tests/common/context.test.ts +3 -3
  99. package/tests/common/handle.test.ts +17 -12
  100. package/tests/common/mutex.test.ts +9 -9
  101. package/tests/common/path.test.ts +1 -1
  102. package/tests/common/readline.test.ts +104 -0
  103. package/tests/common.ts +4 -19
  104. package/tests/fetch/fetch.ts +2 -2
  105. package/tests/fs/append.test.ts +4 -4
  106. package/tests/fs/directory.test.ts +25 -25
  107. package/tests/fs/errors.test.ts +15 -19
  108. package/tests/fs/links.test.ts +4 -3
  109. package/tests/fs/open.test.ts +4 -21
  110. package/tests/fs/permissions.test.ts +14 -18
  111. package/tests/fs/read.test.ts +10 -9
  112. package/tests/fs/readFile.test.ts +10 -26
  113. package/tests/fs/rename.test.ts +4 -9
  114. package/tests/fs/stat.test.ts +8 -8
  115. package/tests/fs/streams.test.ts +2 -11
  116. package/tests/fs/times.test.ts +7 -7
  117. package/tests/fs/truncate.test.ts +8 -36
  118. package/tests/fs/watch.test.ts +10 -10
  119. package/tests/fs/write.test.ts +77 -13
  120. package/tests/fs/xattr.test.ts +85 -0
  121. package/tests/logs.js +22 -0
  122. package/tests/setup/context.ts +1 -1
  123. package/tests/setup/index.ts +3 -3
  124. package/tests/setup/port.ts +7 -1
  125. package/dist/backends/port/fs.d.ts +0 -84
  126. package/dist/backends/port/fs.js +0 -151
  127. package/dist/backends/port/rpc.d.ts +0 -77
  128. package/dist/backends/port/rpc.js +0 -100
  129. package/dist/backends/store/simple.d.ts +0 -20
  130. package/dist/backends/store/simple.js +0 -13
  131. package/dist/internal/file.d.ts +0 -359
  132. package/dist/internal/file.js +0 -751
  133. package/dist/internal/log.d.ts +0 -133
  134. package/dist/internal/log.js +0 -218
  135. package/tests/fs/writeFile.test.ts +0 -70
@@ -1,213 +1,18 @@
1
+ import { Exception, type ExceptionJSON } from 'kerium';
1
2
  /**
2
- * Standard libc error codes. More will be added to this enum and error strings as they are
3
- * needed.
3
+ * @deprecated Use {@link ExceptionJSON} instead
4
4
  * @category Internals
5
- * @see https://en.wikipedia.org/wiki/Errno.h
6
5
  */
7
- export declare enum Errno {
8
- /** Operation not permitted */
9
- EPERM = 1,
10
- /** No such file or directory */
11
- ENOENT = 2,
12
- /** Interrupted system call */
13
- EINTR = 4,
14
- /** Input/output error */
15
- EIO = 5,
16
- /** No such device or address */
17
- ENXIO = 6,
18
- /** Bad file descriptor */
19
- EBADF = 9,
20
- /** Resource temporarily unavailable */
21
- EAGAIN = 11,
22
- /** Cannot allocate memory */
23
- ENOMEM = 12,
24
- /** Permission denied */
25
- EACCES = 13,
26
- /** Bad address */
27
- EFAULT = 14,
28
- /** Block device required */
29
- ENOTBLK = 15,
30
- /** Resource busy or locked */
31
- EBUSY = 16,
32
- /** File exists */
33
- EEXIST = 17,
34
- /** Invalid cross-device link */
35
- EXDEV = 18,
36
- /** No such device */
37
- ENODEV = 19,
38
- /** File is not a directory */
39
- ENOTDIR = 20,
40
- /** File is a directory */
41
- EISDIR = 21,
42
- /** Invalid argument */
43
- EINVAL = 22,
44
- /** Too many open files in system */
45
- ENFILE = 23,
46
- /** Too many open files */
47
- EMFILE = 24,
48
- /** Text file busy */
49
- ETXTBSY = 26,
50
- /** File is too big */
51
- EFBIG = 27,
52
- /** No space left on disk */
53
- ENOSPC = 28,
54
- /** Illegal seek */
55
- ESPIPE = 29,
56
- /** Cannot modify a read-only file system */
57
- EROFS = 30,
58
- /** Too many links */
59
- EMLINK = 31,
60
- /** Broken pipe */
61
- EPIPE = 32,
62
- /** Numerical argument out of domain */
63
- EDOM = 33,
64
- /** Numerical result out of range */
65
- ERANGE = 34,
66
- /** Resource deadlock would occur */
67
- EDEADLK = 35,
68
- /** File name too long */
69
- ENAMETOOLONG = 36,
70
- /** No locks available */
71
- ENOLCK = 37,
72
- /** Function not implemented */
73
- ENOSYS = 38,
74
- /** Directory is not empty */
75
- ENOTEMPTY = 39,
76
- /** Too many levels of symbolic links */
77
- ELOOP = 40,
78
- /** No message of desired type */
79
- ENOMSG = 42,
80
- /** Invalid exchange */
81
- EBADE = 52,
82
- /** Invalid request descriptor */
83
- EBADR = 53,
84
- /** Exchange full */
85
- EXFULL = 54,
86
- /** No anode */
87
- ENOANO = 55,
88
- /** Invalid request code */
89
- EBADRQC = 56,
90
- /** Device not a stream */
91
- ENOSTR = 60,
92
- /** No data available */
93
- ENODATA = 61,
94
- /** Timer expired */
95
- ETIME = 62,
96
- /** Out of streams resources */
97
- ENOSR = 63,
98
- /** Machine is not on the network */
99
- ENONET = 64,
100
- /** Object is remote */
101
- EREMOTE = 66,
102
- /** Link has been severed */
103
- ENOLINK = 67,
104
- /** Communication error on send */
105
- ECOMM = 70,
106
- /** Protocol error */
107
- EPROTO = 71,
108
- /** Bad message */
109
- EBADMSG = 74,
110
- /** Value too large for defined data type */
111
- EOVERFLOW = 75,
112
- /** File descriptor in bad state */
113
- EBADFD = 77,
114
- /** Streams pipe error */
115
- ESTRPIPE = 86,
116
- /** Socket operation on non-socket */
117
- ENOTSOCK = 88,
118
- /** Destination address required */
119
- EDESTADDRREQ = 89,
120
- /** Message too long */
121
- EMSGSIZE = 90,
122
- /** Protocol wrong type for socket */
123
- EPROTOTYPE = 91,
124
- /** Protocol not available */
125
- ENOPROTOOPT = 92,
126
- /** Protocol not supported */
127
- EPROTONOSUPPORT = 93,
128
- /** Socket type not supported */
129
- ESOCKTNOSUPPORT = 94,
130
- /** Operation is not supported */
131
- ENOTSUP = 95,
132
- /** Network is down */
133
- ENETDOWN = 100,
134
- /** Network is unreachable */
135
- ENETUNREACH = 101,
136
- /** Network dropped connection on reset */
137
- ENETRESET = 102,
138
- /** Connection timed out */
139
- ETIMEDOUT = 110,
140
- /** Connection refused */
141
- ECONNREFUSED = 111,
142
- /** Host is down */
143
- EHOSTDOWN = 112,
144
- /** No route to host */
145
- EHOSTUNREACH = 113,
146
- /** Operation already in progress */
147
- EALREADY = 114,
148
- /** Operation now in progress */
149
- EINPROGRESS = 115,
150
- /** Stale file handle */
151
- ESTALE = 116,
152
- /** Remote I/O error */
153
- EREMOTEIO = 121,
154
- /** Disk quota exceeded */
155
- EDQUOT = 122
156
- }
6
+ export type ErrnoErrorJSON = ExceptionJSON;
157
7
  /**
158
- * Strings associated with each error code.
8
+ * @deprecated Use {@link Exception} instead
159
9
  * @category Internals
160
- * @internal
161
10
  */
162
- export declare const errorMessages: {
163
- [K in Errno]: string;
164
- };
11
+ export declare const ErrnoError: typeof Exception;
165
12
  /**
13
+ * @deprecated Use {@link Exception} instead
166
14
  * @category Internals
167
15
  */
168
- export interface ErrnoErrorJSON {
169
- errno: Errno;
170
- message: string;
171
- path?: string;
172
- code: keyof typeof Errno;
173
- stack: string;
174
- syscall: string;
175
- }
176
- /**
177
- * An error with additional information about what happened
178
- * @category Internals
179
- */
180
- export declare class ErrnoError extends Error implements NodeJS.ErrnoException {
181
- /**
182
- * The kind of error
183
- */
184
- errno: Errno;
185
- /**
186
- * A descriptive error message
187
- */
188
- message: string;
189
- path?: string | undefined;
190
- syscall: string;
191
- static fromJSON(json: ErrnoErrorJSON): ErrnoError;
192
- static With(code: keyof typeof Errno, path?: string, syscall?: string): ErrnoError;
193
- code: keyof typeof Errno;
194
- stack: string;
195
- constructor(
196
- /**
197
- * The kind of error
198
- */
199
- errno: Errno,
200
- /**
201
- * A descriptive error message
202
- */
203
- message?: string, path?: string | undefined, syscall?: string);
204
- /**
205
- * @returns A friendly error message.
206
- */
207
- toString(): string;
208
- toJSON(): ErrnoErrorJSON;
209
- /**
210
- * The size of the API error in buffer-form in bytes.
211
- */
212
- bufferSize(): number;
213
- }
16
+ export type ErrnoError = Exception;
17
+ export declare function withPath<E extends Exception>(e: E, path: string): E;
18
+ export declare function wrap<const FS, const Prop extends keyof FS & string>(fs: FS, prop: Prop, path: string, dest?: string): FS[Prop];
@@ -1,292 +1,23 @@
1
+ import { Exception, setUVMessage } from 'kerium';
1
2
  /**
2
- * Standard libc error codes. More will be added to this enum and error strings as they are
3
- * needed.
3
+ * @deprecated Use {@link Exception} instead
4
4
  * @category Internals
5
- * @see https://en.wikipedia.org/wiki/Errno.h
6
5
  */
7
- export var Errno;
8
- (function (Errno) {
9
- /** Operation not permitted */
10
- Errno[Errno["EPERM"] = 1] = "EPERM";
11
- /** No such file or directory */
12
- Errno[Errno["ENOENT"] = 2] = "ENOENT";
13
- /** Interrupted system call */
14
- Errno[Errno["EINTR"] = 4] = "EINTR";
15
- /** Input/output error */
16
- Errno[Errno["EIO"] = 5] = "EIO";
17
- /** No such device or address */
18
- Errno[Errno["ENXIO"] = 6] = "ENXIO";
19
- /** Bad file descriptor */
20
- Errno[Errno["EBADF"] = 9] = "EBADF";
21
- /** Resource temporarily unavailable */
22
- Errno[Errno["EAGAIN"] = 11] = "EAGAIN";
23
- /** Cannot allocate memory */
24
- Errno[Errno["ENOMEM"] = 12] = "ENOMEM";
25
- /** Permission denied */
26
- Errno[Errno["EACCES"] = 13] = "EACCES";
27
- /** Bad address */
28
- Errno[Errno["EFAULT"] = 14] = "EFAULT";
29
- /** Block device required */
30
- Errno[Errno["ENOTBLK"] = 15] = "ENOTBLK";
31
- /** Resource busy or locked */
32
- Errno[Errno["EBUSY"] = 16] = "EBUSY";
33
- /** File exists */
34
- Errno[Errno["EEXIST"] = 17] = "EEXIST";
35
- /** Invalid cross-device link */
36
- Errno[Errno["EXDEV"] = 18] = "EXDEV";
37
- /** No such device */
38
- Errno[Errno["ENODEV"] = 19] = "ENODEV";
39
- /** File is not a directory */
40
- Errno[Errno["ENOTDIR"] = 20] = "ENOTDIR";
41
- /** File is a directory */
42
- Errno[Errno["EISDIR"] = 21] = "EISDIR";
43
- /** Invalid argument */
44
- Errno[Errno["EINVAL"] = 22] = "EINVAL";
45
- /** Too many open files in system */
46
- Errno[Errno["ENFILE"] = 23] = "ENFILE";
47
- /** Too many open files */
48
- Errno[Errno["EMFILE"] = 24] = "EMFILE";
49
- /** Text file busy */
50
- Errno[Errno["ETXTBSY"] = 26] = "ETXTBSY";
51
- /** File is too big */
52
- Errno[Errno["EFBIG"] = 27] = "EFBIG";
53
- /** No space left on disk */
54
- Errno[Errno["ENOSPC"] = 28] = "ENOSPC";
55
- /** Illegal seek */
56
- Errno[Errno["ESPIPE"] = 29] = "ESPIPE";
57
- /** Cannot modify a read-only file system */
58
- Errno[Errno["EROFS"] = 30] = "EROFS";
59
- /** Too many links */
60
- Errno[Errno["EMLINK"] = 31] = "EMLINK";
61
- /** Broken pipe */
62
- Errno[Errno["EPIPE"] = 32] = "EPIPE";
63
- /** Numerical argument out of domain */
64
- Errno[Errno["EDOM"] = 33] = "EDOM";
65
- /** Numerical result out of range */
66
- Errno[Errno["ERANGE"] = 34] = "ERANGE";
67
- /** Resource deadlock would occur */
68
- Errno[Errno["EDEADLK"] = 35] = "EDEADLK";
69
- /** File name too long */
70
- Errno[Errno["ENAMETOOLONG"] = 36] = "ENAMETOOLONG";
71
- /** No locks available */
72
- Errno[Errno["ENOLCK"] = 37] = "ENOLCK";
73
- /** Function not implemented */
74
- Errno[Errno["ENOSYS"] = 38] = "ENOSYS";
75
- /** Directory is not empty */
76
- Errno[Errno["ENOTEMPTY"] = 39] = "ENOTEMPTY";
77
- /** Too many levels of symbolic links */
78
- Errno[Errno["ELOOP"] = 40] = "ELOOP";
79
- /** No message of desired type */
80
- Errno[Errno["ENOMSG"] = 42] = "ENOMSG";
81
- /** Invalid exchange */
82
- Errno[Errno["EBADE"] = 52] = "EBADE";
83
- /** Invalid request descriptor */
84
- Errno[Errno["EBADR"] = 53] = "EBADR";
85
- /** Exchange full */
86
- Errno[Errno["EXFULL"] = 54] = "EXFULL";
87
- /** No anode */
88
- Errno[Errno["ENOANO"] = 55] = "ENOANO";
89
- /** Invalid request code */
90
- Errno[Errno["EBADRQC"] = 56] = "EBADRQC";
91
- /** Device not a stream */
92
- Errno[Errno["ENOSTR"] = 60] = "ENOSTR";
93
- /** No data available */
94
- Errno[Errno["ENODATA"] = 61] = "ENODATA";
95
- /** Timer expired */
96
- Errno[Errno["ETIME"] = 62] = "ETIME";
97
- /** Out of streams resources */
98
- Errno[Errno["ENOSR"] = 63] = "ENOSR";
99
- /** Machine is not on the network */
100
- Errno[Errno["ENONET"] = 64] = "ENONET";
101
- /** Object is remote */
102
- Errno[Errno["EREMOTE"] = 66] = "EREMOTE";
103
- /** Link has been severed */
104
- Errno[Errno["ENOLINK"] = 67] = "ENOLINK";
105
- /** Communication error on send */
106
- Errno[Errno["ECOMM"] = 70] = "ECOMM";
107
- /** Protocol error */
108
- Errno[Errno["EPROTO"] = 71] = "EPROTO";
109
- /** Bad message */
110
- Errno[Errno["EBADMSG"] = 74] = "EBADMSG";
111
- /** Value too large for defined data type */
112
- Errno[Errno["EOVERFLOW"] = 75] = "EOVERFLOW";
113
- /** File descriptor in bad state */
114
- Errno[Errno["EBADFD"] = 77] = "EBADFD";
115
- /** Streams pipe error */
116
- Errno[Errno["ESTRPIPE"] = 86] = "ESTRPIPE";
117
- /** Socket operation on non-socket */
118
- Errno[Errno["ENOTSOCK"] = 88] = "ENOTSOCK";
119
- /** Destination address required */
120
- Errno[Errno["EDESTADDRREQ"] = 89] = "EDESTADDRREQ";
121
- /** Message too long */
122
- Errno[Errno["EMSGSIZE"] = 90] = "EMSGSIZE";
123
- /** Protocol wrong type for socket */
124
- Errno[Errno["EPROTOTYPE"] = 91] = "EPROTOTYPE";
125
- /** Protocol not available */
126
- Errno[Errno["ENOPROTOOPT"] = 92] = "ENOPROTOOPT";
127
- /** Protocol not supported */
128
- Errno[Errno["EPROTONOSUPPORT"] = 93] = "EPROTONOSUPPORT";
129
- /** Socket type not supported */
130
- Errno[Errno["ESOCKTNOSUPPORT"] = 94] = "ESOCKTNOSUPPORT";
131
- /** Operation is not supported */
132
- Errno[Errno["ENOTSUP"] = 95] = "ENOTSUP";
133
- /** Network is down */
134
- Errno[Errno["ENETDOWN"] = 100] = "ENETDOWN";
135
- /** Network is unreachable */
136
- Errno[Errno["ENETUNREACH"] = 101] = "ENETUNREACH";
137
- /** Network dropped connection on reset */
138
- Errno[Errno["ENETRESET"] = 102] = "ENETRESET";
139
- /** Connection timed out */
140
- Errno[Errno["ETIMEDOUT"] = 110] = "ETIMEDOUT";
141
- /** Connection refused */
142
- Errno[Errno["ECONNREFUSED"] = 111] = "ECONNREFUSED";
143
- /** Host is down */
144
- Errno[Errno["EHOSTDOWN"] = 112] = "EHOSTDOWN";
145
- /** No route to host */
146
- Errno[Errno["EHOSTUNREACH"] = 113] = "EHOSTUNREACH";
147
- /** Operation already in progress */
148
- Errno[Errno["EALREADY"] = 114] = "EALREADY";
149
- /** Operation now in progress */
150
- Errno[Errno["EINPROGRESS"] = 115] = "EINPROGRESS";
151
- /** Stale file handle */
152
- Errno[Errno["ESTALE"] = 116] = "ESTALE";
153
- /** Remote I/O error */
154
- Errno[Errno["EREMOTEIO"] = 121] = "EREMOTEIO";
155
- /** Disk quota exceeded */
156
- Errno[Errno["EDQUOT"] = 122] = "EDQUOT";
157
- })(Errno || (Errno = {}));
158
- /**
159
- * Strings associated with each error code.
160
- * @category Internals
161
- * @internal
162
- */
163
- export const errorMessages = {
164
- [Errno.EPERM]: 'Operation not permitted',
165
- [Errno.ENOENT]: 'No such file or directory',
166
- [Errno.EINTR]: 'Interrupted system call',
167
- [Errno.EIO]: 'Input/output error',
168
- [Errno.ENXIO]: 'No such device or address',
169
- [Errno.EBADF]: 'Bad file descriptor',
170
- [Errno.EAGAIN]: 'Resource temporarily unavailable',
171
- [Errno.ENOMEM]: 'Cannot allocate memory',
172
- [Errno.EACCES]: 'Permission denied',
173
- [Errno.EFAULT]: 'Bad address',
174
- [Errno.ENOTBLK]: 'Block device required',
175
- [Errno.EBUSY]: 'Resource busy or locked',
176
- [Errno.EEXIST]: 'File exists',
177
- [Errno.EXDEV]: 'Invalid cross-device link',
178
- [Errno.ENODEV]: 'No such device',
179
- [Errno.ENOTDIR]: 'File is not a directory',
180
- [Errno.EISDIR]: 'File is a directory',
181
- [Errno.EINVAL]: 'Invalid argument',
182
- [Errno.ENFILE]: 'Too many open files in system',
183
- [Errno.EMFILE]: 'Too many open files',
184
- [Errno.ETXTBSY]: 'Text file busy',
185
- [Errno.EFBIG]: 'File is too big',
186
- [Errno.ENOSPC]: 'No space left on disk',
187
- [Errno.ESPIPE]: 'Illegal seek',
188
- [Errno.EROFS]: 'Cannot modify a read-only file system',
189
- [Errno.EMLINK]: 'Too many links',
190
- [Errno.EPIPE]: 'Broken pipe',
191
- [Errno.EDOM]: 'Numerical argument out of domain',
192
- [Errno.ERANGE]: 'Numerical result out of range',
193
- [Errno.EDEADLK]: 'Resource deadlock would occur',
194
- [Errno.ENAMETOOLONG]: 'File name too long',
195
- [Errno.ENOLCK]: 'No locks available',
196
- [Errno.ENOSYS]: 'Function not implemented',
197
- [Errno.ENOTEMPTY]: 'Directory is not empty',
198
- [Errno.ELOOP]: 'Too many levels of symbolic links',
199
- [Errno.ENOMSG]: 'No message of desired type',
200
- [Errno.EBADE]: 'Invalid exchange',
201
- [Errno.EBADR]: 'Invalid request descriptor',
202
- [Errno.EXFULL]: 'Exchange full',
203
- [Errno.ENOANO]: 'No anode',
204
- [Errno.EBADRQC]: 'Invalid request code',
205
- [Errno.ENOSTR]: 'Device not a stream',
206
- [Errno.ENODATA]: 'No data available',
207
- [Errno.ETIME]: 'Timer expired',
208
- [Errno.ENOSR]: 'Out of streams resources',
209
- [Errno.ENONET]: 'Machine is not on the network',
210
- [Errno.EREMOTE]: 'Object is remote',
211
- [Errno.ENOLINK]: 'Link has been severed',
212
- [Errno.ECOMM]: 'Communication error on send',
213
- [Errno.EPROTO]: 'Protocol error',
214
- [Errno.EBADMSG]: 'Bad message',
215
- [Errno.EOVERFLOW]: 'Value too large for defined data type',
216
- [Errno.EBADFD]: 'File descriptor in bad state',
217
- [Errno.ESTRPIPE]: 'Streams pipe error',
218
- [Errno.ENOTSOCK]: 'Socket operation on non-socket',
219
- [Errno.EDESTADDRREQ]: 'Destination address required',
220
- [Errno.EMSGSIZE]: 'Message too long',
221
- [Errno.EPROTOTYPE]: 'Protocol wrong type for socket',
222
- [Errno.ENOPROTOOPT]: 'Protocol not available',
223
- [Errno.EPROTONOSUPPORT]: 'Protocol not supported',
224
- [Errno.ESOCKTNOSUPPORT]: 'Socket type not supported',
225
- [Errno.ENOTSUP]: 'Operation is not supported',
226
- [Errno.ENETDOWN]: 'Network is down',
227
- [Errno.ENETUNREACH]: 'Network is unreachable',
228
- [Errno.ENETRESET]: 'Network dropped connection on reset',
229
- [Errno.ETIMEDOUT]: 'Connection timed out',
230
- [Errno.ECONNREFUSED]: 'Connection refused',
231
- [Errno.EHOSTDOWN]: 'Host is down',
232
- [Errno.EHOSTUNREACH]: 'No route to host',
233
- [Errno.EALREADY]: 'Operation already in progress',
234
- [Errno.EINPROGRESS]: 'Operation now in progress',
235
- [Errno.ESTALE]: 'Stale file handle',
236
- [Errno.EREMOTEIO]: 'Remote I/O error',
237
- [Errno.EDQUOT]: 'Disk quota exceeded',
238
- };
239
- /**
240
- * An error with additional information about what happened
241
- * @category Internals
242
- */
243
- export class ErrnoError extends Error {
244
- static fromJSON(json) {
245
- const err = new ErrnoError(json.errno, json.message, json.path, json.syscall);
246
- err.code = json.code;
247
- err.stack = json.stack;
248
- return err;
249
- }
250
- static With(code, path, syscall) {
251
- return new ErrnoError(Errno[code], errorMessages[Errno[code]], path, syscall);
252
- }
253
- constructor(
254
- /**
255
- * The kind of error
256
- */
257
- errno,
258
- /**
259
- * A descriptive error message
260
- */
261
- message = errorMessages[errno], path, syscall = '') {
262
- super(message);
263
- this.errno = errno;
264
- this.message = message;
265
- this.path = path;
266
- this.syscall = syscall;
267
- this.code = Errno[errno];
268
- }
269
- /**
270
- * @returns A friendly error message.
271
- */
272
- toString() {
273
- return this.code + ': ' + this.message + (this.path ? `, '${this.path}'` : '');
274
- }
275
- toJSON() {
276
- return {
277
- errno: this.errno,
278
- code: this.code,
279
- path: this.path,
280
- stack: this.stack,
281
- message: this.message,
282
- syscall: this.syscall,
283
- };
284
- }
285
- /**
286
- * The size of the API error in buffer-form in bytes.
287
- */
288
- bufferSize() {
289
- // 4 bytes for string length.
290
- return 4 + JSON.stringify(this.toJSON()).length;
291
- }
6
+ export const ErrnoError = Exception;
7
+ export function withPath(e, path) {
8
+ e.path = path;
9
+ return e;
10
+ }
11
+ export function wrap(fs, prop, path, dest) {
12
+ const fn = fs[prop];
13
+ if (typeof fn !== 'function')
14
+ throw new TypeError(`${prop} is not a function`);
15
+ return function (...args) {
16
+ try {
17
+ return fn.call(fs, ...args);
18
+ }
19
+ catch (e) {
20
+ throw setUVMessage(Object.assign(e, { path, dest, syscall: prop.endsWith('Sync') ? prop.slice(0, -4) : prop }));
21
+ }
22
+ };
292
23
  }
@@ -1,6 +1,6 @@
1
+ import type { UsageInfo } from './filesystem.js';
1
2
  import type { InodeLike } from './inode.js';
2
3
  import { Inode } from './inode.js';
3
- import type { UsageInfo } from './filesystem.js';
4
4
  /**
5
5
  * An Index in JSON form
6
6
  * @internal
@@ -1,9 +1,10 @@
1
1
  /* Note: this file is named file_index.ts because Typescript has special behavior regarding index.ts which can't be disabled. */
2
- import { isJSON, randomInt, sizeof } from 'utilium';
2
+ import { withErrno } from 'kerium';
3
+ import { sizeof } from 'memium';
4
+ import { isJSON, randomInt } from 'utilium';
5
+ import { basename, dirname } from '../path.js';
3
6
  import { S_IFDIR, S_IFMT, size_max } from '../vfs/constants.js';
4
- import { basename, dirname } from '../vfs/path.js';
5
- import { Errno, ErrnoError } from './error.js';
6
- import { __inode_sz, Inode } from './inode.js';
7
+ import { Inode } from './inode.js';
7
8
  export const version = 1;
8
9
  /**
9
10
  * An index of file metadata
@@ -35,7 +36,7 @@ export class Index extends Map {
35
36
  * Get the size in bytes of the index (including the size reported for each entry)
36
37
  */
37
38
  get byteSize() {
38
- let size = this.size * __inode_sz;
39
+ let size = this.size * sizeof(Inode);
39
40
  for (const entry of this.values())
40
41
  size += entry.size;
41
42
  return size;
@@ -65,9 +66,9 @@ export class Index extends Map {
65
66
  directoryEntries(path) {
66
67
  const node = this.get(path);
67
68
  if (!node)
68
- throw ErrnoError.With('ENOENT', path);
69
+ throw withErrno('ENOENT');
69
70
  if ((node.mode & S_IFMT) != S_IFDIR)
70
- throw ErrnoError.With('ENOTDIR', path);
71
+ throw withErrno('ENOTDIR');
71
72
  const entries = {};
72
73
  for (const entry of this.keys()) {
73
74
  if (dirname(entry) == path && entry != path) {
@@ -106,9 +107,8 @@ export class Index extends Map {
106
107
  */
107
108
  fromJSON(json) {
108
109
  var _a;
109
- if (json.version != version) {
110
- throw new ErrnoError(Errno.EINVAL, 'Index version mismatch');
111
- }
110
+ if (json.version != version)
111
+ throw withErrno('EINVAL', 'Index version mismatch');
112
112
  this.clear();
113
113
  for (const [path, node] of Object.entries(json.entries)) {
114
114
  (_a = node.data) !== null && _a !== void 0 ? _a : (node.data = randomInt(1, size_max));
@@ -123,7 +123,7 @@ export class Index extends Map {
123
123
  */
124
124
  static parse(data) {
125
125
  if (!isJSON(data))
126
- throw new ErrnoError(Errno.EINVAL, 'Invalid JSON');
126
+ throw withErrno('EINVAL', 'Invalid JSON');
127
127
  const json = JSON.parse(data);
128
128
  const index = new Index();
129
129
  index.fromJSON(json);