@bytecodealliance/preview2-shim 0.17.8 → 0.17.9

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.
@@ -1,8 +1,8 @@
1
- import { streams } from './io.js';
2
- import { environment } from './environment.js';
1
+ import { streams } from "./io.js";
2
+ import { environment } from "./environment.js";
3
3
 
4
- import { _setCwd, _getCwd } from './config.js';
5
- export { _setCwd } from './config.js';
4
+ import { _setCwd, _getCwd } from "./config.js";
5
+ export { _setCwd } from "./config.js";
6
6
 
7
7
  const { InputStream, OutputStream } = streams;
8
8
 
@@ -26,319 +26,305 @@ const { InputStream, OutputStream } = streams;
26
26
  */
27
27
 
28
28
  export function _setFileData(fileData) {
29
- _fileData = fileData;
30
- _rootPreopen[0] = new Descriptor(fileData);
31
- const cwd = environment.initialCwd();
32
- _setCwd(cwd || '/');
29
+ _fileData = fileData;
30
+ _rootPreopen[0] = new Descriptor(fileData);
31
+ const cwd = environment.initialCwd();
32
+ _setCwd(cwd || "/");
33
33
  }
34
34
 
35
35
  export function _getFileData() {
36
- return JSON.stringify(_fileData);
36
+ return JSON.stringify(_fileData);
37
37
  }
38
38
 
39
39
  let _fileData = { dir: {} };
40
40
 
41
41
  const timeZero = {
42
- seconds: BigInt(0),
43
- nanoseconds: 0,
42
+ seconds: BigInt(0),
43
+ nanoseconds: 0,
44
44
  };
45
45
 
46
46
  function getChildEntry(parentEntry, subpath, openFlags) {
47
- if (
48
- subpath === '.' &&
49
- _rootPreopen &&
50
- descriptorGetEntry(_rootPreopen[0]) === parentEntry
51
- ) {
52
- subpath = _getCwd();
53
- if (subpath.startsWith('/') && subpath !== '/') {
54
- subpath = subpath.slice(1);
55
- }
56
- }
57
- let entry = parentEntry;
58
- let segmentIdx;
59
- do {
60
- if (!entry || !entry.dir) {
61
- throw 'not-directory';
62
- }
63
- segmentIdx = subpath.indexOf('/');
64
- const segment =
65
- segmentIdx === -1 ? subpath : subpath.slice(0, segmentIdx);
66
- if (segment === '..') {
67
- throw 'no-entry';
68
- }
69
- if (segment === '.' || segment === '') {
70
- } else if (!entry.dir[segment] && openFlags.create) {
71
- entry = entry.dir[segment] = openFlags.directory
72
- ? { dir: {} }
73
- : { source: new Uint8Array([]) };
74
- } else {
75
- entry = entry.dir[segment];
76
- }
77
- subpath = subpath.slice(segmentIdx + 1);
78
- } while (segmentIdx !== -1);
79
- if (!entry) {
80
- throw 'no-entry';
81
- }
82
- return entry;
47
+ if (subpath === "." && _rootPreopen && descriptorGetEntry(_rootPreopen[0]) === parentEntry) {
48
+ subpath = _getCwd();
49
+ if (subpath.startsWith("/") && subpath !== "/") {
50
+ subpath = subpath.slice(1);
51
+ }
52
+ }
53
+ let entry = parentEntry;
54
+ let segmentIdx;
55
+ do {
56
+ if (!entry || !entry.dir) {
57
+ throw "not-directory";
58
+ }
59
+ segmentIdx = subpath.indexOf("/");
60
+ const segment = segmentIdx === -1 ? subpath : subpath.slice(0, segmentIdx);
61
+ if (segment === "..") {
62
+ throw "no-entry";
63
+ }
64
+ if (segment === "." || segment === "") {
65
+ } else if (!entry.dir[segment] && openFlags.create) {
66
+ entry = entry.dir[segment] = openFlags.directory
67
+ ? { dir: {} }
68
+ : { source: new Uint8Array([]) };
69
+ } else {
70
+ entry = entry.dir[segment];
71
+ }
72
+ subpath = subpath.slice(segmentIdx + 1);
73
+ } while (segmentIdx !== -1);
74
+ if (!entry) {
75
+ throw "no-entry";
76
+ }
77
+ return entry;
83
78
  }
84
79
 
85
80
  function getSource(fileEntry) {
86
- if (typeof fileEntry.source === 'string') {
87
- fileEntry.source = new TextEncoder().encode(fileEntry.source);
88
- }
89
- return fileEntry.source;
81
+ if (typeof fileEntry.source === "string") {
82
+ fileEntry.source = new TextEncoder().encode(fileEntry.source);
83
+ }
84
+ return fileEntry.source;
90
85
  }
91
86
 
92
87
  class DirectoryEntryStream {
93
- constructor(entries) {
94
- this.idx = 0;
95
- this.entries = entries;
96
- }
97
- readDirectoryEntry() {
98
- if (this.idx === this.entries.length) {
99
- return null;
100
- }
101
- const [name, entry] = this.entries[this.idx];
102
- this.idx += 1;
103
- return {
104
- name,
105
- type: entry.dir ? 'directory' : 'regular-file',
106
- };
107
- }
88
+ constructor(entries) {
89
+ this.idx = 0;
90
+ this.entries = entries;
91
+ }
92
+ readDirectoryEntry() {
93
+ if (this.idx === this.entries.length) {
94
+ return null;
95
+ }
96
+ const [name, entry] = this.entries[this.idx];
97
+ this.idx += 1;
98
+ return {
99
+ name,
100
+ type: entry.dir ? "directory" : "regular-file",
101
+ };
102
+ }
108
103
  }
109
104
 
110
105
  class Descriptor {
111
- #stream;
112
- #entry;
113
- #mtime = 0;
114
-
115
- _getEntry(descriptor) {
116
- return descriptor.#entry;
117
- }
118
-
119
- constructor(entry, isStream) {
120
- if (isStream) {
121
- this.#stream = entry;
122
- } else {
123
- this.#entry = entry;
124
- }
125
- }
126
-
127
- readViaStream(_offset) {
128
- const source = getSource(this.#entry);
129
- let offset = Number(_offset);
130
- return new InputStream({
131
- blockingRead(len) {
132
- if (offset === source.byteLength) {
133
- throw { tag: 'closed' };
134
- }
135
- const bytes = source.slice(offset, offset + Number(len));
136
- offset += bytes.byteLength;
137
- return bytes;
138
- },
139
- });
140
- }
141
-
142
- writeViaStream(_offset) {
143
- const entry = this.#entry;
144
- let offset = Number(_offset);
145
- return new OutputStream({
146
- write(buf) {
147
- const newSource = new Uint8Array(
148
- buf.byteLength + entry.source.byteLength
149
- );
150
- newSource.set(entry.source, 0);
151
- newSource.set(buf, offset);
152
- offset += buf.byteLength;
153
- entry.source = newSource;
154
- return buf.byteLength;
155
- },
156
- });
157
- }
158
-
159
- appendViaStream() {
160
- console.log(`[filesystem] APPEND STREAM`);
161
- }
162
-
163
- advise(descriptor, offset, length, advice) {
164
- console.log(`[filesystem] ADVISE`, descriptor, offset, length, advice);
165
- }
166
-
167
- syncData() {
168
- console.log(`[filesystem] SYNC DATA`);
169
- }
170
-
171
- getFlags() {
172
- console.log(`[filesystem] FLAGS FOR`);
173
- }
174
-
175
- getType() {
176
- if (this.#stream) {
177
- return 'fifo';
178
- }
179
- if (this.#entry.dir) {
180
- return 'directory';
181
- }
182
- if (this.#entry.source) {
183
- return 'regular-file';
184
- }
185
- return 'unknown';
186
- }
187
-
188
- setSize(size) {
189
- console.log(`[filesystem] SET SIZE`, size);
190
- }
191
-
192
- setTimes(dataAccessTimestamp, dataModificationTimestamp) {
193
- console.log(
194
- `[filesystem] SET TIMES`,
195
- dataAccessTimestamp,
196
- dataModificationTimestamp
197
- );
198
- }
199
-
200
- read(length, offset) {
201
- const source = getSource(this.#entry);
202
- return [
203
- source.slice(offset, offset + length),
204
- offset + length >= source.byteLength,
205
- ];
206
- }
207
-
208
- write(buffer, offset) {
209
- if (offset !== 0) {
210
- throw 'invalid-seek';
211
- }
212
- this.#entry.source = buffer;
213
- return buffer.byteLength;
214
- }
215
-
216
- readDirectory() {
217
- if (!this.#entry?.dir) {
218
- throw 'bad-descriptor';
219
- }
220
- return new DirectoryEntryStream(
221
- Object.entries(this.#entry.dir).sort(([a], [b]) => (a > b ? 1 : -1))
222
- );
223
- }
224
-
225
- sync() {
226
- console.log(`[filesystem] SYNC`);
227
- }
228
-
229
- createDirectoryAt(path) {
230
- const entry = getChildEntry(this.#entry, path, {
231
- create: true,
232
- directory: true,
233
- });
234
- if (entry.source) {
235
- throw 'exist';
236
- }
237
- }
238
-
239
- stat() {
240
- let type = 'unknown',
241
- size = BigInt(0);
242
- if (this.#entry.source) {
243
- type = 'regular-file';
244
- const source = getSource(this.#entry);
245
- size = BigInt(source.byteLength);
246
- } else if (this.#entry.dir) {
247
- type = 'directory';
106
+ #stream;
107
+ #entry;
108
+ #mtime = 0;
109
+
110
+ _getEntry(descriptor) {
111
+ return descriptor.#entry;
112
+ }
113
+
114
+ constructor(entry, isStream) {
115
+ if (isStream) {
116
+ this.#stream = entry;
117
+ } else {
118
+ this.#entry = entry;
119
+ }
120
+ }
121
+
122
+ readViaStream(_offset) {
123
+ const source = getSource(this.#entry);
124
+ let offset = Number(_offset);
125
+ return new InputStream({
126
+ blockingRead(len) {
127
+ if (offset === source.byteLength) {
128
+ throw { tag: "closed" };
248
129
  }
249
- return {
250
- type,
251
- linkCount: BigInt(0),
252
- size,
253
- dataAccessTimestamp: timeZero,
254
- dataModificationTimestamp: timeZero,
255
- statusChangeTimestamp: timeZero,
256
- };
257
- }
258
-
259
- statAt(_pathFlags, path) {
260
- const entry = getChildEntry(this.#entry, path, {
261
- create: false,
262
- directory: false,
263
- });
264
- let type = 'unknown',
265
- size = BigInt(0);
266
- if (entry.source) {
267
- type = 'regular-file';
268
- const source = getSource(entry);
269
- size = BigInt(source.byteLength);
270
- } else if (entry.dir) {
271
- type = 'directory';
272
- }
273
- return {
274
- type,
275
- linkCount: BigInt(0),
276
- size,
277
- dataAccessTimestamp: timeZero,
278
- dataModificationTimestamp: timeZero,
279
- statusChangeTimestamp: timeZero,
280
- };
281
- }
282
-
283
- setTimesAt() {
284
- console.log(`[filesystem] SET TIMES AT`);
285
- }
286
-
287
- linkAt() {
288
- console.log(`[filesystem] LINK AT`);
289
- }
290
-
291
- openAt(_pathFlags, path, openFlags, _descriptorFlags, _modes) {
292
- const childEntry = getChildEntry(this.#entry, path, openFlags);
293
- return new Descriptor(childEntry);
294
- }
295
-
296
- readlinkAt() {
297
- console.log(`[filesystem] READLINK AT`);
298
- }
299
-
300
- removeDirectoryAt() {
301
- console.log(`[filesystem] REMOVE DIR AT`);
302
- }
303
-
304
- renameAt() {
305
- console.log(`[filesystem] RENAME AT`);
306
- }
307
-
308
- symlinkAt() {
309
- console.log(`[filesystem] SYMLINK AT`);
310
- }
311
-
312
- unlinkFileAt() {
313
- console.log(`[filesystem] UNLINK FILE AT`);
314
- }
315
-
316
- isSameObject(other) {
317
- return other === this;
318
- }
319
-
320
- metadataHash() {
321
- let upper = BigInt(0);
322
- upper += BigInt(this.#mtime);
323
- return { upper, lower: BigInt(0) };
324
- }
325
-
326
- metadataHashAt(_pathFlags, _path) {
327
- let upper = BigInt(0);
328
- upper += BigInt(this.#mtime);
329
- return { upper, lower: BigInt(0) };
330
- }
130
+ const bytes = source.slice(offset, offset + Number(len));
131
+ offset += bytes.byteLength;
132
+ return bytes;
133
+ },
134
+ });
135
+ }
136
+
137
+ writeViaStream(_offset) {
138
+ const entry = this.#entry;
139
+ let offset = Number(_offset);
140
+ return new OutputStream({
141
+ write(buf) {
142
+ const newSource = new Uint8Array(buf.byteLength + entry.source.byteLength);
143
+ newSource.set(entry.source, 0);
144
+ newSource.set(buf, offset);
145
+ offset += buf.byteLength;
146
+ entry.source = newSource;
147
+ return buf.byteLength;
148
+ },
149
+ });
150
+ }
151
+
152
+ appendViaStream() {
153
+ console.log(`[filesystem] APPEND STREAM`);
154
+ }
155
+
156
+ advise(descriptor, offset, length, advice) {
157
+ console.log(`[filesystem] ADVISE`, descriptor, offset, length, advice);
158
+ }
159
+
160
+ syncData() {
161
+ console.log(`[filesystem] SYNC DATA`);
162
+ }
163
+
164
+ getFlags() {
165
+ console.log(`[filesystem] FLAGS FOR`);
166
+ }
167
+
168
+ getType() {
169
+ if (this.#stream) {
170
+ return "fifo";
171
+ }
172
+ if (this.#entry.dir) {
173
+ return "directory";
174
+ }
175
+ if (this.#entry.source) {
176
+ return "regular-file";
177
+ }
178
+ return "unknown";
179
+ }
180
+
181
+ setSize(size) {
182
+ console.log(`[filesystem] SET SIZE`, size);
183
+ }
184
+
185
+ setTimes(dataAccessTimestamp, dataModificationTimestamp) {
186
+ console.log(`[filesystem] SET TIMES`, dataAccessTimestamp, dataModificationTimestamp);
187
+ }
188
+
189
+ read(length, offset) {
190
+ const source = getSource(this.#entry);
191
+ return [source.slice(offset, offset + length), offset + length >= source.byteLength];
192
+ }
193
+
194
+ write(buffer, offset) {
195
+ if (offset !== 0) {
196
+ throw "invalid-seek";
197
+ }
198
+ this.#entry.source = buffer;
199
+ return buffer.byteLength;
200
+ }
201
+
202
+ readDirectory() {
203
+ if (!this.#entry?.dir) {
204
+ throw "bad-descriptor";
205
+ }
206
+ return new DirectoryEntryStream(
207
+ Object.entries(this.#entry.dir).sort(([a], [b]) => (a > b ? 1 : -1)),
208
+ );
209
+ }
210
+
211
+ sync() {
212
+ console.log(`[filesystem] SYNC`);
213
+ }
214
+
215
+ createDirectoryAt(path) {
216
+ const entry = getChildEntry(this.#entry, path, {
217
+ create: true,
218
+ directory: true,
219
+ });
220
+ if (entry.source) {
221
+ throw "exist";
222
+ }
223
+ }
224
+
225
+ stat() {
226
+ let type = "unknown",
227
+ size = BigInt(0);
228
+ if (this.#entry.source) {
229
+ type = "regular-file";
230
+ const source = getSource(this.#entry);
231
+ size = BigInt(source.byteLength);
232
+ } else if (this.#entry.dir) {
233
+ type = "directory";
234
+ }
235
+ return {
236
+ type,
237
+ linkCount: BigInt(0),
238
+ size,
239
+ dataAccessTimestamp: timeZero,
240
+ dataModificationTimestamp: timeZero,
241
+ statusChangeTimestamp: timeZero,
242
+ };
243
+ }
244
+
245
+ statAt(_pathFlags, path) {
246
+ const entry = getChildEntry(this.#entry, path, {
247
+ create: false,
248
+ directory: false,
249
+ });
250
+ let type = "unknown",
251
+ size = BigInt(0);
252
+ if (entry.source) {
253
+ type = "regular-file";
254
+ const source = getSource(entry);
255
+ size = BigInt(source.byteLength);
256
+ } else if (entry.dir) {
257
+ type = "directory";
258
+ }
259
+ return {
260
+ type,
261
+ linkCount: BigInt(0),
262
+ size,
263
+ dataAccessTimestamp: timeZero,
264
+ dataModificationTimestamp: timeZero,
265
+ statusChangeTimestamp: timeZero,
266
+ };
267
+ }
268
+
269
+ setTimesAt() {
270
+ console.log(`[filesystem] SET TIMES AT`);
271
+ }
272
+
273
+ linkAt() {
274
+ console.log(`[filesystem] LINK AT`);
275
+ }
276
+
277
+ openAt(_pathFlags, path, openFlags, _descriptorFlags, _modes) {
278
+ const childEntry = getChildEntry(this.#entry, path, openFlags);
279
+ return new Descriptor(childEntry);
280
+ }
281
+
282
+ readlinkAt() {
283
+ console.log(`[filesystem] READLINK AT`);
284
+ }
285
+
286
+ removeDirectoryAt() {
287
+ console.log(`[filesystem] REMOVE DIR AT`);
288
+ }
289
+
290
+ renameAt() {
291
+ console.log(`[filesystem] RENAME AT`);
292
+ }
293
+
294
+ symlinkAt() {
295
+ console.log(`[filesystem] SYMLINK AT`);
296
+ }
297
+
298
+ unlinkFileAt() {
299
+ console.log(`[filesystem] UNLINK FILE AT`);
300
+ }
301
+
302
+ isSameObject(other) {
303
+ return other === this;
304
+ }
305
+
306
+ metadataHash() {
307
+ let upper = BigInt(0);
308
+ upper += BigInt(this.#mtime);
309
+ return { upper, lower: BigInt(0) };
310
+ }
311
+
312
+ metadataHashAt(_pathFlags, _path) {
313
+ let upper = BigInt(0);
314
+ upper += BigInt(this.#mtime);
315
+ return { upper, lower: BigInt(0) };
316
+ }
331
317
  }
332
318
  const descriptorGetEntry = Descriptor.prototype._getEntry;
333
319
  delete Descriptor.prototype._getEntry;
334
320
 
335
- let _preopens = [[new Descriptor(_fileData), '/']],
336
- _rootPreopen = _preopens[0];
321
+ let _preopens = [[new Descriptor(_fileData), "/"]],
322
+ _rootPreopen = _preopens[0];
337
323
 
338
324
  export const preopens = {
339
- getDirectories() {
340
- return _preopens;
341
- },
325
+ getDirectories() {
326
+ return _preopens;
327
+ },
342
328
  };
343
329
 
344
330
  /**
@@ -346,10 +332,10 @@ export const preopens = {
346
332
  * @param {Record<string, FileData>} preopensConfig - Map of virtual paths to file data entries
347
333
  */
348
334
  export function _setPreopens(preopensConfig) {
349
- _preopens = [];
350
- for (const [virtualPath, fileData] of Object.entries(preopensConfig)) {
351
- _addPreopen(virtualPath, fileData);
352
- }
335
+ _preopens = [];
336
+ for (const [virtualPath, fileData] of Object.entries(preopensConfig)) {
337
+ _addPreopen(virtualPath, fileData);
338
+ }
353
339
  }
354
340
 
355
341
  /**
@@ -358,22 +344,22 @@ export function _setPreopens(preopensConfig) {
358
344
  * @param {FileData} fileData - The file data object representing the directory
359
345
  */
360
346
  export function _addPreopen(virtualPath, fileData) {
361
- const descriptor = new Descriptor(fileData);
362
- _preopens.push([descriptor, virtualPath]);
363
- if (virtualPath === '/') {
364
- _rootPreopen = [descriptor, virtualPath];
365
- }
347
+ const descriptor = new Descriptor(fileData);
348
+ _preopens.push([descriptor, virtualPath]);
349
+ if (virtualPath === "/") {
350
+ _rootPreopen = [descriptor, virtualPath];
351
+ }
366
352
  }
367
353
 
368
354
  /**
369
355
  * Clear all preopens, giving the guest no filesystem access.
370
- *
356
+ *
371
357
  * This functionality exists mostly to maintain backwards compatibility. Prefer setting preopens
372
358
  * via `WASIShim` rather than making top level changes to preopens using these functions.
373
359
  */
374
360
  export function _clearPreopens() {
375
- _preopens = [];
376
- _rootPreopen = null;
361
+ _preopens = [];
362
+ _rootPreopen = null;
377
363
  }
378
364
 
379
365
  /**
@@ -381,7 +367,7 @@ export function _clearPreopens() {
381
367
  * @returns {Array<[Descriptor, string]>} Array of [descriptor, virtualPath] pairs
382
368
  */
383
369
  export function _getPreopens() {
384
- return [..._preopens];
370
+ return [..._preopens];
385
371
  }
386
372
 
387
373
  /**
@@ -391,109 +377,109 @@ export function _getPreopens() {
391
377
  * @returns {Descriptor} A preopen descriptor
392
378
  */
393
379
  export function _createPreopenDescriptor(fileData) {
394
- return new Descriptor(fileData);
380
+ return new Descriptor(fileData);
395
381
  }
396
382
 
397
383
  export const types = {
398
- Descriptor,
399
- DirectoryEntryStream,
400
- filesystemErrorCode(err) {
401
- return convertFsError(err.payload);
402
- },
384
+ Descriptor,
385
+ DirectoryEntryStream,
386
+ filesystemErrorCode(err) {
387
+ return convertFsError(err.payload);
388
+ },
403
389
  };
404
390
 
405
391
  function convertFsError(e) {
406
- switch (e.code) {
407
- case 'EACCES':
408
- return 'access';
409
- case 'EAGAIN':
410
- case 'EWOULDBLOCK':
411
- return 'would-block';
412
- case 'EALREADY':
413
- return 'already';
414
- case 'EBADF':
415
- return 'bad-descriptor';
416
- case 'EBUSY':
417
- return 'busy';
418
- case 'EDEADLK':
419
- return 'deadlock';
420
- case 'EDQUOT':
421
- return 'quota';
422
- case 'EEXIST':
423
- return 'exist';
424
- case 'EFBIG':
425
- return 'file-too-large';
426
- case 'EILSEQ':
427
- return 'illegal-byte-sequence';
428
- case 'EINPROGRESS':
429
- return 'in-progress';
430
- case 'EINTR':
431
- return 'interrupted';
432
- case 'EINVAL':
433
- return 'invalid';
434
- case 'EIO':
435
- return 'io';
436
- case 'EISDIR':
437
- return 'is-directory';
438
- case 'ELOOP':
439
- return 'loop';
440
- case 'EMLINK':
441
- return 'too-many-links';
442
- case 'EMSGSIZE':
443
- return 'message-size';
444
- case 'ENAMETOOLONG':
445
- return 'name-too-long';
446
- case 'ENODEV':
447
- return 'no-device';
448
- case 'ENOENT':
449
- return 'no-entry';
450
- case 'ENOLCK':
451
- return 'no-lock';
452
- case 'ENOMEM':
453
- return 'insufficient-memory';
454
- case 'ENOSPC':
455
- return 'insufficient-space';
456
- case 'ENOTDIR':
457
- case 'ERR_FS_EISDIR':
458
- return 'not-directory';
459
- case 'ENOTEMPTY':
460
- return 'not-empty';
461
- case 'ENOTRECOVERABLE':
462
- return 'not-recoverable';
463
- case 'ENOTSUP':
464
- return 'unsupported';
465
- case 'ENOTTY':
466
- return 'no-tty';
467
- // windows gives this error for badly structured `//` reads
468
- // this seems like a slightly better error than unknown given
469
- // that it's a common footgun
392
+ switch (e.code) {
393
+ case "EACCES":
394
+ return "access";
395
+ case "EAGAIN":
396
+ case "EWOULDBLOCK":
397
+ return "would-block";
398
+ case "EALREADY":
399
+ return "already";
400
+ case "EBADF":
401
+ return "bad-descriptor";
402
+ case "EBUSY":
403
+ return "busy";
404
+ case "EDEADLK":
405
+ return "deadlock";
406
+ case "EDQUOT":
407
+ return "quota";
408
+ case "EEXIST":
409
+ return "exist";
410
+ case "EFBIG":
411
+ return "file-too-large";
412
+ case "EILSEQ":
413
+ return "illegal-byte-sequence";
414
+ case "EINPROGRESS":
415
+ return "in-progress";
416
+ case "EINTR":
417
+ return "interrupted";
418
+ case "EINVAL":
419
+ return "invalid";
420
+ case "EIO":
421
+ return "io";
422
+ case "EISDIR":
423
+ return "is-directory";
424
+ case "ELOOP":
425
+ return "loop";
426
+ case "EMLINK":
427
+ return "too-many-links";
428
+ case "EMSGSIZE":
429
+ return "message-size";
430
+ case "ENAMETOOLONG":
431
+ return "name-too-long";
432
+ case "ENODEV":
433
+ return "no-device";
434
+ case "ENOENT":
435
+ return "no-entry";
436
+ case "ENOLCK":
437
+ return "no-lock";
438
+ case "ENOMEM":
439
+ return "insufficient-memory";
440
+ case "ENOSPC":
441
+ return "insufficient-space";
442
+ case "ENOTDIR":
443
+ case "ERR_FS_EISDIR":
444
+ return "not-directory";
445
+ case "ENOTEMPTY":
446
+ return "not-empty";
447
+ case "ENOTRECOVERABLE":
448
+ return "not-recoverable";
449
+ case "ENOTSUP":
450
+ return "unsupported";
451
+ case "ENOTTY":
452
+ return "no-tty";
453
+ // windows gives this error for badly structured `//` reads
454
+ // this seems like a slightly better error than unknown given
455
+ // that it's a common footgun
470
456
  case -4094:
471
- case 'ENXIO':
472
- return 'no-such-device';
473
- case 'EOVERFLOW':
474
- return 'overflow';
475
- case 'EPERM':
476
- return 'not-permitted';
477
- case 'EPIPE':
478
- return 'pipe';
479
- case 'EROFS':
480
- return 'read-only';
481
- case 'ESPIPE':
482
- return 'invalid-seek';
483
- case 'ETXTBSY':
484
- return 'text-file-busy';
485
- case 'EXDEV':
486
- return 'cross-device';
487
- case 'UNKNOWN':
488
- switch (e.errno) {
457
+ case "ENXIO":
458
+ return "no-such-device";
459
+ case "EOVERFLOW":
460
+ return "overflow";
461
+ case "EPERM":
462
+ return "not-permitted";
463
+ case "EPIPE":
464
+ return "pipe";
465
+ case "EROFS":
466
+ return "read-only";
467
+ case "ESPIPE":
468
+ return "invalid-seek";
469
+ case "ETXTBSY":
470
+ return "text-file-busy";
471
+ case "EXDEV":
472
+ return "cross-device";
473
+ case "UNKNOWN":
474
+ switch (e.errno) {
489
475
  case -4094:
490
- return 'no-such-device';
476
+ return "no-such-device";
491
477
  default:
492
- throw e;
493
- }
478
+ throw e;
479
+ }
494
480
  default:
495
- throw e;
496
- }
481
+ throw e;
482
+ }
497
483
  }
498
484
 
499
485
  export { types as filesystemTypes };