@kubb/core 0.37.30 → 0.38.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.
@@ -22,6 +22,10 @@ var kubb = (function (exports) {
22
22
  return to;
23
23
  };
24
24
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
+ // If the importer is in node compatibility mode or this is not an ESM
26
+ // file that has been converted to a CommonJS file using a Babel-
27
+ // compatible transform (i.e. "__esModule" has not been set), then set
28
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
29
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
30
  mod
27
31
  ));
@@ -117,6 +121,7 @@ var kubb = (function (exports) {
117
121
  return dir + sep + base;
118
122
  }
119
123
  var posix = {
124
+ // path.resolve([from ...], to)
120
125
  resolve: function resolve() {
121
126
  var resolvedPath = "";
122
127
  var resolvedAbsolute = false;
@@ -370,7 +375,9 @@ var kubb = (function (exports) {
370
375
  preDotState = -1;
371
376
  }
372
377
  }
373
- if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
378
+ if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot
379
+ preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
380
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
374
381
  return "";
375
382
  }
376
383
  return path.slice(startDot, end);
@@ -423,7 +430,9 @@ var kubb = (function (exports) {
423
430
  preDotState = -1;
424
431
  }
425
432
  }
426
- if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
433
+ if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot
434
+ preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
435
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
427
436
  if (end !== -1) {
428
437
  if (startPart === 0 && isAbsolute)
429
438
  ret.base = ret.name = path.slice(1, end);
@@ -542,65 +551,68 @@ var kubb = (function (exports) {
542
551
  var S_IFLNK = constants_1.constants.S_IFLNK;
543
552
  var S_IFIFO = constants_1.constants.S_IFIFO;
544
553
  var S_IFSOCK = constants_1.constants.S_IFSOCK;
545
- var Stats = function() {
546
- function Stats2() {
547
- }
548
- Stats2.build = function(node, bigint) {
549
- if (bigint === void 0) {
550
- bigint = false;
551
- }
552
- var stats = new Stats2();
553
- var uid = node.uid, gid = node.gid, atime = node.atime, mtime = node.mtime, ctime = node.ctime;
554
- var getStatNumber = !bigint ? function(number) {
555
- return number;
556
- } : getBigInt_1.default;
557
- stats.uid = getStatNumber(uid);
558
- stats.gid = getStatNumber(gid);
559
- stats.rdev = getStatNumber(0);
560
- stats.blksize = getStatNumber(4096);
561
- stats.ino = getStatNumber(node.ino);
562
- stats.size = getStatNumber(node.getSize());
563
- stats.blocks = getStatNumber(1);
564
- stats.atime = atime;
565
- stats.mtime = mtime;
566
- stats.ctime = ctime;
567
- stats.birthtime = ctime;
568
- stats.atimeMs = getStatNumber(atime.getTime());
569
- stats.mtimeMs = getStatNumber(mtime.getTime());
570
- var ctimeMs = getStatNumber(ctime.getTime());
571
- stats.ctimeMs = ctimeMs;
572
- stats.birthtimeMs = ctimeMs;
573
- stats.dev = getStatNumber(0);
574
- stats.mode = getStatNumber(node.mode);
575
- stats.nlink = getStatNumber(node.nlink);
576
- return stats;
577
- };
578
- Stats2.prototype._checkModeProperty = function(property) {
579
- return (Number(this.mode) & S_IFMT) === property;
580
- };
581
- Stats2.prototype.isDirectory = function() {
582
- return this._checkModeProperty(S_IFDIR);
583
- };
584
- Stats2.prototype.isFile = function() {
585
- return this._checkModeProperty(S_IFREG);
586
- };
587
- Stats2.prototype.isBlockDevice = function() {
588
- return this._checkModeProperty(S_IFBLK);
589
- };
590
- Stats2.prototype.isCharacterDevice = function() {
591
- return this._checkModeProperty(S_IFCHR);
592
- };
593
- Stats2.prototype.isSymbolicLink = function() {
594
- return this._checkModeProperty(S_IFLNK);
595
- };
596
- Stats2.prototype.isFIFO = function() {
597
- return this._checkModeProperty(S_IFIFO);
598
- };
599
- Stats2.prototype.isSocket = function() {
600
- return this._checkModeProperty(S_IFSOCK);
601
- };
602
- return Stats2;
603
- }();
554
+ var Stats = (
555
+ /** @class */
556
+ function() {
557
+ function Stats2() {
558
+ }
559
+ Stats2.build = function(node, bigint) {
560
+ if (bigint === void 0) {
561
+ bigint = false;
562
+ }
563
+ var stats = new Stats2();
564
+ var uid = node.uid, gid = node.gid, atime = node.atime, mtime = node.mtime, ctime = node.ctime;
565
+ var getStatNumber = !bigint ? function(number) {
566
+ return number;
567
+ } : getBigInt_1.default;
568
+ stats.uid = getStatNumber(uid);
569
+ stats.gid = getStatNumber(gid);
570
+ stats.rdev = getStatNumber(0);
571
+ stats.blksize = getStatNumber(4096);
572
+ stats.ino = getStatNumber(node.ino);
573
+ stats.size = getStatNumber(node.getSize());
574
+ stats.blocks = getStatNumber(1);
575
+ stats.atime = atime;
576
+ stats.mtime = mtime;
577
+ stats.ctime = ctime;
578
+ stats.birthtime = ctime;
579
+ stats.atimeMs = getStatNumber(atime.getTime());
580
+ stats.mtimeMs = getStatNumber(mtime.getTime());
581
+ var ctimeMs = getStatNumber(ctime.getTime());
582
+ stats.ctimeMs = ctimeMs;
583
+ stats.birthtimeMs = ctimeMs;
584
+ stats.dev = getStatNumber(0);
585
+ stats.mode = getStatNumber(node.mode);
586
+ stats.nlink = getStatNumber(node.nlink);
587
+ return stats;
588
+ };
589
+ Stats2.prototype._checkModeProperty = function(property) {
590
+ return (Number(this.mode) & S_IFMT) === property;
591
+ };
592
+ Stats2.prototype.isDirectory = function() {
593
+ return this._checkModeProperty(S_IFDIR);
594
+ };
595
+ Stats2.prototype.isFile = function() {
596
+ return this._checkModeProperty(S_IFREG);
597
+ };
598
+ Stats2.prototype.isBlockDevice = function() {
599
+ return this._checkModeProperty(S_IFBLK);
600
+ };
601
+ Stats2.prototype.isCharacterDevice = function() {
602
+ return this._checkModeProperty(S_IFCHR);
603
+ };
604
+ Stats2.prototype.isSymbolicLink = function() {
605
+ return this._checkModeProperty(S_IFLNK);
606
+ };
607
+ Stats2.prototype.isFIFO = function() {
608
+ return this._checkModeProperty(S_IFIFO);
609
+ };
610
+ Stats2.prototype.isSocket = function() {
611
+ return this._checkModeProperty(S_IFSOCK);
612
+ };
613
+ return Stats2;
614
+ }()
615
+ );
604
616
  exports.Stats = Stats;
605
617
  exports.default = Stats;
606
618
  }
@@ -1843,7 +1855,8 @@ var kubb = (function (exports) {
1843
1855
  if (first === void 0 || last === void 0) {
1844
1856
  boundsError(offset, this.length - 8);
1845
1857
  }
1846
- const val = (first << 24) + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
1858
+ const val = (first << 24) + // Overflow
1859
+ this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
1847
1860
  return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last);
1848
1861
  });
1849
1862
  Buffer2.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
@@ -2742,6 +2755,7 @@ var kubb = (function (exports) {
2742
2755
  "%encodeURIComponent%": encodeURIComponent,
2743
2756
  "%Error%": Error,
2744
2757
  "%eval%": eval,
2758
+ // eslint-disable-line no-eval
2745
2759
  "%EvalError%": EvalError,
2746
2760
  "%Float32Array%": typeof Float32Array === "undefined" ? undefined2 : Float32Array,
2747
2761
  "%Float64Array%": typeof Float64Array === "undefined" ? undefined2 : Float64Array,
@@ -3881,6 +3895,7 @@ var kubb = (function (exports) {
3881
3895
  "null": "bold",
3882
3896
  "string": "green",
3883
3897
  "date": "magenta",
3898
+ // "name": intentionally not styling
3884
3899
  "regexp": "red"
3885
3900
  };
3886
3901
  function stylizeWithColor(str, styleType) {
@@ -3902,7 +3917,9 @@ var kubb = (function (exports) {
3902
3917
  return hash;
3903
3918
  }
3904
3919
  function formatValue(ctx, value, recurseTimes) {
3905
- if (ctx.customInspect && value && isFunction(value.inspect) && value.inspect !== exports.inspect && !(value.constructor && value.constructor.prototype === value)) {
3920
+ if (ctx.customInspect && value && isFunction(value.inspect) && // Filter out the util module, it's inspect function is special
3921
+ value.inspect !== exports.inspect && // Also filter out any prototype objects using the circular check.
3922
+ !(value.constructor && value.constructor.prototype === value)) {
3906
3923
  var ret = value.inspect(recurseTimes, ctx);
3907
3924
  if (!isString(ret)) {
3908
3925
  ret = formatValue(ctx, ret, recurseTimes);
@@ -4145,7 +4162,8 @@ var kubb = (function (exports) {
4145
4162
  }
4146
4163
  exports.isFunction = isFunction;
4147
4164
  function isPrimitive(arg) {
4148
- return arg === null || typeof arg === "boolean" || typeof arg === "number" || typeof arg === "string" || typeof arg === "symbol" || typeof arg === "undefined";
4165
+ return arg === null || typeof arg === "boolean" || typeof arg === "number" || typeof arg === "string" || typeof arg === "symbol" || // ES6 symbol
4166
+ typeof arg === "undefined";
4149
4167
  }
4150
4168
  exports.isPrimitive = isPrimitive;
4151
4169
  exports.isBuffer = require_isBufferBrowser();
@@ -4170,7 +4188,7 @@ var kubb = (function (exports) {
4170
4188
  "Dec"
4171
4189
  ];
4172
4190
  function timestamp() {
4173
- var d = new Date();
4191
+ var d = /* @__PURE__ */ new Date();
4174
4192
  var time = [
4175
4193
  pad(d.getHours()),
4176
4194
  pad(d.getMinutes()),
@@ -4690,10 +4708,18 @@ var kubb = (function (exports) {
4690
4708
  customInspect: false,
4691
4709
  depth: 1e3,
4692
4710
  maxArrayLength: Infinity,
4711
+ // Assert compares only enumerable properties (with a few exceptions).
4693
4712
  showHidden: false,
4713
+ // Having a long line as error is better than wrapping the line for
4714
+ // comparison for now.
4715
+ // TODO(BridgeAR): `breakLength` should be limited as soon as soon as we
4716
+ // have meta information about the inspected properties (i.e., know where
4717
+ // in what line the property starts and ends).
4694
4718
  breakLength: Infinity,
4719
+ // Assert does not detect proxies currently.
4695
4720
  showProxy: false,
4696
4721
  sorted: true,
4722
+ // Inspect getters as we also check them when comparing entries.
4697
4723
  getters: true
4698
4724
  });
4699
4725
  }
@@ -6426,46 +6452,52 @@ var kubb = (function (exports) {
6426
6452
  var kCode = typeof Symbol === "undefined" ? "_kCode" : Symbol("code");
6427
6453
  var messages = {};
6428
6454
  function makeNodeError(Base) {
6429
- return function(_super) {
6430
- __extends(NodeError, _super);
6431
- function NodeError(key) {
6432
- var args = [];
6433
- for (var _i = 1; _i < arguments.length; _i++) {
6434
- args[_i - 1] = arguments[_i];
6435
- }
6436
- var _this = _super.call(this, message(key, args)) || this;
6437
- _this.code = key;
6438
- _this[kCode] = key;
6439
- _this.name = "".concat(_super.prototype.name, " [").concat(_this[kCode], "]");
6440
- return _this;
6441
- }
6442
- return NodeError;
6443
- }(Base);
6455
+ return (
6456
+ /** @class */
6457
+ function(_super) {
6458
+ __extends(NodeError, _super);
6459
+ function NodeError(key) {
6460
+ var args = [];
6461
+ for (var _i = 1; _i < arguments.length; _i++) {
6462
+ args[_i - 1] = arguments[_i];
6463
+ }
6464
+ var _this = _super.call(this, message(key, args)) || this;
6465
+ _this.code = key;
6466
+ _this[kCode] = key;
6467
+ _this.name = "".concat(_super.prototype.name, " [").concat(_this[kCode], "]");
6468
+ return _this;
6469
+ }
6470
+ return NodeError;
6471
+ }(Base)
6472
+ );
6444
6473
  }
6445
6474
  var g = typeof globalThis !== "undefined" ? globalThis : globalThis;
6446
- var AssertionError = function(_super) {
6447
- __extends(AssertionError2, _super);
6448
- function AssertionError2(options) {
6449
- var _this = this;
6450
- if (typeof options !== "object" || options === null) {
6451
- throw new exports.TypeError("ERR_INVALID_ARG_TYPE", "options", "object");
6452
- }
6453
- if (options.message) {
6454
- _this = _super.call(this, options.message) || this;
6455
- } else {
6456
- _this = _super.call(this, "".concat(util.inspect(options.actual).slice(0, 128), " ") + "".concat(options.operator, " ").concat(util.inspect(options.expected).slice(0, 128))) || this;
6475
+ var AssertionError = (
6476
+ /** @class */
6477
+ function(_super) {
6478
+ __extends(AssertionError2, _super);
6479
+ function AssertionError2(options) {
6480
+ var _this = this;
6481
+ if (typeof options !== "object" || options === null) {
6482
+ throw new exports.TypeError("ERR_INVALID_ARG_TYPE", "options", "object");
6483
+ }
6484
+ if (options.message) {
6485
+ _this = _super.call(this, options.message) || this;
6486
+ } else {
6487
+ _this = _super.call(this, "".concat(util.inspect(options.actual).slice(0, 128), " ") + "".concat(options.operator, " ").concat(util.inspect(options.expected).slice(0, 128))) || this;
6488
+ }
6489
+ _this.generatedMessage = !options.message;
6490
+ _this.name = "AssertionError [ERR_ASSERTION]";
6491
+ _this.code = "ERR_ASSERTION";
6492
+ _this.actual = options.actual;
6493
+ _this.expected = options.expected;
6494
+ _this.operator = options.operator;
6495
+ exports.Error.captureStackTrace(_this, options.stackStartFunction);
6496
+ return _this;
6457
6497
  }
6458
- _this.generatedMessage = !options.message;
6459
- _this.name = "AssertionError [ERR_ASSERTION]";
6460
- _this.code = "ERR_ASSERTION";
6461
- _this.actual = options.actual;
6462
- _this.expected = options.expected;
6463
- _this.operator = options.operator;
6464
- exports.Error.captureStackTrace(_this, options.stackStartFunction);
6465
- return _this;
6466
- }
6467
- return AssertionError2;
6468
- }(g.Error);
6498
+ return AssertionError2;
6499
+ }(g.Error)
6500
+ );
6469
6501
  exports.AssertionError = AssertionError;
6470
6502
  function message(key, args) {
6471
6503
  assert.strictEqual(typeof key, "string");
@@ -6695,44 +6727,47 @@ var kubb = (function (exports) {
6695
6727
  var S_IFLNK = constants_1.constants.S_IFLNK;
6696
6728
  var S_IFIFO = constants_1.constants.S_IFIFO;
6697
6729
  var S_IFSOCK = constants_1.constants.S_IFSOCK;
6698
- var Dirent = function() {
6699
- function Dirent2() {
6700
- this.name = "";
6701
- this.mode = 0;
6702
- }
6703
- Dirent2.build = function(link, encoding) {
6704
- var dirent = new Dirent2();
6705
- var mode = link.getNode().mode;
6706
- dirent.name = (0, encoding_1.strToEncoding)(link.getName(), encoding);
6707
- dirent.mode = mode;
6708
- return dirent;
6709
- };
6710
- Dirent2.prototype._checkModeProperty = function(property) {
6711
- return (this.mode & S_IFMT) === property;
6712
- };
6713
- Dirent2.prototype.isDirectory = function() {
6714
- return this._checkModeProperty(S_IFDIR);
6715
- };
6716
- Dirent2.prototype.isFile = function() {
6717
- return this._checkModeProperty(S_IFREG);
6718
- };
6719
- Dirent2.prototype.isBlockDevice = function() {
6720
- return this._checkModeProperty(S_IFBLK);
6721
- };
6722
- Dirent2.prototype.isCharacterDevice = function() {
6723
- return this._checkModeProperty(S_IFCHR);
6724
- };
6725
- Dirent2.prototype.isSymbolicLink = function() {
6726
- return this._checkModeProperty(S_IFLNK);
6727
- };
6728
- Dirent2.prototype.isFIFO = function() {
6729
- return this._checkModeProperty(S_IFIFO);
6730
- };
6731
- Dirent2.prototype.isSocket = function() {
6732
- return this._checkModeProperty(S_IFSOCK);
6733
- };
6734
- return Dirent2;
6735
- }();
6730
+ var Dirent = (
6731
+ /** @class */
6732
+ function() {
6733
+ function Dirent2() {
6734
+ this.name = "";
6735
+ this.mode = 0;
6736
+ }
6737
+ Dirent2.build = function(link, encoding) {
6738
+ var dirent = new Dirent2();
6739
+ var mode = link.getNode().mode;
6740
+ dirent.name = (0, encoding_1.strToEncoding)(link.getName(), encoding);
6741
+ dirent.mode = mode;
6742
+ return dirent;
6743
+ };
6744
+ Dirent2.prototype._checkModeProperty = function(property) {
6745
+ return (this.mode & S_IFMT) === property;
6746
+ };
6747
+ Dirent2.prototype.isDirectory = function() {
6748
+ return this._checkModeProperty(S_IFDIR);
6749
+ };
6750
+ Dirent2.prototype.isFile = function() {
6751
+ return this._checkModeProperty(S_IFREG);
6752
+ };
6753
+ Dirent2.prototype.isBlockDevice = function() {
6754
+ return this._checkModeProperty(S_IFBLK);
6755
+ };
6756
+ Dirent2.prototype.isCharacterDevice = function() {
6757
+ return this._checkModeProperty(S_IFCHR);
6758
+ };
6759
+ Dirent2.prototype.isSymbolicLink = function() {
6760
+ return this._checkModeProperty(S_IFLNK);
6761
+ };
6762
+ Dirent2.prototype.isFIFO = function() {
6763
+ return this._checkModeProperty(S_IFIFO);
6764
+ };
6765
+ Dirent2.prototype.isSocket = function() {
6766
+ return this._checkModeProperty(S_IFSOCK);
6767
+ };
6768
+ return Dirent2;
6769
+ }()
6770
+ );
6736
6771
  exports.Dirent = Dirent;
6737
6772
  exports.default = Dirent;
6738
6773
  }
@@ -7180,384 +7215,394 @@ var kubb = (function (exports) {
7180
7215
  return (_b = (_a = process_1.default.getgid) === null || _a === void 0 ? void 0 : _a.call(process_1.default)) !== null && _b !== void 0 ? _b : 0;
7181
7216
  };
7182
7217
  exports.SEP = "/";
7183
- var Node = function(_super) {
7184
- __extends(Node2, _super);
7185
- function Node2(ino, perm) {
7186
- if (perm === void 0) {
7187
- perm = 438;
7188
- }
7189
- var _this = _super.call(this) || this;
7190
- _this.uid = getuid();
7191
- _this.gid = getgid();
7192
- _this.atime = new Date();
7193
- _this.mtime = new Date();
7194
- _this.ctime = new Date();
7195
- _this.perm = 438;
7196
- _this.mode = S_IFREG;
7197
- _this.nlink = 1;
7198
- _this.perm = perm;
7199
- _this.mode |= perm;
7200
- _this.ino = ino;
7201
- return _this;
7202
- }
7203
- Node2.prototype.getString = function(encoding) {
7204
- if (encoding === void 0) {
7205
- encoding = "utf8";
7206
- }
7207
- return this.getBuffer().toString(encoding);
7208
- };
7209
- Node2.prototype.setString = function(str) {
7210
- this.buf = (0, buffer_1.bufferFrom)(str, "utf8");
7211
- this.touch();
7212
- };
7213
- Node2.prototype.getBuffer = function() {
7214
- if (!this.buf)
7215
- this.setBuffer((0, buffer_1.bufferAllocUnsafe)(0));
7216
- return (0, buffer_1.bufferFrom)(this.buf);
7217
- };
7218
- Node2.prototype.setBuffer = function(buf) {
7219
- this.buf = (0, buffer_1.bufferFrom)(buf);
7220
- this.touch();
7221
- };
7222
- Node2.prototype.getSize = function() {
7223
- return this.buf ? this.buf.length : 0;
7224
- };
7225
- Node2.prototype.setModeProperty = function(property) {
7226
- this.mode = this.mode & ~S_IFMT | property;
7227
- };
7228
- Node2.prototype.setIsFile = function() {
7229
- this.setModeProperty(S_IFREG);
7230
- };
7231
- Node2.prototype.setIsDirectory = function() {
7232
- this.setModeProperty(S_IFDIR);
7233
- };
7234
- Node2.prototype.setIsSymlink = function() {
7235
- this.setModeProperty(S_IFLNK);
7236
- };
7237
- Node2.prototype.isFile = function() {
7238
- return (this.mode & S_IFMT) === S_IFREG;
7239
- };
7240
- Node2.prototype.isDirectory = function() {
7241
- return (this.mode & S_IFMT) === S_IFDIR;
7242
- };
7243
- Node2.prototype.isSymlink = function() {
7244
- return (this.mode & S_IFMT) === S_IFLNK;
7245
- };
7246
- Node2.prototype.makeSymlink = function(steps) {
7247
- this.symlink = steps;
7248
- this.setIsSymlink();
7249
- };
7250
- Node2.prototype.write = function(buf, off, len, pos) {
7251
- if (off === void 0) {
7252
- off = 0;
7253
- }
7254
- if (len === void 0) {
7255
- len = buf.length;
7256
- }
7257
- if (pos === void 0) {
7258
- pos = 0;
7259
- }
7260
- if (!this.buf)
7261
- this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
7262
- if (pos + len > this.buf.length) {
7263
- var newBuf = (0, buffer_1.bufferAllocUnsafe)(pos + len);
7264
- this.buf.copy(newBuf, 0, 0, this.buf.length);
7265
- this.buf = newBuf;
7266
- }
7267
- buf.copy(this.buf, pos, off, off + len);
7268
- this.touch();
7269
- return len;
7270
- };
7271
- Node2.prototype.read = function(buf, off, len, pos) {
7272
- if (off === void 0) {
7273
- off = 0;
7274
- }
7275
- if (len === void 0) {
7276
- len = buf.byteLength;
7277
- }
7278
- if (pos === void 0) {
7279
- pos = 0;
7280
- }
7281
- if (!this.buf)
7282
- this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
7283
- var actualLen = len;
7284
- if (actualLen > buf.byteLength) {
7285
- actualLen = buf.byteLength;
7286
- }
7287
- if (actualLen + pos > this.buf.length) {
7288
- actualLen = this.buf.length - pos;
7289
- }
7290
- this.buf.copy(buf, off, pos, pos + actualLen);
7291
- return actualLen;
7292
- };
7293
- Node2.prototype.truncate = function(len) {
7294
- if (len === void 0) {
7295
- len = 0;
7218
+ var Node = (
7219
+ /** @class */
7220
+ function(_super) {
7221
+ __extends(Node2, _super);
7222
+ function Node2(ino, perm) {
7223
+ if (perm === void 0) {
7224
+ perm = 438;
7225
+ }
7226
+ var _this = _super.call(this) || this;
7227
+ _this.uid = getuid();
7228
+ _this.gid = getgid();
7229
+ _this.atime = /* @__PURE__ */ new Date();
7230
+ _this.mtime = /* @__PURE__ */ new Date();
7231
+ _this.ctime = /* @__PURE__ */ new Date();
7232
+ _this.perm = 438;
7233
+ _this.mode = S_IFREG;
7234
+ _this.nlink = 1;
7235
+ _this.perm = perm;
7236
+ _this.mode |= perm;
7237
+ _this.ino = ino;
7238
+ return _this;
7296
7239
  }
7297
- if (!len)
7298
- this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
7299
- else {
7240
+ Node2.prototype.getString = function(encoding) {
7241
+ if (encoding === void 0) {
7242
+ encoding = "utf8";
7243
+ }
7244
+ return this.getBuffer().toString(encoding);
7245
+ };
7246
+ Node2.prototype.setString = function(str) {
7247
+ this.buf = (0, buffer_1.bufferFrom)(str, "utf8");
7248
+ this.touch();
7249
+ };
7250
+ Node2.prototype.getBuffer = function() {
7251
+ if (!this.buf)
7252
+ this.setBuffer((0, buffer_1.bufferAllocUnsafe)(0));
7253
+ return (0, buffer_1.bufferFrom)(this.buf);
7254
+ };
7255
+ Node2.prototype.setBuffer = function(buf) {
7256
+ this.buf = (0, buffer_1.bufferFrom)(buf);
7257
+ this.touch();
7258
+ };
7259
+ Node2.prototype.getSize = function() {
7260
+ return this.buf ? this.buf.length : 0;
7261
+ };
7262
+ Node2.prototype.setModeProperty = function(property) {
7263
+ this.mode = this.mode & ~S_IFMT | property;
7264
+ };
7265
+ Node2.prototype.setIsFile = function() {
7266
+ this.setModeProperty(S_IFREG);
7267
+ };
7268
+ Node2.prototype.setIsDirectory = function() {
7269
+ this.setModeProperty(S_IFDIR);
7270
+ };
7271
+ Node2.prototype.setIsSymlink = function() {
7272
+ this.setModeProperty(S_IFLNK);
7273
+ };
7274
+ Node2.prototype.isFile = function() {
7275
+ return (this.mode & S_IFMT) === S_IFREG;
7276
+ };
7277
+ Node2.prototype.isDirectory = function() {
7278
+ return (this.mode & S_IFMT) === S_IFDIR;
7279
+ };
7280
+ Node2.prototype.isSymlink = function() {
7281
+ return (this.mode & S_IFMT) === S_IFLNK;
7282
+ };
7283
+ Node2.prototype.makeSymlink = function(steps) {
7284
+ this.symlink = steps;
7285
+ this.setIsSymlink();
7286
+ };
7287
+ Node2.prototype.write = function(buf, off, len, pos) {
7288
+ if (off === void 0) {
7289
+ off = 0;
7290
+ }
7291
+ if (len === void 0) {
7292
+ len = buf.length;
7293
+ }
7294
+ if (pos === void 0) {
7295
+ pos = 0;
7296
+ }
7300
7297
  if (!this.buf)
7301
7298
  this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
7302
- if (len <= this.buf.length) {
7303
- this.buf = this.buf.slice(0, len);
7304
- } else {
7305
- var buf = (0, buffer_1.bufferAllocUnsafe)(len);
7306
- this.buf.copy(buf);
7307
- buf.fill(0, this.buf.length);
7308
- this.buf = buf;
7299
+ if (pos + len > this.buf.length) {
7300
+ var newBuf = (0, buffer_1.bufferAllocUnsafe)(pos + len);
7301
+ this.buf.copy(newBuf, 0, 0, this.buf.length);
7302
+ this.buf = newBuf;
7309
7303
  }
7310
- }
7311
- this.touch();
7312
- };
7313
- Node2.prototype.chmod = function(perm) {
7314
- this.perm = perm;
7315
- this.mode = this.mode & ~511 | perm;
7316
- this.touch();
7317
- };
7318
- Node2.prototype.chown = function(uid, gid) {
7319
- this.uid = uid;
7320
- this.gid = gid;
7321
- this.touch();
7322
- };
7323
- Node2.prototype.touch = function() {
7324
- this.mtime = new Date();
7325
- this.emit("change", this);
7326
- };
7327
- Node2.prototype.canRead = function(uid, gid) {
7328
- if (uid === void 0) {
7329
- uid = getuid();
7330
- }
7331
- if (gid === void 0) {
7332
- gid = getgid();
7333
- }
7334
- if (this.perm & 4) {
7335
- return true;
7336
- }
7337
- if (gid === this.gid) {
7338
- if (this.perm & 32) {
7339
- return true;
7304
+ buf.copy(this.buf, pos, off, off + len);
7305
+ this.touch();
7306
+ return len;
7307
+ };
7308
+ Node2.prototype.read = function(buf, off, len, pos) {
7309
+ if (off === void 0) {
7310
+ off = 0;
7340
7311
  }
7341
- }
7342
- if (uid === this.uid) {
7343
- if (this.perm & 256) {
7344
- return true;
7312
+ if (len === void 0) {
7313
+ len = buf.byteLength;
7345
7314
  }
7346
- }
7347
- return false;
7348
- };
7349
- Node2.prototype.canWrite = function(uid, gid) {
7350
- if (uid === void 0) {
7351
- uid = getuid();
7352
- }
7353
- if (gid === void 0) {
7354
- gid = getgid();
7355
- }
7356
- if (this.perm & 2) {
7357
- return true;
7358
- }
7359
- if (gid === this.gid) {
7360
- if (this.perm & 16) {
7315
+ if (pos === void 0) {
7316
+ pos = 0;
7317
+ }
7318
+ if (!this.buf)
7319
+ this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
7320
+ var actualLen = len;
7321
+ if (actualLen > buf.byteLength) {
7322
+ actualLen = buf.byteLength;
7323
+ }
7324
+ if (actualLen + pos > this.buf.length) {
7325
+ actualLen = this.buf.length - pos;
7326
+ }
7327
+ this.buf.copy(buf, off, pos, pos + actualLen);
7328
+ return actualLen;
7329
+ };
7330
+ Node2.prototype.truncate = function(len) {
7331
+ if (len === void 0) {
7332
+ len = 0;
7333
+ }
7334
+ if (!len)
7335
+ this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
7336
+ else {
7337
+ if (!this.buf)
7338
+ this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
7339
+ if (len <= this.buf.length) {
7340
+ this.buf = this.buf.slice(0, len);
7341
+ } else {
7342
+ var buf = (0, buffer_1.bufferAllocUnsafe)(len);
7343
+ this.buf.copy(buf);
7344
+ buf.fill(0, this.buf.length);
7345
+ this.buf = buf;
7346
+ }
7347
+ }
7348
+ this.touch();
7349
+ };
7350
+ Node2.prototype.chmod = function(perm) {
7351
+ this.perm = perm;
7352
+ this.mode = this.mode & ~511 | perm;
7353
+ this.touch();
7354
+ };
7355
+ Node2.prototype.chown = function(uid, gid) {
7356
+ this.uid = uid;
7357
+ this.gid = gid;
7358
+ this.touch();
7359
+ };
7360
+ Node2.prototype.touch = function() {
7361
+ this.mtime = /* @__PURE__ */ new Date();
7362
+ this.emit("change", this);
7363
+ };
7364
+ Node2.prototype.canRead = function(uid, gid) {
7365
+ if (uid === void 0) {
7366
+ uid = getuid();
7367
+ }
7368
+ if (gid === void 0) {
7369
+ gid = getgid();
7370
+ }
7371
+ if (this.perm & 4) {
7361
7372
  return true;
7362
7373
  }
7363
- }
7364
- if (uid === this.uid) {
7365
- if (this.perm & 128) {
7374
+ if (gid === this.gid) {
7375
+ if (this.perm & 32) {
7376
+ return true;
7377
+ }
7378
+ }
7379
+ if (uid === this.uid) {
7380
+ if (this.perm & 256) {
7381
+ return true;
7382
+ }
7383
+ }
7384
+ return false;
7385
+ };
7386
+ Node2.prototype.canWrite = function(uid, gid) {
7387
+ if (uid === void 0) {
7388
+ uid = getuid();
7389
+ }
7390
+ if (gid === void 0) {
7391
+ gid = getgid();
7392
+ }
7393
+ if (this.perm & 2) {
7366
7394
  return true;
7367
7395
  }
7368
- }
7369
- return false;
7370
- };
7371
- Node2.prototype.del = function() {
7372
- this.emit("delete", this);
7373
- };
7374
- Node2.prototype.toJSON = function() {
7375
- return {
7376
- ino: this.ino,
7377
- uid: this.uid,
7378
- gid: this.gid,
7379
- atime: this.atime.getTime(),
7380
- mtime: this.mtime.getTime(),
7381
- ctime: this.ctime.getTime(),
7382
- perm: this.perm,
7383
- mode: this.mode,
7384
- nlink: this.nlink,
7385
- symlink: this.symlink,
7386
- data: this.getString()
7396
+ if (gid === this.gid) {
7397
+ if (this.perm & 16) {
7398
+ return true;
7399
+ }
7400
+ }
7401
+ if (uid === this.uid) {
7402
+ if (this.perm & 128) {
7403
+ return true;
7404
+ }
7405
+ }
7406
+ return false;
7387
7407
  };
7388
- };
7389
- return Node2;
7390
- }(events_1.EventEmitter);
7408
+ Node2.prototype.del = function() {
7409
+ this.emit("delete", this);
7410
+ };
7411
+ Node2.prototype.toJSON = function() {
7412
+ return {
7413
+ ino: this.ino,
7414
+ uid: this.uid,
7415
+ gid: this.gid,
7416
+ atime: this.atime.getTime(),
7417
+ mtime: this.mtime.getTime(),
7418
+ ctime: this.ctime.getTime(),
7419
+ perm: this.perm,
7420
+ mode: this.mode,
7421
+ nlink: this.nlink,
7422
+ symlink: this.symlink,
7423
+ data: this.getString()
7424
+ };
7425
+ };
7426
+ return Node2;
7427
+ }(events_1.EventEmitter)
7428
+ );
7391
7429
  exports.Node = Node;
7392
- var Link = function(_super) {
7393
- __extends(Link2, _super);
7394
- function Link2(vol, parent, name2) {
7395
- var _this = _super.call(this) || this;
7396
- _this.children = {};
7397
- _this._steps = [];
7398
- _this.ino = 0;
7399
- _this.length = 0;
7400
- _this.vol = vol;
7401
- _this.parent = parent;
7402
- _this.name = name2;
7403
- _this.syncSteps();
7404
- return _this;
7405
- }
7406
- Object.defineProperty(Link2.prototype, "steps", {
7407
- get: function() {
7408
- return this._steps;
7409
- },
7410
- set: function(val) {
7411
- this._steps = val;
7412
- for (var _i = 0, _a = Object.values(this.children); _i < _a.length; _i++) {
7413
- var child = _a[_i];
7414
- child === null || child === void 0 ? void 0 : child.syncSteps();
7415
- }
7416
- },
7417
- enumerable: false,
7418
- configurable: true
7419
- });
7420
- Link2.prototype.setNode = function(node) {
7421
- this.node = node;
7422
- this.ino = node.ino;
7423
- };
7424
- Link2.prototype.getNode = function() {
7425
- return this.node;
7426
- };
7427
- Link2.prototype.createChild = function(name2, node) {
7428
- if (node === void 0) {
7429
- node = this.vol.createNode();
7430
- }
7431
- var link = new Link2(this.vol, this, name2);
7432
- link.setNode(node);
7433
- if (node.isDirectory()) ;
7434
- this.setChild(name2, link);
7435
- return link;
7436
- };
7437
- Link2.prototype.setChild = function(name2, link) {
7438
- if (link === void 0) {
7439
- link = new Link2(this.vol, this, name2);
7440
- }
7441
- this.children[name2] = link;
7442
- link.parent = this;
7443
- this.length++;
7444
- this.emit("child:add", link, this);
7445
- return link;
7446
- };
7447
- Link2.prototype.deleteChild = function(link) {
7448
- delete this.children[link.getName()];
7449
- this.length--;
7450
- this.emit("child:delete", link, this);
7451
- };
7452
- Link2.prototype.getChild = function(name2) {
7453
- if (Object.hasOwnProperty.call(this.children, name2)) {
7454
- return this.children[name2];
7455
- }
7456
- };
7457
- Link2.prototype.getPath = function() {
7458
- return this.steps.join(exports.SEP);
7459
- };
7460
- Link2.prototype.getName = function() {
7461
- return this.steps[this.steps.length - 1];
7462
- };
7463
- Link2.prototype.walk = function(steps, stop, i) {
7464
- if (stop === void 0) {
7465
- stop = steps.length;
7466
- }
7467
- if (i === void 0) {
7468
- i = 0;
7430
+ var Link = (
7431
+ /** @class */
7432
+ function(_super) {
7433
+ __extends(Link2, _super);
7434
+ function Link2(vol, parent, name2) {
7435
+ var _this = _super.call(this) || this;
7436
+ _this.children = {};
7437
+ _this._steps = [];
7438
+ _this.ino = 0;
7439
+ _this.length = 0;
7440
+ _this.vol = vol;
7441
+ _this.parent = parent;
7442
+ _this.name = name2;
7443
+ _this.syncSteps();
7444
+ return _this;
7469
7445
  }
7470
- if (i >= steps.length)
7471
- return this;
7472
- if (i >= stop)
7473
- return this;
7474
- var step = steps[i];
7475
- var link = this.getChild(step);
7476
- if (!link)
7477
- return null;
7478
- return link.walk(steps, stop, i + 1);
7479
- };
7480
- Link2.prototype.toJSON = function() {
7481
- return {
7482
- steps: this.steps,
7483
- ino: this.ino,
7484
- children: Object.keys(this.children)
7446
+ Object.defineProperty(Link2.prototype, "steps", {
7447
+ get: function() {
7448
+ return this._steps;
7449
+ },
7450
+ // Recursively sync children steps, e.g. in case of dir rename
7451
+ set: function(val) {
7452
+ this._steps = val;
7453
+ for (var _i = 0, _a = Object.values(this.children); _i < _a.length; _i++) {
7454
+ var child = _a[_i];
7455
+ child === null || child === void 0 ? void 0 : child.syncSteps();
7456
+ }
7457
+ },
7458
+ enumerable: false,
7459
+ configurable: true
7460
+ });
7461
+ Link2.prototype.setNode = function(node) {
7462
+ this.node = node;
7463
+ this.ino = node.ino;
7485
7464
  };
7486
- };
7487
- Link2.prototype.syncSteps = function() {
7488
- this.steps = this.parent ? this.parent.steps.concat([this.name]) : [this.name];
7489
- };
7490
- return Link2;
7491
- }(events_1.EventEmitter);
7465
+ Link2.prototype.getNode = function() {
7466
+ return this.node;
7467
+ };
7468
+ Link2.prototype.createChild = function(name2, node) {
7469
+ if (node === void 0) {
7470
+ node = this.vol.createNode();
7471
+ }
7472
+ var link = new Link2(this.vol, this, name2);
7473
+ link.setNode(node);
7474
+ if (node.isDirectory()) ;
7475
+ this.setChild(name2, link);
7476
+ return link;
7477
+ };
7478
+ Link2.prototype.setChild = function(name2, link) {
7479
+ if (link === void 0) {
7480
+ link = new Link2(this.vol, this, name2);
7481
+ }
7482
+ this.children[name2] = link;
7483
+ link.parent = this;
7484
+ this.length++;
7485
+ this.emit("child:add", link, this);
7486
+ return link;
7487
+ };
7488
+ Link2.prototype.deleteChild = function(link) {
7489
+ delete this.children[link.getName()];
7490
+ this.length--;
7491
+ this.emit("child:delete", link, this);
7492
+ };
7493
+ Link2.prototype.getChild = function(name2) {
7494
+ if (Object.hasOwnProperty.call(this.children, name2)) {
7495
+ return this.children[name2];
7496
+ }
7497
+ };
7498
+ Link2.prototype.getPath = function() {
7499
+ return this.steps.join(exports.SEP);
7500
+ };
7501
+ Link2.prototype.getName = function() {
7502
+ return this.steps[this.steps.length - 1];
7503
+ };
7504
+ Link2.prototype.walk = function(steps, stop, i) {
7505
+ if (stop === void 0) {
7506
+ stop = steps.length;
7507
+ }
7508
+ if (i === void 0) {
7509
+ i = 0;
7510
+ }
7511
+ if (i >= steps.length)
7512
+ return this;
7513
+ if (i >= stop)
7514
+ return this;
7515
+ var step = steps[i];
7516
+ var link = this.getChild(step);
7517
+ if (!link)
7518
+ return null;
7519
+ return link.walk(steps, stop, i + 1);
7520
+ };
7521
+ Link2.prototype.toJSON = function() {
7522
+ return {
7523
+ steps: this.steps,
7524
+ ino: this.ino,
7525
+ children: Object.keys(this.children)
7526
+ };
7527
+ };
7528
+ Link2.prototype.syncSteps = function() {
7529
+ this.steps = this.parent ? this.parent.steps.concat([this.name]) : [this.name];
7530
+ };
7531
+ return Link2;
7532
+ }(events_1.EventEmitter)
7533
+ );
7492
7534
  exports.Link = Link;
7493
- var File = function() {
7494
- function File2(link, node, flags, fd) {
7495
- this.position = 0;
7496
- this.link = link;
7497
- this.node = node;
7498
- this.flags = flags;
7499
- this.fd = fd;
7500
- }
7501
- File2.prototype.getString = function(encoding) {
7502
- return this.node.getString();
7503
- };
7504
- File2.prototype.setString = function(str) {
7505
- this.node.setString(str);
7506
- };
7507
- File2.prototype.getBuffer = function() {
7508
- return this.node.getBuffer();
7509
- };
7510
- File2.prototype.setBuffer = function(buf) {
7511
- this.node.setBuffer(buf);
7512
- };
7513
- File2.prototype.getSize = function() {
7514
- return this.node.getSize();
7515
- };
7516
- File2.prototype.truncate = function(len) {
7517
- this.node.truncate(len);
7518
- };
7519
- File2.prototype.seekTo = function(position) {
7520
- this.position = position;
7521
- };
7522
- File2.prototype.stats = function() {
7523
- return Stats_1.default.build(this.node);
7524
- };
7525
- File2.prototype.write = function(buf, offset, length, position) {
7526
- if (offset === void 0) {
7527
- offset = 0;
7528
- }
7529
- if (length === void 0) {
7530
- length = buf.length;
7531
- }
7532
- if (typeof position !== "number")
7533
- position = this.position;
7534
- if (this.flags & O_APPEND)
7535
- position = this.getSize();
7536
- var bytes = this.node.write(buf, offset, length, position);
7537
- this.position = position + bytes;
7538
- return bytes;
7539
- };
7540
- File2.prototype.read = function(buf, offset, length, position) {
7541
- if (offset === void 0) {
7542
- offset = 0;
7543
- }
7544
- if (length === void 0) {
7545
- length = buf.byteLength;
7546
- }
7547
- if (typeof position !== "number")
7548
- position = this.position;
7549
- var bytes = this.node.read(buf, offset, length, position);
7550
- this.position = position + bytes;
7551
- return bytes;
7552
- };
7553
- File2.prototype.chmod = function(perm) {
7554
- this.node.chmod(perm);
7555
- };
7556
- File2.prototype.chown = function(uid, gid) {
7557
- this.node.chown(uid, gid);
7558
- };
7559
- return File2;
7560
- }();
7535
+ var File = (
7536
+ /** @class */
7537
+ function() {
7538
+ function File2(link, node, flags, fd) {
7539
+ this.position = 0;
7540
+ this.link = link;
7541
+ this.node = node;
7542
+ this.flags = flags;
7543
+ this.fd = fd;
7544
+ }
7545
+ File2.prototype.getString = function(encoding) {
7546
+ return this.node.getString();
7547
+ };
7548
+ File2.prototype.setString = function(str) {
7549
+ this.node.setString(str);
7550
+ };
7551
+ File2.prototype.getBuffer = function() {
7552
+ return this.node.getBuffer();
7553
+ };
7554
+ File2.prototype.setBuffer = function(buf) {
7555
+ this.node.setBuffer(buf);
7556
+ };
7557
+ File2.prototype.getSize = function() {
7558
+ return this.node.getSize();
7559
+ };
7560
+ File2.prototype.truncate = function(len) {
7561
+ this.node.truncate(len);
7562
+ };
7563
+ File2.prototype.seekTo = function(position) {
7564
+ this.position = position;
7565
+ };
7566
+ File2.prototype.stats = function() {
7567
+ return Stats_1.default.build(this.node);
7568
+ };
7569
+ File2.prototype.write = function(buf, offset, length, position) {
7570
+ if (offset === void 0) {
7571
+ offset = 0;
7572
+ }
7573
+ if (length === void 0) {
7574
+ length = buf.length;
7575
+ }
7576
+ if (typeof position !== "number")
7577
+ position = this.position;
7578
+ if (this.flags & O_APPEND)
7579
+ position = this.getSize();
7580
+ var bytes = this.node.write(buf, offset, length, position);
7581
+ this.position = position + bytes;
7582
+ return bytes;
7583
+ };
7584
+ File2.prototype.read = function(buf, offset, length, position) {
7585
+ if (offset === void 0) {
7586
+ offset = 0;
7587
+ }
7588
+ if (length === void 0) {
7589
+ length = buf.byteLength;
7590
+ }
7591
+ if (typeof position !== "number")
7592
+ position = this.position;
7593
+ var bytes = this.node.read(buf, offset, length, position);
7594
+ this.position = position + bytes;
7595
+ return bytes;
7596
+ };
7597
+ File2.prototype.chmod = function(perm) {
7598
+ this.node.chmod(perm);
7599
+ };
7600
+ File2.prototype.chown = function(uid, gid) {
7601
+ this.node.chown(uid, gid);
7602
+ };
7603
+ return File2;
7604
+ }()
7605
+ );
7561
7606
  exports.File = File;
7562
7607
  }
7563
7608
  });
@@ -7742,6 +7787,7 @@ var kubb = (function (exports) {
7742
7787
  }
7743
7788
  return ret;
7744
7789
  }
7790
+ // Consumes a specified amount of bytes or characters from the buffered data.
7745
7791
  }, {
7746
7792
  key: "consume",
7747
7793
  value: function consume(n, hasStrings) {
@@ -7761,6 +7807,7 @@ var kubb = (function (exports) {
7761
7807
  value: function first() {
7762
7808
  return this.head.data;
7763
7809
  }
7810
+ // Consumes a specified amount of characters from the buffered data.
7764
7811
  }, {
7765
7812
  key: "_getString",
7766
7813
  value: function _getString(n) {
@@ -7794,6 +7841,7 @@ var kubb = (function (exports) {
7794
7841
  this.length -= c;
7795
7842
  return ret;
7796
7843
  }
7844
+ // Consumes a specified amount of bytes from the buffered data.
7797
7845
  }, {
7798
7846
  key: "_getBuffer",
7799
7847
  value: function _getBuffer(n) {
@@ -7825,11 +7873,14 @@ var kubb = (function (exports) {
7825
7873
  this.length -= c;
7826
7874
  return ret;
7827
7875
  }
7876
+ // Make sure the linked list only shows the minimal necessary information.
7828
7877
  }, {
7829
7878
  key: custom,
7830
7879
  value: function value(_, options) {
7831
7880
  return inspect(this, _objectSpread({}, options, {
7881
+ // Only inspect one level.
7832
7882
  depth: 0,
7883
+ // It should not recurse.
7833
7884
  customInspect: false
7834
7885
  }));
7835
7886
  }
@@ -8310,6 +8361,9 @@ var kubb = (function (exports) {
8310
8361
  return this;
8311
8362
  };
8312
8363
  Object.defineProperty(Writable.prototype, "writableBuffer", {
8364
+ // making it explicit this property is not enumerable
8365
+ // because otherwise some prototype manipulation in
8366
+ // userland will fail
8313
8367
  enumerable: false,
8314
8368
  get: function get() {
8315
8369
  return this._writableState && this._writableState.getBuffer();
@@ -8322,6 +8376,9 @@ var kubb = (function (exports) {
8322
8376
  return chunk;
8323
8377
  }
8324
8378
  Object.defineProperty(Writable.prototype, "writableHighWaterMark", {
8379
+ // making it explicit this property is not enumerable
8380
+ // because otherwise some prototype manipulation in
8381
+ // userland will fail
8325
8382
  enumerable: false,
8326
8383
  get: function get() {
8327
8384
  return this._writableState.highWaterMark;
@@ -8500,6 +8557,9 @@ var kubb = (function (exports) {
8500
8557
  return this;
8501
8558
  };
8502
8559
  Object.defineProperty(Writable.prototype, "writableLength", {
8560
+ // making it explicit this property is not enumerable
8561
+ // because otherwise some prototype manipulation in
8562
+ // userland will fail
8503
8563
  enumerable: false,
8504
8564
  get: function get() {
8505
8565
  return this._writableState.length;
@@ -8572,6 +8632,9 @@ var kubb = (function (exports) {
8572
8632
  state.corkedRequestsFree.next = corkReq;
8573
8633
  }
8574
8634
  Object.defineProperty(Writable.prototype, "destroyed", {
8635
+ // making it explicit this property is not enumerable
8636
+ // because otherwise some prototype manipulation in
8637
+ // userland will fail
8575
8638
  enumerable: false,
8576
8639
  get: function get() {
8577
8640
  if (this._writableState === void 0) {
@@ -8638,18 +8701,27 @@ var kubb = (function (exports) {
8638
8701
  }
8639
8702
  }
8640
8703
  Object.defineProperty(Duplex.prototype, "writableHighWaterMark", {
8704
+ // making it explicit this property is not enumerable
8705
+ // because otherwise some prototype manipulation in
8706
+ // userland will fail
8641
8707
  enumerable: false,
8642
8708
  get: function get() {
8643
8709
  return this._writableState.highWaterMark;
8644
8710
  }
8645
8711
  });
8646
8712
  Object.defineProperty(Duplex.prototype, "writableBuffer", {
8713
+ // making it explicit this property is not enumerable
8714
+ // because otherwise some prototype manipulation in
8715
+ // userland will fail
8647
8716
  enumerable: false,
8648
8717
  get: function get() {
8649
8718
  return this._writableState && this._writableState.getBuffer();
8650
8719
  }
8651
8720
  });
8652
8721
  Object.defineProperty(Duplex.prototype, "writableLength", {
8722
+ // making it explicit this property is not enumerable
8723
+ // because otherwise some prototype manipulation in
8724
+ // userland will fail
8653
8725
  enumerable: false,
8654
8726
  get: function get() {
8655
8727
  return this._writableState.length;
@@ -8664,6 +8736,9 @@ var kubb = (function (exports) {
8664
8736
  self.end();
8665
8737
  }
8666
8738
  Object.defineProperty(Duplex.prototype, "destroyed", {
8739
+ // making it explicit this property is not enumerable
8740
+ // because otherwise some prototype manipulation in
8741
+ // userland will fail
8667
8742
  enumerable: false,
8668
8743
  get: function get() {
8669
8744
  if (this._readableState === void 0 || this._writableState === void 0) {
@@ -9388,6 +9463,9 @@ var kubb = (function (exports) {
9388
9463
  Stream.call(this);
9389
9464
  }
9390
9465
  Object.defineProperty(Readable.prototype, "destroyed", {
9466
+ // making it explicit this property is not enumerable
9467
+ // because otherwise some prototype manipulation in
9468
+ // userland will fail
9391
9469
  enumerable: false,
9392
9470
  get: function get() {
9393
9471
  if (this._readableState === void 0) {
@@ -9974,18 +10052,27 @@ var kubb = (function (exports) {
9974
10052
  };
9975
10053
  }
9976
10054
  Object.defineProperty(Readable.prototype, "readableHighWaterMark", {
10055
+ // making it explicit this property is not enumerable
10056
+ // because otherwise some prototype manipulation in
10057
+ // userland will fail
9977
10058
  enumerable: false,
9978
10059
  get: function get() {
9979
10060
  return this._readableState.highWaterMark;
9980
10061
  }
9981
10062
  });
9982
10063
  Object.defineProperty(Readable.prototype, "readableBuffer", {
10064
+ // making it explicit this property is not enumerable
10065
+ // because otherwise some prototype manipulation in
10066
+ // userland will fail
9983
10067
  enumerable: false,
9984
10068
  get: function get() {
9985
10069
  return this._readableState && this._readableState.buffer;
9986
10070
  }
9987
10071
  });
9988
10072
  Object.defineProperty(Readable.prototype, "readableFlowing", {
10073
+ // making it explicit this property is not enumerable
10074
+ // because otherwise some prototype manipulation in
10075
+ // userland will fail
9989
10076
  enumerable: false,
9990
10077
  get: function get() {
9991
10078
  return this._readableState.flowing;
@@ -9998,6 +10085,9 @@ var kubb = (function (exports) {
9998
10085
  });
9999
10086
  Readable._fromList = fromList;
10000
10087
  Object.defineProperty(Readable.prototype, "readableLength", {
10088
+ // making it explicit this property is not enumerable
10089
+ // because otherwise some prototype manipulation in
10090
+ // userland will fail
10001
10091
  enumerable: false,
10002
10092
  get: function get() {
10003
10093
  return this._readableState.length;
@@ -10405,56 +10495,59 @@ var kubb = (function (exports) {
10405
10495
  });
10406
10496
  };
10407
10497
  }
10408
- var FileHandle = function() {
10409
- function FileHandle2(vol, fd) {
10410
- this.vol = vol;
10411
- this.fd = fd;
10412
- }
10413
- FileHandle2.prototype.appendFile = function(data, options) {
10414
- return promisify(this.vol, "appendFile")(this.fd, data, options);
10415
- };
10416
- FileHandle2.prototype.chmod = function(mode) {
10417
- return promisify(this.vol, "fchmod")(this.fd, mode);
10418
- };
10419
- FileHandle2.prototype.chown = function(uid, gid) {
10420
- return promisify(this.vol, "fchown")(this.fd, uid, gid);
10421
- };
10422
- FileHandle2.prototype.close = function() {
10423
- return promisify(this.vol, "close")(this.fd);
10424
- };
10425
- FileHandle2.prototype.datasync = function() {
10426
- return promisify(this.vol, "fdatasync")(this.fd);
10427
- };
10428
- FileHandle2.prototype.read = function(buffer, offset, length, position) {
10429
- return promisify(this.vol, "read", function(bytesRead) {
10430
- return { bytesRead, buffer };
10431
- })(this.fd, buffer, offset, length, position);
10432
- };
10433
- FileHandle2.prototype.readFile = function(options) {
10434
- return promisify(this.vol, "readFile")(this.fd, options);
10435
- };
10436
- FileHandle2.prototype.stat = function(options) {
10437
- return promisify(this.vol, "fstat")(this.fd, options);
10438
- };
10439
- FileHandle2.prototype.sync = function() {
10440
- return promisify(this.vol, "fsync")(this.fd);
10441
- };
10442
- FileHandle2.prototype.truncate = function(len) {
10443
- return promisify(this.vol, "ftruncate")(this.fd, len);
10444
- };
10445
- FileHandle2.prototype.utimes = function(atime, mtime) {
10446
- return promisify(this.vol, "futimes")(this.fd, atime, mtime);
10447
- };
10448
- FileHandle2.prototype.write = function(buffer, offset, length, position) {
10449
- return promisify(this.vol, "write", function(bytesWritten) {
10450
- return { bytesWritten, buffer };
10451
- })(this.fd, buffer, offset, length, position);
10452
- };
10453
- FileHandle2.prototype.writeFile = function(data, options) {
10454
- return promisify(this.vol, "writeFile")(this.fd, data, options);
10455
- };
10456
- return FileHandle2;
10457
- }();
10498
+ var FileHandle = (
10499
+ /** @class */
10500
+ function() {
10501
+ function FileHandle2(vol, fd) {
10502
+ this.vol = vol;
10503
+ this.fd = fd;
10504
+ }
10505
+ FileHandle2.prototype.appendFile = function(data, options) {
10506
+ return promisify(this.vol, "appendFile")(this.fd, data, options);
10507
+ };
10508
+ FileHandle2.prototype.chmod = function(mode) {
10509
+ return promisify(this.vol, "fchmod")(this.fd, mode);
10510
+ };
10511
+ FileHandle2.prototype.chown = function(uid, gid) {
10512
+ return promisify(this.vol, "fchown")(this.fd, uid, gid);
10513
+ };
10514
+ FileHandle2.prototype.close = function() {
10515
+ return promisify(this.vol, "close")(this.fd);
10516
+ };
10517
+ FileHandle2.prototype.datasync = function() {
10518
+ return promisify(this.vol, "fdatasync")(this.fd);
10519
+ };
10520
+ FileHandle2.prototype.read = function(buffer, offset, length, position) {
10521
+ return promisify(this.vol, "read", function(bytesRead) {
10522
+ return { bytesRead, buffer };
10523
+ })(this.fd, buffer, offset, length, position);
10524
+ };
10525
+ FileHandle2.prototype.readFile = function(options) {
10526
+ return promisify(this.vol, "readFile")(this.fd, options);
10527
+ };
10528
+ FileHandle2.prototype.stat = function(options) {
10529
+ return promisify(this.vol, "fstat")(this.fd, options);
10530
+ };
10531
+ FileHandle2.prototype.sync = function() {
10532
+ return promisify(this.vol, "fsync")(this.fd);
10533
+ };
10534
+ FileHandle2.prototype.truncate = function(len) {
10535
+ return promisify(this.vol, "ftruncate")(this.fd, len);
10536
+ };
10537
+ FileHandle2.prototype.utimes = function(atime, mtime) {
10538
+ return promisify(this.vol, "futimes")(this.fd, atime, mtime);
10539
+ };
10540
+ FileHandle2.prototype.write = function(buffer, offset, length, position) {
10541
+ return promisify(this.vol, "write", function(bytesWritten) {
10542
+ return { bytesWritten, buffer };
10543
+ })(this.fd, buffer, offset, length, position);
10544
+ };
10545
+ FileHandle2.prototype.writeFile = function(data, options) {
10546
+ return promisify(this.vol, "writeFile")(this.fd, data, options);
10547
+ };
10548
+ return FileHandle2;
10549
+ }()
10550
+ );
10458
10551
  exports.FileHandle = FileHandle;
10459
10552
  function createPromisesApi(vol) {
10460
10553
  if (typeof Promise === "undefined")
@@ -10750,7 +10843,19 @@ var kubb = (function (exports) {
10750
10843
  });
10751
10844
  }
10752
10845
  punycode = {
10846
+ /**
10847
+ * A string representing the current Punycode.js version number.
10848
+ * @memberOf punycode
10849
+ * @type String
10850
+ */
10753
10851
  "version": "1.3.2",
10852
+ /**
10853
+ * An object of methods to convert from JavaScript's internal character
10854
+ * representation (UCS-2) to Unicode code points, and back.
10855
+ * @see <https://mathiasbynens.be/notes/javascript-encoding>
10856
+ * @memberOf punycode
10857
+ * @type Object
10858
+ */
10754
10859
  "ucs2": {
10755
10860
  "decode": ucs2decode,
10756
10861
  "encode": ucs2encode
@@ -11514,6 +11619,7 @@ var kubb = (function (exports) {
11514
11619
  var kMinPoolSpace = 128;
11515
11620
  var ERRSTR = {
11516
11621
  PATH_STR: "path must be a string or Buffer",
11622
+ // FD: 'file descriptor must be a unsigned 32-bit integer',
11517
11623
  FD: "fd must be a file descriptor",
11518
11624
  MODE_INT: "mode must be an int",
11519
11625
  CB: "callback must be a function",
@@ -11901,1382 +12007,1410 @@ var kubb = (function (exports) {
11901
12007
  flatten("", nestedJSON);
11902
12008
  return flatJSON;
11903
12009
  }
11904
- var Volume = function() {
11905
- function Volume2(props) {
11906
- if (props === void 0) {
11907
- props = {};
11908
- }
11909
- this.ino = 0;
11910
- this.inodes = {};
11911
- this.releasedInos = [];
11912
- this.fds = {};
11913
- this.releasedFds = [];
11914
- this.maxFiles = 1e4;
11915
- this.openFiles = 0;
11916
- this.promisesApi = (0, promises_1.default)(this);
11917
- this.statWatchers = {};
11918
- this.props = Object.assign({ Node: node_1.Node, Link: node_1.Link, File: node_1.File }, props);
11919
- var root = this.createLink();
11920
- root.setNode(this.createNode(true));
11921
- var self = this;
11922
- this.StatWatcher = function(_super) {
11923
- __extends(StatWatcher2, _super);
11924
- function StatWatcher2() {
11925
- return _super.call(this, self) || this;
11926
- }
11927
- return StatWatcher2;
11928
- }(StatWatcher);
11929
- var _ReadStream = FsReadStream;
11930
- this.ReadStream = function(_super) {
11931
- __extends(class_1, _super);
11932
- function class_1() {
11933
- var args = [];
11934
- for (var _i = 0; _i < arguments.length; _i++) {
11935
- args[_i] = arguments[_i];
12010
+ var Volume = (
12011
+ /** @class */
12012
+ function() {
12013
+ function Volume2(props) {
12014
+ if (props === void 0) {
12015
+ props = {};
12016
+ }
12017
+ this.ino = 0;
12018
+ this.inodes = {};
12019
+ this.releasedInos = [];
12020
+ this.fds = {};
12021
+ this.releasedFds = [];
12022
+ this.maxFiles = 1e4;
12023
+ this.openFiles = 0;
12024
+ this.promisesApi = (0, promises_1.default)(this);
12025
+ this.statWatchers = {};
12026
+ this.props = Object.assign({ Node: node_1.Node, Link: node_1.Link, File: node_1.File }, props);
12027
+ var root = this.createLink();
12028
+ root.setNode(this.createNode(true));
12029
+ var self = this;
12030
+ this.StatWatcher = /** @class */
12031
+ function(_super) {
12032
+ __extends(StatWatcher2, _super);
12033
+ function StatWatcher2() {
12034
+ return _super.call(this, self) || this;
11936
12035
  }
11937
- return _super.apply(this, __spreadArray([self], args, false)) || this;
11938
- }
11939
- return class_1;
11940
- }(_ReadStream);
11941
- var _WriteStream = FsWriteStream;
11942
- this.WriteStream = function(_super) {
11943
- __extends(class_2, _super);
11944
- function class_2() {
11945
- var args = [];
11946
- for (var _i = 0; _i < arguments.length; _i++) {
11947
- args[_i] = arguments[_i];
12036
+ return StatWatcher2;
12037
+ }(StatWatcher);
12038
+ var _ReadStream = FsReadStream;
12039
+ this.ReadStream = /** @class */
12040
+ function(_super) {
12041
+ __extends(class_1, _super);
12042
+ function class_1() {
12043
+ var args = [];
12044
+ for (var _i = 0; _i < arguments.length; _i++) {
12045
+ args[_i] = arguments[_i];
12046
+ }
12047
+ return _super.apply(this, __spreadArray([self], args, false)) || this;
11948
12048
  }
11949
- return _super.apply(this, __spreadArray([self], args, false)) || this;
11950
- }
11951
- return class_2;
11952
- }(_WriteStream);
11953
- this.FSWatcher = function(_super) {
11954
- __extends(FSWatcher2, _super);
11955
- function FSWatcher2() {
11956
- return _super.call(this, self) || this;
11957
- }
11958
- return FSWatcher2;
11959
- }(FSWatcher);
11960
- this.root = root;
11961
- }
11962
- Volume2.fromJSON = function(json, cwd) {
11963
- var vol = new Volume2();
11964
- vol.fromJSON(json, cwd);
11965
- return vol;
11966
- };
11967
- Volume2.fromNestedJSON = function(json, cwd) {
11968
- var vol = new Volume2();
11969
- vol.fromNestedJSON(json, cwd);
11970
- return vol;
11971
- };
11972
- Object.defineProperty(Volume2.prototype, "promises", {
11973
- get: function() {
11974
- if (this.promisesApi === null)
11975
- throw new Error("Promise is not supported in this environment.");
11976
- return this.promisesApi;
11977
- },
11978
- enumerable: false,
11979
- configurable: true
11980
- });
11981
- Volume2.prototype.createLink = function(parent, name2, isDirectory, perm) {
11982
- if (isDirectory === void 0) {
11983
- isDirectory = false;
11984
- }
11985
- if (!parent) {
11986
- return new this.props.Link(this, null, "");
11987
- }
11988
- if (!name2) {
11989
- throw new Error("createLink: name cannot be empty");
11990
- }
11991
- return parent.createChild(name2, this.createNode(isDirectory, perm));
11992
- };
11993
- Volume2.prototype.deleteLink = function(link) {
11994
- var parent = link.parent;
11995
- if (parent) {
11996
- parent.deleteChild(link);
11997
- return true;
11998
- }
11999
- return false;
12000
- };
12001
- Volume2.prototype.newInoNumber = function() {
12002
- var releasedFd = this.releasedInos.pop();
12003
- if (releasedFd)
12004
- return releasedFd;
12005
- else {
12006
- this.ino = (this.ino + 1) % 4294967295;
12007
- return this.ino;
12008
- }
12009
- };
12010
- Volume2.prototype.newFdNumber = function() {
12011
- var releasedFd = this.releasedFds.pop();
12012
- return typeof releasedFd === "number" ? releasedFd : Volume2.fd--;
12013
- };
12014
- Volume2.prototype.createNode = function(isDirectory, perm) {
12015
- if (isDirectory === void 0) {
12016
- isDirectory = false;
12017
- }
12018
- var node = new this.props.Node(this.newInoNumber(), perm);
12019
- if (isDirectory)
12020
- node.setIsDirectory();
12021
- this.inodes[node.ino] = node;
12022
- return node;
12023
- };
12024
- Volume2.prototype.getNode = function(ino) {
12025
- return this.inodes[ino];
12026
- };
12027
- Volume2.prototype.deleteNode = function(node) {
12028
- node.del();
12029
- delete this.inodes[node.ino];
12030
- this.releasedInos.push(node.ino);
12031
- };
12032
- Volume2.prototype.genRndStr = function() {
12033
- var str = (Math.random() + 1).toString(36).substring(2, 8);
12034
- if (str.length === 6)
12035
- return str;
12036
- else
12037
- return this.genRndStr();
12038
- };
12039
- Volume2.prototype.getLink = function(steps) {
12040
- return this.root.walk(steps);
12041
- };
12042
- Volume2.prototype.getLinkOrThrow = function(filename, funcName) {
12043
- var steps = filenameToSteps(filename);
12044
- var link = this.getLink(steps);
12045
- if (!link)
12046
- throw createError(ENOENT, funcName, filename);
12047
- return link;
12048
- };
12049
- Volume2.prototype.getResolvedLink = function(filenameOrSteps) {
12050
- var steps = typeof filenameOrSteps === "string" ? filenameToSteps(filenameOrSteps) : filenameOrSteps;
12051
- var link = this.root;
12052
- var i = 0;
12053
- while (i < steps.length) {
12054
- var step = steps[i];
12055
- link = link.getChild(step);
12056
- if (!link)
12057
- return null;
12058
- var node = link.getNode();
12059
- if (node.isSymlink()) {
12060
- steps = node.symlink.concat(steps.slice(i + 1));
12061
- link = this.root;
12062
- i = 0;
12063
- continue;
12049
+ return class_1;
12050
+ }(_ReadStream);
12051
+ var _WriteStream = FsWriteStream;
12052
+ this.WriteStream = /** @class */
12053
+ function(_super) {
12054
+ __extends(class_2, _super);
12055
+ function class_2() {
12056
+ var args = [];
12057
+ for (var _i = 0; _i < arguments.length; _i++) {
12058
+ args[_i] = arguments[_i];
12059
+ }
12060
+ return _super.apply(this, __spreadArray([self], args, false)) || this;
12061
+ }
12062
+ return class_2;
12063
+ }(_WriteStream);
12064
+ this.FSWatcher = /** @class */
12065
+ function(_super) {
12066
+ __extends(FSWatcher2, _super);
12067
+ function FSWatcher2() {
12068
+ return _super.call(this, self) || this;
12069
+ }
12070
+ return FSWatcher2;
12071
+ }(FSWatcher);
12072
+ this.root = root;
12073
+ }
12074
+ Volume2.fromJSON = function(json, cwd) {
12075
+ var vol = new Volume2();
12076
+ vol.fromJSON(json, cwd);
12077
+ return vol;
12078
+ };
12079
+ Volume2.fromNestedJSON = function(json, cwd) {
12080
+ var vol = new Volume2();
12081
+ vol.fromNestedJSON(json, cwd);
12082
+ return vol;
12083
+ };
12084
+ Object.defineProperty(Volume2.prototype, "promises", {
12085
+ get: function() {
12086
+ if (this.promisesApi === null)
12087
+ throw new Error("Promise is not supported in this environment.");
12088
+ return this.promisesApi;
12089
+ },
12090
+ enumerable: false,
12091
+ configurable: true
12092
+ });
12093
+ Volume2.prototype.createLink = function(parent, name2, isDirectory, perm) {
12094
+ if (isDirectory === void 0) {
12095
+ isDirectory = false;
12064
12096
  }
12065
- i++;
12066
- }
12067
- return link;
12068
- };
12069
- Volume2.prototype.getResolvedLinkOrThrow = function(filename, funcName) {
12070
- var link = this.getResolvedLink(filename);
12071
- if (!link)
12072
- throw createError(ENOENT, funcName, filename);
12073
- return link;
12074
- };
12075
- Volume2.prototype.resolveSymlinks = function(link) {
12076
- return this.getResolvedLink(link.steps.slice(1));
12077
- };
12078
- Volume2.prototype.getLinkAsDirOrThrow = function(filename, funcName) {
12079
- var link = this.getLinkOrThrow(filename, funcName);
12080
- if (!link.getNode().isDirectory())
12081
- throw createError(ENOTDIR, funcName, filename);
12082
- return link;
12083
- };
12084
- Volume2.prototype.getLinkParent = function(steps) {
12085
- return this.root.walk(steps, steps.length - 1);
12086
- };
12087
- Volume2.prototype.getLinkParentAsDirOrThrow = function(filenameOrSteps, funcName) {
12088
- var steps = filenameOrSteps instanceof Array ? filenameOrSteps : filenameToSteps(filenameOrSteps);
12089
- var link = this.getLinkParent(steps);
12090
- if (!link)
12091
- throw createError(ENOENT, funcName, sep + steps.join(sep));
12092
- if (!link.getNode().isDirectory())
12093
- throw createError(ENOTDIR, funcName, sep + steps.join(sep));
12094
- return link;
12095
- };
12096
- Volume2.prototype.getFileByFd = function(fd) {
12097
- return this.fds[String(fd)];
12098
- };
12099
- Volume2.prototype.getFileByFdOrThrow = function(fd, funcName) {
12100
- if (!isFd(fd))
12101
- throw TypeError(ERRSTR.FD);
12102
- var file = this.getFileByFd(fd);
12103
- if (!file)
12104
- throw createError(EBADF, funcName);
12105
- return file;
12106
- };
12107
- Volume2.prototype.wrapAsync = function(method, args, callback) {
12108
- var _this = this;
12109
- validateCallback(callback);
12110
- (0, setImmediate_1.default)(function() {
12111
- var result;
12112
- try {
12113
- result = method.apply(_this, args);
12114
- } catch (err) {
12115
- callback(err);
12116
- return;
12097
+ if (!parent) {
12098
+ return new this.props.Link(this, null, "");
12117
12099
  }
12118
- callback(null, result);
12119
- });
12120
- };
12121
- Volume2.prototype._toJSON = function(link, json, path) {
12122
- var _a2;
12123
- if (link === void 0) {
12124
- link = this.root;
12125
- }
12126
- if (json === void 0) {
12127
- json = {};
12128
- }
12129
- var isEmpty = true;
12130
- var children = link.children;
12131
- if (link.getNode().isFile()) {
12132
- children = (_a2 = {}, _a2[link.getName()] = link.parent.getChild(link.getName()), _a2);
12133
- link = link.parent;
12134
- }
12135
- for (var name_1 in children) {
12136
- isEmpty = false;
12137
- var child = link.getChild(name_1);
12138
- if (!child) {
12139
- throw new Error("_toJSON: unexpected undefined");
12140
- }
12141
- var node = child.getNode();
12142
- if (node.isFile()) {
12143
- var filename = child.getPath();
12144
- if (path)
12145
- filename = relative(path, filename);
12146
- json[filename] = node.getString();
12147
- } else if (node.isDirectory()) {
12148
- this._toJSON(child, json, path);
12149
- }
12150
- }
12151
- var dirPath = link.getPath();
12152
- if (path)
12153
- dirPath = relative(path, dirPath);
12154
- if (dirPath && isEmpty) {
12155
- json[dirPath] = null;
12156
- }
12157
- return json;
12158
- };
12159
- Volume2.prototype.toJSON = function(paths, json, isRelative) {
12160
- if (json === void 0) {
12161
- json = {};
12162
- }
12163
- if (isRelative === void 0) {
12164
- isRelative = false;
12165
- }
12166
- var links = [];
12167
- if (paths) {
12168
- if (!(paths instanceof Array))
12169
- paths = [paths];
12170
- for (var _i = 0, paths_1 = paths; _i < paths_1.length; _i++) {
12171
- var path = paths_1[_i];
12172
- var filename = pathToFilename(path);
12173
- var link = this.getResolvedLink(filename);
12100
+ if (!name2) {
12101
+ throw new Error("createLink: name cannot be empty");
12102
+ }
12103
+ return parent.createChild(name2, this.createNode(isDirectory, perm));
12104
+ };
12105
+ Volume2.prototype.deleteLink = function(link) {
12106
+ var parent = link.parent;
12107
+ if (parent) {
12108
+ parent.deleteChild(link);
12109
+ return true;
12110
+ }
12111
+ return false;
12112
+ };
12113
+ Volume2.prototype.newInoNumber = function() {
12114
+ var releasedFd = this.releasedInos.pop();
12115
+ if (releasedFd)
12116
+ return releasedFd;
12117
+ else {
12118
+ this.ino = (this.ino + 1) % 4294967295;
12119
+ return this.ino;
12120
+ }
12121
+ };
12122
+ Volume2.prototype.newFdNumber = function() {
12123
+ var releasedFd = this.releasedFds.pop();
12124
+ return typeof releasedFd === "number" ? releasedFd : Volume2.fd--;
12125
+ };
12126
+ Volume2.prototype.createNode = function(isDirectory, perm) {
12127
+ if (isDirectory === void 0) {
12128
+ isDirectory = false;
12129
+ }
12130
+ var node = new this.props.Node(this.newInoNumber(), perm);
12131
+ if (isDirectory)
12132
+ node.setIsDirectory();
12133
+ this.inodes[node.ino] = node;
12134
+ return node;
12135
+ };
12136
+ Volume2.prototype.getNode = function(ino) {
12137
+ return this.inodes[ino];
12138
+ };
12139
+ Volume2.prototype.deleteNode = function(node) {
12140
+ node.del();
12141
+ delete this.inodes[node.ino];
12142
+ this.releasedInos.push(node.ino);
12143
+ };
12144
+ Volume2.prototype.genRndStr = function() {
12145
+ var str = (Math.random() + 1).toString(36).substring(2, 8);
12146
+ if (str.length === 6)
12147
+ return str;
12148
+ else
12149
+ return this.genRndStr();
12150
+ };
12151
+ Volume2.prototype.getLink = function(steps) {
12152
+ return this.root.walk(steps);
12153
+ };
12154
+ Volume2.prototype.getLinkOrThrow = function(filename, funcName) {
12155
+ var steps = filenameToSteps(filename);
12156
+ var link = this.getLink(steps);
12157
+ if (!link)
12158
+ throw createError(ENOENT, funcName, filename);
12159
+ return link;
12160
+ };
12161
+ Volume2.prototype.getResolvedLink = function(filenameOrSteps) {
12162
+ var steps = typeof filenameOrSteps === "string" ? filenameToSteps(filenameOrSteps) : filenameOrSteps;
12163
+ var link = this.root;
12164
+ var i = 0;
12165
+ while (i < steps.length) {
12166
+ var step = steps[i];
12167
+ link = link.getChild(step);
12174
12168
  if (!link)
12169
+ return null;
12170
+ var node = link.getNode();
12171
+ if (node.isSymlink()) {
12172
+ steps = node.symlink.concat(steps.slice(i + 1));
12173
+ link = this.root;
12174
+ i = 0;
12175
12175
  continue;
12176
- links.push(link);
12176
+ }
12177
+ i++;
12178
+ }
12179
+ return link;
12180
+ };
12181
+ Volume2.prototype.getResolvedLinkOrThrow = function(filename, funcName) {
12182
+ var link = this.getResolvedLink(filename);
12183
+ if (!link)
12184
+ throw createError(ENOENT, funcName, filename);
12185
+ return link;
12186
+ };
12187
+ Volume2.prototype.resolveSymlinks = function(link) {
12188
+ return this.getResolvedLink(link.steps.slice(1));
12189
+ };
12190
+ Volume2.prototype.getLinkAsDirOrThrow = function(filename, funcName) {
12191
+ var link = this.getLinkOrThrow(filename, funcName);
12192
+ if (!link.getNode().isDirectory())
12193
+ throw createError(ENOTDIR, funcName, filename);
12194
+ return link;
12195
+ };
12196
+ Volume2.prototype.getLinkParent = function(steps) {
12197
+ return this.root.walk(steps, steps.length - 1);
12198
+ };
12199
+ Volume2.prototype.getLinkParentAsDirOrThrow = function(filenameOrSteps, funcName) {
12200
+ var steps = filenameOrSteps instanceof Array ? filenameOrSteps : filenameToSteps(filenameOrSteps);
12201
+ var link = this.getLinkParent(steps);
12202
+ if (!link)
12203
+ throw createError(ENOENT, funcName, sep + steps.join(sep));
12204
+ if (!link.getNode().isDirectory())
12205
+ throw createError(ENOTDIR, funcName, sep + steps.join(sep));
12206
+ return link;
12207
+ };
12208
+ Volume2.prototype.getFileByFd = function(fd) {
12209
+ return this.fds[String(fd)];
12210
+ };
12211
+ Volume2.prototype.getFileByFdOrThrow = function(fd, funcName) {
12212
+ if (!isFd(fd))
12213
+ throw TypeError(ERRSTR.FD);
12214
+ var file = this.getFileByFd(fd);
12215
+ if (!file)
12216
+ throw createError(EBADF, funcName);
12217
+ return file;
12218
+ };
12219
+ Volume2.prototype.wrapAsync = function(method, args, callback) {
12220
+ var _this = this;
12221
+ validateCallback(callback);
12222
+ (0, setImmediate_1.default)(function() {
12223
+ var result;
12224
+ try {
12225
+ result = method.apply(_this, args);
12226
+ } catch (err) {
12227
+ callback(err);
12228
+ return;
12229
+ }
12230
+ callback(null, result);
12231
+ });
12232
+ };
12233
+ Volume2.prototype._toJSON = function(link, json, path) {
12234
+ var _a2;
12235
+ if (link === void 0) {
12236
+ link = this.root;
12237
+ }
12238
+ if (json === void 0) {
12239
+ json = {};
12240
+ }
12241
+ var isEmpty = true;
12242
+ var children = link.children;
12243
+ if (link.getNode().isFile()) {
12244
+ children = (_a2 = {}, _a2[link.getName()] = link.parent.getChild(link.getName()), _a2);
12245
+ link = link.parent;
12246
+ }
12247
+ for (var name_1 in children) {
12248
+ isEmpty = false;
12249
+ var child = link.getChild(name_1);
12250
+ if (!child) {
12251
+ throw new Error("_toJSON: unexpected undefined");
12252
+ }
12253
+ var node = child.getNode();
12254
+ if (node.isFile()) {
12255
+ var filename = child.getPath();
12256
+ if (path)
12257
+ filename = relative(path, filename);
12258
+ json[filename] = node.getString();
12259
+ } else if (node.isDirectory()) {
12260
+ this._toJSON(child, json, path);
12261
+ }
12262
+ }
12263
+ var dirPath = link.getPath();
12264
+ if (path)
12265
+ dirPath = relative(path, dirPath);
12266
+ if (dirPath && isEmpty) {
12267
+ json[dirPath] = null;
12177
12268
  }
12178
- } else {
12179
- links.push(this.root);
12180
- }
12181
- if (!links.length)
12182
12269
  return json;
12183
- for (var _a2 = 0, links_1 = links; _a2 < links_1.length; _a2++) {
12184
- var link = links_1[_a2];
12185
- this._toJSON(link, json, isRelative ? link.getPath() : "");
12186
- }
12187
- return json;
12188
- };
12189
- Volume2.prototype.fromJSON = function(json, cwd) {
12190
- if (cwd === void 0) {
12191
- cwd = process_1.default.cwd();
12192
- }
12193
- for (var filename in json) {
12194
- var data = json[filename];
12195
- filename = resolve(filename, cwd);
12196
- if (typeof data === "string") {
12197
- var dir = dirname(filename);
12198
- this.mkdirpBase(dir, 511);
12199
- this.writeFileSync(filename, data);
12270
+ };
12271
+ Volume2.prototype.toJSON = function(paths, json, isRelative) {
12272
+ if (json === void 0) {
12273
+ json = {};
12274
+ }
12275
+ if (isRelative === void 0) {
12276
+ isRelative = false;
12277
+ }
12278
+ var links = [];
12279
+ if (paths) {
12280
+ if (!(paths instanceof Array))
12281
+ paths = [paths];
12282
+ for (var _i = 0, paths_1 = paths; _i < paths_1.length; _i++) {
12283
+ var path = paths_1[_i];
12284
+ var filename = pathToFilename(path);
12285
+ var link = this.getResolvedLink(filename);
12286
+ if (!link)
12287
+ continue;
12288
+ links.push(link);
12289
+ }
12200
12290
  } else {
12201
- this.mkdirpBase(filename, 511);
12291
+ links.push(this.root);
12202
12292
  }
12203
- }
12204
- };
12205
- Volume2.prototype.fromNestedJSON = function(json, cwd) {
12206
- this.fromJSON(flattenJSON(json), cwd);
12207
- };
12208
- Volume2.prototype.reset = function() {
12209
- this.ino = 0;
12210
- this.inodes = {};
12211
- this.releasedInos = [];
12212
- this.fds = {};
12213
- this.releasedFds = [];
12214
- this.openFiles = 0;
12215
- this.root = this.createLink();
12216
- this.root.setNode(this.createNode(true));
12217
- };
12218
- Volume2.prototype.mountSync = function(mountpoint, json) {
12219
- this.fromJSON(json, mountpoint);
12220
- };
12221
- Volume2.prototype.openLink = function(link, flagsNum, resolveSymlinks) {
12222
- if (resolveSymlinks === void 0) {
12223
- resolveSymlinks = true;
12224
- }
12225
- if (this.openFiles >= this.maxFiles) {
12226
- throw createError(EMFILE, "open", link.getPath());
12227
- }
12228
- var realLink = link;
12229
- if (resolveSymlinks)
12230
- realLink = this.resolveSymlinks(link);
12231
- if (!realLink)
12232
- throw createError(ENOENT, "open", link.getPath());
12233
- var node = realLink.getNode();
12234
- if (node.isDirectory()) {
12235
- if ((flagsNum & (O_RDONLY | O_RDWR | O_WRONLY)) !== O_RDONLY)
12236
- throw createError(EISDIR, "open", link.getPath());
12237
- } else {
12238
- if (flagsNum & O_DIRECTORY)
12239
- throw createError(ENOTDIR, "open", link.getPath());
12240
- }
12241
- if (!(flagsNum & O_WRONLY)) {
12242
- if (!node.canRead()) {
12243
- throw createError(EACCES, "open", link.getPath());
12293
+ if (!links.length)
12294
+ return json;
12295
+ for (var _a2 = 0, links_1 = links; _a2 < links_1.length; _a2++) {
12296
+ var link = links_1[_a2];
12297
+ this._toJSON(link, json, isRelative ? link.getPath() : "");
12244
12298
  }
12245
- }
12246
- var file = new this.props.File(link, node, flagsNum, this.newFdNumber());
12247
- this.fds[file.fd] = file;
12248
- this.openFiles++;
12249
- if (flagsNum & O_TRUNC)
12250
- file.truncate();
12251
- return file;
12252
- };
12253
- Volume2.prototype.openFile = function(filename, flagsNum, modeNum, resolveSymlinks) {
12254
- if (resolveSymlinks === void 0) {
12255
- resolveSymlinks = true;
12256
- }
12257
- var steps = filenameToSteps(filename);
12258
- var link = resolveSymlinks ? this.getResolvedLink(steps) : this.getLink(steps);
12259
- if (link && flagsNum & O_EXCL)
12260
- throw createError(EEXIST, "open", filename);
12261
- if (!link && flagsNum & O_CREAT) {
12262
- var dirLink = this.getResolvedLink(steps.slice(0, steps.length - 1));
12263
- if (!dirLink)
12264
- throw createError(ENOENT, "open", sep + steps.join(sep));
12265
- if (flagsNum & O_CREAT && typeof modeNum === "number") {
12266
- link = this.createLink(dirLink, steps[steps.length - 1], false, modeNum);
12299
+ return json;
12300
+ };
12301
+ Volume2.prototype.fromJSON = function(json, cwd) {
12302
+ if (cwd === void 0) {
12303
+ cwd = process_1.default.cwd();
12267
12304
  }
12268
- }
12269
- if (link)
12270
- return this.openLink(link, flagsNum, resolveSymlinks);
12271
- throw createError(ENOENT, "open", filename);
12272
- };
12273
- Volume2.prototype.openBase = function(filename, flagsNum, modeNum, resolveSymlinks) {
12274
- if (resolveSymlinks === void 0) {
12275
- resolveSymlinks = true;
12276
- }
12277
- var file = this.openFile(filename, flagsNum, modeNum, resolveSymlinks);
12278
- if (!file)
12279
- throw createError(ENOENT, "open", filename);
12280
- return file.fd;
12281
- };
12282
- Volume2.prototype.openSync = function(path, flags, mode) {
12283
- if (mode === void 0) {
12284
- mode = 438;
12285
- }
12286
- var modeNum = modeToNumber(mode);
12287
- var fileName = pathToFilename(path);
12288
- var flagsNum = flagsToNumber(flags);
12289
- return this.openBase(fileName, flagsNum, modeNum);
12290
- };
12291
- Volume2.prototype.open = function(path, flags, a, b) {
12292
- var mode = a;
12293
- var callback = b;
12294
- if (typeof a === "function") {
12295
- mode = 438;
12296
- callback = a;
12297
- }
12298
- mode = mode || 438;
12299
- var modeNum = modeToNumber(mode);
12300
- var fileName = pathToFilename(path);
12301
- var flagsNum = flagsToNumber(flags);
12302
- this.wrapAsync(this.openBase, [fileName, flagsNum, modeNum], callback);
12303
- };
12304
- Volume2.prototype.closeFile = function(file) {
12305
- if (!this.fds[file.fd])
12306
- return;
12307
- this.openFiles--;
12308
- delete this.fds[file.fd];
12309
- this.releasedFds.push(file.fd);
12310
- };
12311
- Volume2.prototype.closeSync = function(fd) {
12312
- validateFd(fd);
12313
- var file = this.getFileByFdOrThrow(fd, "close");
12314
- this.closeFile(file);
12315
- };
12316
- Volume2.prototype.close = function(fd, callback) {
12317
- validateFd(fd);
12318
- this.wrapAsync(this.closeSync, [fd], callback);
12319
- };
12320
- Volume2.prototype.openFileOrGetById = function(id, flagsNum, modeNum) {
12321
- if (typeof id === "number") {
12322
- var file = this.fds[id];
12323
- if (!file)
12324
- throw createError(ENOENT);
12305
+ for (var filename in json) {
12306
+ var data = json[filename];
12307
+ filename = resolve(filename, cwd);
12308
+ if (typeof data === "string") {
12309
+ var dir = dirname(filename);
12310
+ this.mkdirpBase(
12311
+ dir,
12312
+ 511
12313
+ /* MODE.DIR */
12314
+ );
12315
+ this.writeFileSync(filename, data);
12316
+ } else {
12317
+ this.mkdirpBase(
12318
+ filename,
12319
+ 511
12320
+ /* MODE.DIR */
12321
+ );
12322
+ }
12323
+ }
12324
+ };
12325
+ Volume2.prototype.fromNestedJSON = function(json, cwd) {
12326
+ this.fromJSON(flattenJSON(json), cwd);
12327
+ };
12328
+ Volume2.prototype.reset = function() {
12329
+ this.ino = 0;
12330
+ this.inodes = {};
12331
+ this.releasedInos = [];
12332
+ this.fds = {};
12333
+ this.releasedFds = [];
12334
+ this.openFiles = 0;
12335
+ this.root = this.createLink();
12336
+ this.root.setNode(this.createNode(true));
12337
+ };
12338
+ Volume2.prototype.mountSync = function(mountpoint, json) {
12339
+ this.fromJSON(json, mountpoint);
12340
+ };
12341
+ Volume2.prototype.openLink = function(link, flagsNum, resolveSymlinks) {
12342
+ if (resolveSymlinks === void 0) {
12343
+ resolveSymlinks = true;
12344
+ }
12345
+ if (this.openFiles >= this.maxFiles) {
12346
+ throw createError(EMFILE, "open", link.getPath());
12347
+ }
12348
+ var realLink = link;
12349
+ if (resolveSymlinks)
12350
+ realLink = this.resolveSymlinks(link);
12351
+ if (!realLink)
12352
+ throw createError(ENOENT, "open", link.getPath());
12353
+ var node = realLink.getNode();
12354
+ if (node.isDirectory()) {
12355
+ if ((flagsNum & (O_RDONLY | O_RDWR | O_WRONLY)) !== O_RDONLY)
12356
+ throw createError(EISDIR, "open", link.getPath());
12357
+ } else {
12358
+ if (flagsNum & O_DIRECTORY)
12359
+ throw createError(ENOTDIR, "open", link.getPath());
12360
+ }
12361
+ if (!(flagsNum & O_WRONLY)) {
12362
+ if (!node.canRead()) {
12363
+ throw createError(EACCES, "open", link.getPath());
12364
+ }
12365
+ }
12366
+ var file = new this.props.File(link, node, flagsNum, this.newFdNumber());
12367
+ this.fds[file.fd] = file;
12368
+ this.openFiles++;
12369
+ if (flagsNum & O_TRUNC)
12370
+ file.truncate();
12325
12371
  return file;
12326
- } else {
12327
- return this.openFile(pathToFilename(id), flagsNum, modeNum);
12328
- }
12329
- };
12330
- Volume2.prototype.readBase = function(fd, buffer, offset, length, position) {
12331
- var file = this.getFileByFdOrThrow(fd);
12332
- return file.read(buffer, Number(offset), Number(length), position);
12333
- };
12334
- Volume2.prototype.readSync = function(fd, buffer, offset, length, position) {
12335
- validateFd(fd);
12336
- return this.readBase(fd, buffer, offset, length, position);
12337
- };
12338
- Volume2.prototype.read = function(fd, buffer, offset, length, position, callback) {
12339
- var _this = this;
12340
- validateCallback(callback);
12341
- if (length === 0) {
12342
- return process_1.default.nextTick(function() {
12343
- if (callback)
12344
- callback(null, 0, buffer);
12345
- });
12346
- }
12347
- (0, setImmediate_1.default)(function() {
12348
- try {
12349
- var bytes = _this.readBase(fd, buffer, offset, length, position);
12350
- callback(null, bytes, buffer);
12351
- } catch (err) {
12352
- callback(err);
12372
+ };
12373
+ Volume2.prototype.openFile = function(filename, flagsNum, modeNum, resolveSymlinks) {
12374
+ if (resolveSymlinks === void 0) {
12375
+ resolveSymlinks = true;
12353
12376
  }
12354
- });
12355
- };
12356
- Volume2.prototype.readFileBase = function(id, flagsNum, encoding) {
12357
- var result;
12358
- var isUserFd = typeof id === "number";
12359
- var userOwnsFd = isUserFd && isFd(id);
12360
- var fd;
12361
- if (userOwnsFd)
12362
- fd = id;
12363
- else {
12364
- var filename = pathToFilename(id);
12365
12377
  var steps = filenameToSteps(filename);
12366
- var link = this.getResolvedLink(steps);
12367
- if (link) {
12368
- var node = link.getNode();
12369
- if (node.isDirectory())
12370
- throw createError(EISDIR, "open", link.getPath());
12378
+ var link = resolveSymlinks ? this.getResolvedLink(steps) : this.getLink(steps);
12379
+ if (link && flagsNum & O_EXCL)
12380
+ throw createError(EEXIST, "open", filename);
12381
+ if (!link && flagsNum & O_CREAT) {
12382
+ var dirLink = this.getResolvedLink(steps.slice(0, steps.length - 1));
12383
+ if (!dirLink)
12384
+ throw createError(ENOENT, "open", sep + steps.join(sep));
12385
+ if (flagsNum & O_CREAT && typeof modeNum === "number") {
12386
+ link = this.createLink(dirLink, steps[steps.length - 1], false, modeNum);
12387
+ }
12371
12388
  }
12372
- fd = this.openSync(id, flagsNum);
12373
- }
12374
- try {
12375
- result = bufferToEncoding(this.getFileByFdOrThrow(fd).getBuffer(), encoding);
12376
- } finally {
12377
- if (!userOwnsFd) {
12378
- this.closeSync(fd);
12389
+ if (link)
12390
+ return this.openLink(link, flagsNum, resolveSymlinks);
12391
+ throw createError(ENOENT, "open", filename);
12392
+ };
12393
+ Volume2.prototype.openBase = function(filename, flagsNum, modeNum, resolveSymlinks) {
12394
+ if (resolveSymlinks === void 0) {
12395
+ resolveSymlinks = true;
12379
12396
  }
12380
- }
12381
- return result;
12382
- };
12383
- Volume2.prototype.readFileSync = function(file, options) {
12384
- var opts = getReadFileOptions(options);
12385
- var flagsNum = flagsToNumber(opts.flag);
12386
- return this.readFileBase(file, flagsNum, opts.encoding);
12387
- };
12388
- Volume2.prototype.readFile = function(id, a, b) {
12389
- var _a2 = optsAndCbGenerator(getReadFileOptions)(a, b), opts = _a2[0], callback = _a2[1];
12390
- var flagsNum = flagsToNumber(opts.flag);
12391
- this.wrapAsync(this.readFileBase, [id, flagsNum, opts.encoding], callback);
12392
- };
12393
- Volume2.prototype.writeBase = function(fd, buf, offset, length, position) {
12394
- var file = this.getFileByFdOrThrow(fd, "write");
12395
- return file.write(buf, offset, length, position);
12396
- };
12397
- Volume2.prototype.writeSync = function(fd, a, b, c, d) {
12398
- validateFd(fd);
12399
- var encoding;
12400
- var offset;
12401
- var length;
12402
- var position;
12403
- var isBuffer = typeof a !== "string";
12404
- if (isBuffer) {
12405
- offset = (b || 0) | 0;
12406
- length = c;
12407
- position = d;
12408
- } else {
12409
- position = b;
12410
- encoding = c;
12411
- }
12412
- var buf = dataToBuffer(a, encoding);
12413
- if (isBuffer) {
12414
- if (typeof length === "undefined") {
12415
- length = buf.length;
12397
+ var file = this.openFile(filename, flagsNum, modeNum, resolveSymlinks);
12398
+ if (!file)
12399
+ throw createError(ENOENT, "open", filename);
12400
+ return file.fd;
12401
+ };
12402
+ Volume2.prototype.openSync = function(path, flags, mode) {
12403
+ if (mode === void 0) {
12404
+ mode = 438;
12416
12405
  }
12417
- } else {
12418
- offset = 0;
12419
- length = buf.length;
12420
- }
12421
- return this.writeBase(fd, buf, offset, length, position);
12422
- };
12423
- Volume2.prototype.write = function(fd, a, b, c, d, e) {
12424
- var _this = this;
12425
- validateFd(fd);
12426
- var offset;
12427
- var length;
12428
- var position;
12429
- var encoding;
12430
- var callback;
12431
- var tipa = typeof a;
12432
- var tipb = typeof b;
12433
- var tipc = typeof c;
12434
- var tipd = typeof d;
12435
- if (tipa !== "string") {
12436
- if (tipb === "function") {
12437
- callback = b;
12438
- } else if (tipc === "function") {
12439
- offset = b | 0;
12440
- callback = c;
12441
- } else if (tipd === "function") {
12442
- offset = b | 0;
12443
- length = c;
12444
- callback = d;
12406
+ var modeNum = modeToNumber(mode);
12407
+ var fileName = pathToFilename(path);
12408
+ var flagsNum = flagsToNumber(flags);
12409
+ return this.openBase(fileName, flagsNum, modeNum);
12410
+ };
12411
+ Volume2.prototype.open = function(path, flags, a, b) {
12412
+ var mode = a;
12413
+ var callback = b;
12414
+ if (typeof a === "function") {
12415
+ mode = 438;
12416
+ callback = a;
12417
+ }
12418
+ mode = mode || 438;
12419
+ var modeNum = modeToNumber(mode);
12420
+ var fileName = pathToFilename(path);
12421
+ var flagsNum = flagsToNumber(flags);
12422
+ this.wrapAsync(this.openBase, [fileName, flagsNum, modeNum], callback);
12423
+ };
12424
+ Volume2.prototype.closeFile = function(file) {
12425
+ if (!this.fds[file.fd])
12426
+ return;
12427
+ this.openFiles--;
12428
+ delete this.fds[file.fd];
12429
+ this.releasedFds.push(file.fd);
12430
+ };
12431
+ Volume2.prototype.closeSync = function(fd) {
12432
+ validateFd(fd);
12433
+ var file = this.getFileByFdOrThrow(fd, "close");
12434
+ this.closeFile(file);
12435
+ };
12436
+ Volume2.prototype.close = function(fd, callback) {
12437
+ validateFd(fd);
12438
+ this.wrapAsync(this.closeSync, [fd], callback);
12439
+ };
12440
+ Volume2.prototype.openFileOrGetById = function(id, flagsNum, modeNum) {
12441
+ if (typeof id === "number") {
12442
+ var file = this.fds[id];
12443
+ if (!file)
12444
+ throw createError(ENOENT);
12445
+ return file;
12445
12446
  } else {
12446
- offset = b | 0;
12447
+ return this.openFile(pathToFilename(id), flagsNum, modeNum);
12448
+ }
12449
+ };
12450
+ Volume2.prototype.readBase = function(fd, buffer, offset, length, position) {
12451
+ var file = this.getFileByFdOrThrow(fd);
12452
+ return file.read(buffer, Number(offset), Number(length), position);
12453
+ };
12454
+ Volume2.prototype.readSync = function(fd, buffer, offset, length, position) {
12455
+ validateFd(fd);
12456
+ return this.readBase(fd, buffer, offset, length, position);
12457
+ };
12458
+ Volume2.prototype.read = function(fd, buffer, offset, length, position, callback) {
12459
+ var _this = this;
12460
+ validateCallback(callback);
12461
+ if (length === 0) {
12462
+ return process_1.default.nextTick(function() {
12463
+ if (callback)
12464
+ callback(null, 0, buffer);
12465
+ });
12466
+ }
12467
+ (0, setImmediate_1.default)(function() {
12468
+ try {
12469
+ var bytes = _this.readBase(fd, buffer, offset, length, position);
12470
+ callback(null, bytes, buffer);
12471
+ } catch (err) {
12472
+ callback(err);
12473
+ }
12474
+ });
12475
+ };
12476
+ Volume2.prototype.readFileBase = function(id, flagsNum, encoding) {
12477
+ var result;
12478
+ var isUserFd = typeof id === "number";
12479
+ var userOwnsFd = isUserFd && isFd(id);
12480
+ var fd;
12481
+ if (userOwnsFd)
12482
+ fd = id;
12483
+ else {
12484
+ var filename = pathToFilename(id);
12485
+ var steps = filenameToSteps(filename);
12486
+ var link = this.getResolvedLink(steps);
12487
+ if (link) {
12488
+ var node = link.getNode();
12489
+ if (node.isDirectory())
12490
+ throw createError(EISDIR, "open", link.getPath());
12491
+ }
12492
+ fd = this.openSync(id, flagsNum);
12493
+ }
12494
+ try {
12495
+ result = bufferToEncoding(this.getFileByFdOrThrow(fd).getBuffer(), encoding);
12496
+ } finally {
12497
+ if (!userOwnsFd) {
12498
+ this.closeSync(fd);
12499
+ }
12500
+ }
12501
+ return result;
12502
+ };
12503
+ Volume2.prototype.readFileSync = function(file, options) {
12504
+ var opts = getReadFileOptions(options);
12505
+ var flagsNum = flagsToNumber(opts.flag);
12506
+ return this.readFileBase(file, flagsNum, opts.encoding);
12507
+ };
12508
+ Volume2.prototype.readFile = function(id, a, b) {
12509
+ var _a2 = optsAndCbGenerator(getReadFileOptions)(a, b), opts = _a2[0], callback = _a2[1];
12510
+ var flagsNum = flagsToNumber(opts.flag);
12511
+ this.wrapAsync(this.readFileBase, [id, flagsNum, opts.encoding], callback);
12512
+ };
12513
+ Volume2.prototype.writeBase = function(fd, buf, offset, length, position) {
12514
+ var file = this.getFileByFdOrThrow(fd, "write");
12515
+ return file.write(buf, offset, length, position);
12516
+ };
12517
+ Volume2.prototype.writeSync = function(fd, a, b, c, d) {
12518
+ validateFd(fd);
12519
+ var encoding;
12520
+ var offset;
12521
+ var length;
12522
+ var position;
12523
+ var isBuffer = typeof a !== "string";
12524
+ if (isBuffer) {
12525
+ offset = (b || 0) | 0;
12447
12526
  length = c;
12448
12527
  position = d;
12449
- callback = e;
12450
- }
12451
- } else {
12452
- if (tipb === "function") {
12453
- callback = b;
12454
- } else if (tipc === "function") {
12455
- position = b;
12456
- callback = c;
12457
- } else if (tipd === "function") {
12528
+ } else {
12458
12529
  position = b;
12459
12530
  encoding = c;
12460
- callback = d;
12461
12531
  }
12462
- }
12463
- var buf = dataToBuffer(a, encoding);
12464
- if (tipa !== "string") {
12465
- if (typeof length === "undefined")
12532
+ var buf = dataToBuffer(a, encoding);
12533
+ if (isBuffer) {
12534
+ if (typeof length === "undefined") {
12535
+ length = buf.length;
12536
+ }
12537
+ } else {
12538
+ offset = 0;
12466
12539
  length = buf.length;
12467
- } else {
12468
- offset = 0;
12469
- length = buf.length;
12470
- }
12471
- var cb = validateCallback(callback);
12472
- (0, setImmediate_1.default)(function() {
12473
- try {
12474
- var bytes = _this.writeBase(fd, buf, offset, length, position);
12475
- if (tipa !== "string") {
12476
- cb(null, bytes, buf);
12540
+ }
12541
+ return this.writeBase(fd, buf, offset, length, position);
12542
+ };
12543
+ Volume2.prototype.write = function(fd, a, b, c, d, e) {
12544
+ var _this = this;
12545
+ validateFd(fd);
12546
+ var offset;
12547
+ var length;
12548
+ var position;
12549
+ var encoding;
12550
+ var callback;
12551
+ var tipa = typeof a;
12552
+ var tipb = typeof b;
12553
+ var tipc = typeof c;
12554
+ var tipd = typeof d;
12555
+ if (tipa !== "string") {
12556
+ if (tipb === "function") {
12557
+ callback = b;
12558
+ } else if (tipc === "function") {
12559
+ offset = b | 0;
12560
+ callback = c;
12561
+ } else if (tipd === "function") {
12562
+ offset = b | 0;
12563
+ length = c;
12564
+ callback = d;
12477
12565
  } else {
12478
- cb(null, bytes, a);
12566
+ offset = b | 0;
12567
+ length = c;
12568
+ position = d;
12569
+ callback = e;
12570
+ }
12571
+ } else {
12572
+ if (tipb === "function") {
12573
+ callback = b;
12574
+ } else if (tipc === "function") {
12575
+ position = b;
12576
+ callback = c;
12577
+ } else if (tipd === "function") {
12578
+ position = b;
12579
+ encoding = c;
12580
+ callback = d;
12581
+ }
12582
+ }
12583
+ var buf = dataToBuffer(a, encoding);
12584
+ if (tipa !== "string") {
12585
+ if (typeof length === "undefined")
12586
+ length = buf.length;
12587
+ } else {
12588
+ offset = 0;
12589
+ length = buf.length;
12590
+ }
12591
+ var cb = validateCallback(callback);
12592
+ (0, setImmediate_1.default)(function() {
12593
+ try {
12594
+ var bytes = _this.writeBase(fd, buf, offset, length, position);
12595
+ if (tipa !== "string") {
12596
+ cb(null, bytes, buf);
12597
+ } else {
12598
+ cb(null, bytes, a);
12599
+ }
12600
+ } catch (err) {
12601
+ cb(err);
12479
12602
  }
12603
+ });
12604
+ };
12605
+ Volume2.prototype.writeFileBase = function(id, buf, flagsNum, modeNum) {
12606
+ var isUserFd = typeof id === "number";
12607
+ var fd;
12608
+ if (isUserFd)
12609
+ fd = id;
12610
+ else {
12611
+ fd = this.openBase(pathToFilename(id), flagsNum, modeNum);
12612
+ }
12613
+ var offset = 0;
12614
+ var length = buf.length;
12615
+ var position = flagsNum & O_APPEND ? void 0 : 0;
12616
+ try {
12617
+ while (length > 0) {
12618
+ var written = this.writeSync(fd, buf, offset, length, position);
12619
+ offset += written;
12620
+ length -= written;
12621
+ if (position !== void 0)
12622
+ position += written;
12623
+ }
12624
+ } finally {
12625
+ if (!isUserFd)
12626
+ this.closeSync(fd);
12627
+ }
12628
+ };
12629
+ Volume2.prototype.writeFileSync = function(id, data, options) {
12630
+ var opts = getWriteFileOptions(options);
12631
+ var flagsNum = flagsToNumber(opts.flag);
12632
+ var modeNum = modeToNumber(opts.mode);
12633
+ var buf = dataToBuffer(data, opts.encoding);
12634
+ this.writeFileBase(id, buf, flagsNum, modeNum);
12635
+ };
12636
+ Volume2.prototype.writeFile = function(id, data, a, b) {
12637
+ var options = a;
12638
+ var callback = b;
12639
+ if (typeof a === "function") {
12640
+ options = writeFileDefaults;
12641
+ callback = a;
12642
+ }
12643
+ var cb = validateCallback(callback);
12644
+ var opts = getWriteFileOptions(options);
12645
+ var flagsNum = flagsToNumber(opts.flag);
12646
+ var modeNum = modeToNumber(opts.mode);
12647
+ var buf = dataToBuffer(data, opts.encoding);
12648
+ this.wrapAsync(this.writeFileBase, [id, buf, flagsNum, modeNum], cb);
12649
+ };
12650
+ Volume2.prototype.linkBase = function(filename1, filename2) {
12651
+ var steps1 = filenameToSteps(filename1);
12652
+ var link1 = this.getLink(steps1);
12653
+ if (!link1)
12654
+ throw createError(ENOENT, "link", filename1, filename2);
12655
+ var steps2 = filenameToSteps(filename2);
12656
+ var dir2 = this.getLinkParent(steps2);
12657
+ if (!dir2)
12658
+ throw createError(ENOENT, "link", filename1, filename2);
12659
+ var name2 = steps2[steps2.length - 1];
12660
+ if (dir2.getChild(name2))
12661
+ throw createError(EEXIST, "link", filename1, filename2);
12662
+ var node = link1.getNode();
12663
+ node.nlink++;
12664
+ dir2.createChild(name2, node);
12665
+ };
12666
+ Volume2.prototype.copyFileBase = function(src, dest, flags) {
12667
+ var buf = this.readFileSync(src);
12668
+ if (flags & COPYFILE_EXCL) {
12669
+ if (this.existsSync(dest)) {
12670
+ throw createError(EEXIST, "copyFile", src, dest);
12671
+ }
12672
+ }
12673
+ if (flags & COPYFILE_FICLONE_FORCE) {
12674
+ throw createError(ENOSYS, "copyFile", src, dest);
12675
+ }
12676
+ this.writeFileBase(
12677
+ dest,
12678
+ buf,
12679
+ FLAGS.w,
12680
+ 438
12681
+ /* MODE.DEFAULT */
12682
+ );
12683
+ };
12684
+ Volume2.prototype.copyFileSync = function(src, dest, flags) {
12685
+ var srcFilename = pathToFilename(src);
12686
+ var destFilename = pathToFilename(dest);
12687
+ return this.copyFileBase(srcFilename, destFilename, (flags || 0) | 0);
12688
+ };
12689
+ Volume2.prototype.copyFile = function(src, dest, a, b) {
12690
+ var srcFilename = pathToFilename(src);
12691
+ var destFilename = pathToFilename(dest);
12692
+ var flags;
12693
+ var callback;
12694
+ if (typeof a === "function") {
12695
+ flags = 0;
12696
+ callback = a;
12697
+ } else {
12698
+ flags = a;
12699
+ callback = b;
12700
+ }
12701
+ validateCallback(callback);
12702
+ this.wrapAsync(this.copyFileBase, [srcFilename, destFilename, flags], callback);
12703
+ };
12704
+ Volume2.prototype.linkSync = function(existingPath, newPath) {
12705
+ var existingPathFilename = pathToFilename(existingPath);
12706
+ var newPathFilename = pathToFilename(newPath);
12707
+ this.linkBase(existingPathFilename, newPathFilename);
12708
+ };
12709
+ Volume2.prototype.link = function(existingPath, newPath, callback) {
12710
+ var existingPathFilename = pathToFilename(existingPath);
12711
+ var newPathFilename = pathToFilename(newPath);
12712
+ this.wrapAsync(this.linkBase, [existingPathFilename, newPathFilename], callback);
12713
+ };
12714
+ Volume2.prototype.unlinkBase = function(filename) {
12715
+ var steps = filenameToSteps(filename);
12716
+ var link = this.getLink(steps);
12717
+ if (!link)
12718
+ throw createError(ENOENT, "unlink", filename);
12719
+ if (link.length)
12720
+ throw Error("Dir not empty...");
12721
+ this.deleteLink(link);
12722
+ var node = link.getNode();
12723
+ node.nlink--;
12724
+ if (node.nlink <= 0) {
12725
+ this.deleteNode(node);
12726
+ }
12727
+ };
12728
+ Volume2.prototype.unlinkSync = function(path) {
12729
+ var filename = pathToFilename(path);
12730
+ this.unlinkBase(filename);
12731
+ };
12732
+ Volume2.prototype.unlink = function(path, callback) {
12733
+ var filename = pathToFilename(path);
12734
+ this.wrapAsync(this.unlinkBase, [filename], callback);
12735
+ };
12736
+ Volume2.prototype.symlinkBase = function(targetFilename, pathFilename) {
12737
+ var pathSteps = filenameToSteps(pathFilename);
12738
+ var dirLink = this.getLinkParent(pathSteps);
12739
+ if (!dirLink)
12740
+ throw createError(ENOENT, "symlink", targetFilename, pathFilename);
12741
+ var name2 = pathSteps[pathSteps.length - 1];
12742
+ if (dirLink.getChild(name2))
12743
+ throw createError(EEXIST, "symlink", targetFilename, pathFilename);
12744
+ var symlink = dirLink.createChild(name2);
12745
+ symlink.getNode().makeSymlink(filenameToSteps(targetFilename));
12746
+ return symlink;
12747
+ };
12748
+ Volume2.prototype.symlinkSync = function(target, path, type) {
12749
+ var targetFilename = pathToFilename(target);
12750
+ var pathFilename = pathToFilename(path);
12751
+ this.symlinkBase(targetFilename, pathFilename);
12752
+ };
12753
+ Volume2.prototype.symlink = function(target, path, a, b) {
12754
+ var callback = validateCallback(typeof a === "function" ? a : b);
12755
+ var targetFilename = pathToFilename(target);
12756
+ var pathFilename = pathToFilename(path);
12757
+ this.wrapAsync(this.symlinkBase, [targetFilename, pathFilename], callback);
12758
+ };
12759
+ Volume2.prototype.realpathBase = function(filename, encoding) {
12760
+ var steps = filenameToSteps(filename);
12761
+ var realLink = this.getResolvedLink(steps);
12762
+ if (!realLink)
12763
+ throw createError(ENOENT, "realpath", filename);
12764
+ return (0, encoding_1.strToEncoding)(realLink.getPath() || "/", encoding);
12765
+ };
12766
+ Volume2.prototype.realpathSync = function(path, options) {
12767
+ return this.realpathBase(pathToFilename(path), getRealpathOptions(options).encoding);
12768
+ };
12769
+ Volume2.prototype.realpath = function(path, a, b) {
12770
+ var _a2 = getRealpathOptsAndCb(a, b), opts = _a2[0], callback = _a2[1];
12771
+ var pathFilename = pathToFilename(path);
12772
+ this.wrapAsync(this.realpathBase, [pathFilename, opts.encoding], callback);
12773
+ };
12774
+ Volume2.prototype.lstatBase = function(filename, bigint, throwIfNoEntry) {
12775
+ if (bigint === void 0) {
12776
+ bigint = false;
12777
+ }
12778
+ if (throwIfNoEntry === void 0) {
12779
+ throwIfNoEntry = false;
12780
+ }
12781
+ var link = this.getLink(filenameToSteps(filename));
12782
+ if (link) {
12783
+ return Stats_1.default.build(link.getNode(), bigint);
12784
+ } else if (!throwIfNoEntry) {
12785
+ return void 0;
12786
+ } else {
12787
+ throw createError(ENOENT, "lstat", filename);
12788
+ }
12789
+ };
12790
+ Volume2.prototype.lstatSync = function(path, options) {
12791
+ var _a2 = getStatOptions(options), _b = _a2.throwIfNoEntry, throwIfNoEntry = _b === void 0 ? true : _b, _c = _a2.bigint, bigint = _c === void 0 ? false : _c;
12792
+ return this.lstatBase(pathToFilename(path), bigint, throwIfNoEntry);
12793
+ };
12794
+ Volume2.prototype.lstat = function(path, a, b) {
12795
+ var _a2 = getStatOptsAndCb(a, b), _b = _a2[0], _c = _b.throwIfNoEntry, throwIfNoEntry = _c === void 0 ? true : _c, _d = _b.bigint, bigint = _d === void 0 ? false : _d, callback = _a2[1];
12796
+ this.wrapAsync(this.lstatBase, [pathToFilename(path), bigint, throwIfNoEntry], callback);
12797
+ };
12798
+ Volume2.prototype.statBase = function(filename, bigint, throwIfNoEntry) {
12799
+ if (bigint === void 0) {
12800
+ bigint = false;
12801
+ }
12802
+ if (throwIfNoEntry === void 0) {
12803
+ throwIfNoEntry = true;
12804
+ }
12805
+ var link = this.getResolvedLink(filenameToSteps(filename));
12806
+ if (link) {
12807
+ return Stats_1.default.build(link.getNode(), bigint);
12808
+ } else if (!throwIfNoEntry) {
12809
+ return void 0;
12810
+ } else {
12811
+ throw createError(ENOENT, "stat", filename);
12812
+ }
12813
+ };
12814
+ Volume2.prototype.statSync = function(path, options) {
12815
+ var _a2 = getStatOptions(options), _b = _a2.bigint, bigint = _b === void 0 ? true : _b, _c = _a2.throwIfNoEntry, throwIfNoEntry = _c === void 0 ? true : _c;
12816
+ return this.statBase(pathToFilename(path), bigint, throwIfNoEntry);
12817
+ };
12818
+ Volume2.prototype.stat = function(path, a, b) {
12819
+ var _a2 = getStatOptsAndCb(a, b), _b = _a2[0], _c = _b.bigint, bigint = _c === void 0 ? false : _c, _d = _b.throwIfNoEntry, throwIfNoEntry = _d === void 0 ? true : _d, callback = _a2[1];
12820
+ this.wrapAsync(this.statBase, [pathToFilename(path), bigint, throwIfNoEntry], callback);
12821
+ };
12822
+ Volume2.prototype.fstatBase = function(fd, bigint) {
12823
+ if (bigint === void 0) {
12824
+ bigint = false;
12825
+ }
12826
+ var file = this.getFileByFd(fd);
12827
+ if (!file)
12828
+ throw createError(EBADF, "fstat");
12829
+ return Stats_1.default.build(file.node, bigint);
12830
+ };
12831
+ Volume2.prototype.fstatSync = function(fd, options) {
12832
+ return this.fstatBase(fd, getStatOptions(options).bigint);
12833
+ };
12834
+ Volume2.prototype.fstat = function(fd, a, b) {
12835
+ var _a2 = getStatOptsAndCb(a, b), opts = _a2[0], callback = _a2[1];
12836
+ this.wrapAsync(this.fstatBase, [fd, opts.bigint], callback);
12837
+ };
12838
+ Volume2.prototype.renameBase = function(oldPathFilename, newPathFilename) {
12839
+ var link = this.getLink(filenameToSteps(oldPathFilename));
12840
+ if (!link)
12841
+ throw createError(ENOENT, "rename", oldPathFilename, newPathFilename);
12842
+ var newPathSteps = filenameToSteps(newPathFilename);
12843
+ var newPathDirLink = this.getLinkParent(newPathSteps);
12844
+ if (!newPathDirLink)
12845
+ throw createError(ENOENT, "rename", oldPathFilename, newPathFilename);
12846
+ var oldLinkParent = link.parent;
12847
+ if (oldLinkParent) {
12848
+ oldLinkParent.deleteChild(link);
12849
+ }
12850
+ var name2 = newPathSteps[newPathSteps.length - 1];
12851
+ link.name = name2;
12852
+ link.steps = __spreadArray(__spreadArray([], newPathDirLink.steps, true), [name2], false);
12853
+ newPathDirLink.setChild(link.getName(), link);
12854
+ };
12855
+ Volume2.prototype.renameSync = function(oldPath, newPath) {
12856
+ var oldPathFilename = pathToFilename(oldPath);
12857
+ var newPathFilename = pathToFilename(newPath);
12858
+ this.renameBase(oldPathFilename, newPathFilename);
12859
+ };
12860
+ Volume2.prototype.rename = function(oldPath, newPath, callback) {
12861
+ var oldPathFilename = pathToFilename(oldPath);
12862
+ var newPathFilename = pathToFilename(newPath);
12863
+ this.wrapAsync(this.renameBase, [oldPathFilename, newPathFilename], callback);
12864
+ };
12865
+ Volume2.prototype.existsBase = function(filename) {
12866
+ return !!this.statBase(filename);
12867
+ };
12868
+ Volume2.prototype.existsSync = function(path) {
12869
+ try {
12870
+ return this.existsBase(pathToFilename(path));
12480
12871
  } catch (err) {
12481
- cb(err);
12872
+ return false;
12482
12873
  }
12483
- });
12484
- };
12485
- Volume2.prototype.writeFileBase = function(id, buf, flagsNum, modeNum) {
12486
- var isUserFd = typeof id === "number";
12487
- var fd;
12488
- if (isUserFd)
12489
- fd = id;
12490
- else {
12491
- fd = this.openBase(pathToFilename(id), flagsNum, modeNum);
12492
- }
12493
- var offset = 0;
12494
- var length = buf.length;
12495
- var position = flagsNum & O_APPEND ? void 0 : 0;
12496
- try {
12497
- while (length > 0) {
12498
- var written = this.writeSync(fd, buf, offset, length, position);
12499
- offset += written;
12500
- length -= written;
12501
- if (position !== void 0)
12502
- position += written;
12874
+ };
12875
+ Volume2.prototype.exists = function(path, callback) {
12876
+ var _this = this;
12877
+ var filename = pathToFilename(path);
12878
+ if (typeof callback !== "function")
12879
+ throw Error(ERRSTR.CB);
12880
+ (0, setImmediate_1.default)(function() {
12881
+ try {
12882
+ callback(_this.existsBase(filename));
12883
+ } catch (err) {
12884
+ callback(false);
12885
+ }
12886
+ });
12887
+ };
12888
+ Volume2.prototype.accessBase = function(filename, mode) {
12889
+ this.getLinkOrThrow(filename, "access");
12890
+ };
12891
+ Volume2.prototype.accessSync = function(path, mode) {
12892
+ if (mode === void 0) {
12893
+ mode = F_OK;
12503
12894
  }
12504
- } finally {
12505
- if (!isUserFd)
12506
- this.closeSync(fd);
12507
- }
12508
- };
12509
- Volume2.prototype.writeFileSync = function(id, data, options) {
12510
- var opts = getWriteFileOptions(options);
12511
- var flagsNum = flagsToNumber(opts.flag);
12512
- var modeNum = modeToNumber(opts.mode);
12513
- var buf = dataToBuffer(data, opts.encoding);
12514
- this.writeFileBase(id, buf, flagsNum, modeNum);
12515
- };
12516
- Volume2.prototype.writeFile = function(id, data, a, b) {
12517
- var options = a;
12518
- var callback = b;
12519
- if (typeof a === "function") {
12520
- options = writeFileDefaults;
12521
- callback = a;
12522
- }
12523
- var cb = validateCallback(callback);
12524
- var opts = getWriteFileOptions(options);
12525
- var flagsNum = flagsToNumber(opts.flag);
12526
- var modeNum = modeToNumber(opts.mode);
12527
- var buf = dataToBuffer(data, opts.encoding);
12528
- this.wrapAsync(this.writeFileBase, [id, buf, flagsNum, modeNum], cb);
12529
- };
12530
- Volume2.prototype.linkBase = function(filename1, filename2) {
12531
- var steps1 = filenameToSteps(filename1);
12532
- var link1 = this.getLink(steps1);
12533
- if (!link1)
12534
- throw createError(ENOENT, "link", filename1, filename2);
12535
- var steps2 = filenameToSteps(filename2);
12536
- var dir2 = this.getLinkParent(steps2);
12537
- if (!dir2)
12538
- throw createError(ENOENT, "link", filename1, filename2);
12539
- var name2 = steps2[steps2.length - 1];
12540
- if (dir2.getChild(name2))
12541
- throw createError(EEXIST, "link", filename1, filename2);
12542
- var node = link1.getNode();
12543
- node.nlink++;
12544
- dir2.createChild(name2, node);
12545
- };
12546
- Volume2.prototype.copyFileBase = function(src, dest, flags) {
12547
- var buf = this.readFileSync(src);
12548
- if (flags & COPYFILE_EXCL) {
12549
- if (this.existsSync(dest)) {
12550
- throw createError(EEXIST, "copyFile", src, dest);
12895
+ var filename = pathToFilename(path);
12896
+ mode = mode | 0;
12897
+ this.accessBase(filename, mode);
12898
+ };
12899
+ Volume2.prototype.access = function(path, a, b) {
12900
+ var mode = F_OK;
12901
+ var callback;
12902
+ if (typeof a !== "function") {
12903
+ mode = a | 0;
12904
+ callback = validateCallback(b);
12905
+ } else {
12906
+ callback = a;
12551
12907
  }
12552
- }
12553
- if (flags & COPYFILE_FICLONE_FORCE) {
12554
- throw createError(ENOSYS, "copyFile", src, dest);
12555
- }
12556
- this.writeFileBase(dest, buf, FLAGS.w, 438);
12557
- };
12558
- Volume2.prototype.copyFileSync = function(src, dest, flags) {
12559
- var srcFilename = pathToFilename(src);
12560
- var destFilename = pathToFilename(dest);
12561
- return this.copyFileBase(srcFilename, destFilename, (flags || 0) | 0);
12562
- };
12563
- Volume2.prototype.copyFile = function(src, dest, a, b) {
12564
- var srcFilename = pathToFilename(src);
12565
- var destFilename = pathToFilename(dest);
12566
- var flags;
12567
- var callback;
12568
- if (typeof a === "function") {
12569
- flags = 0;
12570
- callback = a;
12571
- } else {
12572
- flags = a;
12573
- callback = b;
12574
- }
12575
- validateCallback(callback);
12576
- this.wrapAsync(this.copyFileBase, [srcFilename, destFilename, flags], callback);
12577
- };
12578
- Volume2.prototype.linkSync = function(existingPath, newPath) {
12579
- var existingPathFilename = pathToFilename(existingPath);
12580
- var newPathFilename = pathToFilename(newPath);
12581
- this.linkBase(existingPathFilename, newPathFilename);
12582
- };
12583
- Volume2.prototype.link = function(existingPath, newPath, callback) {
12584
- var existingPathFilename = pathToFilename(existingPath);
12585
- var newPathFilename = pathToFilename(newPath);
12586
- this.wrapAsync(this.linkBase, [existingPathFilename, newPathFilename], callback);
12587
- };
12588
- Volume2.prototype.unlinkBase = function(filename) {
12589
- var steps = filenameToSteps(filename);
12590
- var link = this.getLink(steps);
12591
- if (!link)
12592
- throw createError(ENOENT, "unlink", filename);
12593
- if (link.length)
12594
- throw Error("Dir not empty...");
12595
- this.deleteLink(link);
12596
- var node = link.getNode();
12597
- node.nlink--;
12598
- if (node.nlink <= 0) {
12599
- this.deleteNode(node);
12600
- }
12601
- };
12602
- Volume2.prototype.unlinkSync = function(path) {
12603
- var filename = pathToFilename(path);
12604
- this.unlinkBase(filename);
12605
- };
12606
- Volume2.prototype.unlink = function(path, callback) {
12607
- var filename = pathToFilename(path);
12608
- this.wrapAsync(this.unlinkBase, [filename], callback);
12609
- };
12610
- Volume2.prototype.symlinkBase = function(targetFilename, pathFilename) {
12611
- var pathSteps = filenameToSteps(pathFilename);
12612
- var dirLink = this.getLinkParent(pathSteps);
12613
- if (!dirLink)
12614
- throw createError(ENOENT, "symlink", targetFilename, pathFilename);
12615
- var name2 = pathSteps[pathSteps.length - 1];
12616
- if (dirLink.getChild(name2))
12617
- throw createError(EEXIST, "symlink", targetFilename, pathFilename);
12618
- var symlink = dirLink.createChild(name2);
12619
- symlink.getNode().makeSymlink(filenameToSteps(targetFilename));
12620
- return symlink;
12621
- };
12622
- Volume2.prototype.symlinkSync = function(target, path, type) {
12623
- var targetFilename = pathToFilename(target);
12624
- var pathFilename = pathToFilename(path);
12625
- this.symlinkBase(targetFilename, pathFilename);
12626
- };
12627
- Volume2.prototype.symlink = function(target, path, a, b) {
12628
- var callback = validateCallback(typeof a === "function" ? a : b);
12629
- var targetFilename = pathToFilename(target);
12630
- var pathFilename = pathToFilename(path);
12631
- this.wrapAsync(this.symlinkBase, [targetFilename, pathFilename], callback);
12632
- };
12633
- Volume2.prototype.realpathBase = function(filename, encoding) {
12634
- var steps = filenameToSteps(filename);
12635
- var realLink = this.getResolvedLink(steps);
12636
- if (!realLink)
12637
- throw createError(ENOENT, "realpath", filename);
12638
- return (0, encoding_1.strToEncoding)(realLink.getPath() || "/", encoding);
12639
- };
12640
- Volume2.prototype.realpathSync = function(path, options) {
12641
- return this.realpathBase(pathToFilename(path), getRealpathOptions(options).encoding);
12642
- };
12643
- Volume2.prototype.realpath = function(path, a, b) {
12644
- var _a2 = getRealpathOptsAndCb(a, b), opts = _a2[0], callback = _a2[1];
12645
- var pathFilename = pathToFilename(path);
12646
- this.wrapAsync(this.realpathBase, [pathFilename, opts.encoding], callback);
12647
- };
12648
- Volume2.prototype.lstatBase = function(filename, bigint, throwIfNoEntry) {
12649
- if (bigint === void 0) {
12650
- bigint = false;
12651
- }
12652
- if (throwIfNoEntry === void 0) {
12653
- throwIfNoEntry = false;
12654
- }
12655
- var link = this.getLink(filenameToSteps(filename));
12656
- if (link) {
12657
- return Stats_1.default.build(link.getNode(), bigint);
12658
- } else if (!throwIfNoEntry) {
12659
- return void 0;
12660
- } else {
12661
- throw createError(ENOENT, "lstat", filename);
12662
- }
12663
- };
12664
- Volume2.prototype.lstatSync = function(path, options) {
12665
- var _a2 = getStatOptions(options), _b = _a2.throwIfNoEntry, throwIfNoEntry = _b === void 0 ? true : _b, _c = _a2.bigint, bigint = _c === void 0 ? false : _c;
12666
- return this.lstatBase(pathToFilename(path), bigint, throwIfNoEntry);
12667
- };
12668
- Volume2.prototype.lstat = function(path, a, b) {
12669
- var _a2 = getStatOptsAndCb(a, b), _b = _a2[0], _c = _b.throwIfNoEntry, throwIfNoEntry = _c === void 0 ? true : _c, _d = _b.bigint, bigint = _d === void 0 ? false : _d, callback = _a2[1];
12670
- this.wrapAsync(this.lstatBase, [pathToFilename(path), bigint, throwIfNoEntry], callback);
12671
- };
12672
- Volume2.prototype.statBase = function(filename, bigint, throwIfNoEntry) {
12673
- if (bigint === void 0) {
12674
- bigint = false;
12675
- }
12676
- if (throwIfNoEntry === void 0) {
12677
- throwIfNoEntry = true;
12678
- }
12679
- var link = this.getResolvedLink(filenameToSteps(filename));
12680
- if (link) {
12681
- return Stats_1.default.build(link.getNode(), bigint);
12682
- } else if (!throwIfNoEntry) {
12683
- return void 0;
12684
- } else {
12685
- throw createError(ENOENT, "stat", filename);
12686
- }
12687
- };
12688
- Volume2.prototype.statSync = function(path, options) {
12689
- var _a2 = getStatOptions(options), _b = _a2.bigint, bigint = _b === void 0 ? true : _b, _c = _a2.throwIfNoEntry, throwIfNoEntry = _c === void 0 ? true : _c;
12690
- return this.statBase(pathToFilename(path), bigint, throwIfNoEntry);
12691
- };
12692
- Volume2.prototype.stat = function(path, a, b) {
12693
- var _a2 = getStatOptsAndCb(a, b), _b = _a2[0], _c = _b.bigint, bigint = _c === void 0 ? false : _c, _d = _b.throwIfNoEntry, throwIfNoEntry = _d === void 0 ? true : _d, callback = _a2[1];
12694
- this.wrapAsync(this.statBase, [pathToFilename(path), bigint, throwIfNoEntry], callback);
12695
- };
12696
- Volume2.prototype.fstatBase = function(fd, bigint) {
12697
- if (bigint === void 0) {
12698
- bigint = false;
12699
- }
12700
- var file = this.getFileByFd(fd);
12701
- if (!file)
12702
- throw createError(EBADF, "fstat");
12703
- return Stats_1.default.build(file.node, bigint);
12704
- };
12705
- Volume2.prototype.fstatSync = function(fd, options) {
12706
- return this.fstatBase(fd, getStatOptions(options).bigint);
12707
- };
12708
- Volume2.prototype.fstat = function(fd, a, b) {
12709
- var _a2 = getStatOptsAndCb(a, b), opts = _a2[0], callback = _a2[1];
12710
- this.wrapAsync(this.fstatBase, [fd, opts.bigint], callback);
12711
- };
12712
- Volume2.prototype.renameBase = function(oldPathFilename, newPathFilename) {
12713
- var link = this.getLink(filenameToSteps(oldPathFilename));
12714
- if (!link)
12715
- throw createError(ENOENT, "rename", oldPathFilename, newPathFilename);
12716
- var newPathSteps = filenameToSteps(newPathFilename);
12717
- var newPathDirLink = this.getLinkParent(newPathSteps);
12718
- if (!newPathDirLink)
12719
- throw createError(ENOENT, "rename", oldPathFilename, newPathFilename);
12720
- var oldLinkParent = link.parent;
12721
- if (oldLinkParent) {
12722
- oldLinkParent.deleteChild(link);
12723
- }
12724
- var name2 = newPathSteps[newPathSteps.length - 1];
12725
- link.name = name2;
12726
- link.steps = __spreadArray(__spreadArray([], newPathDirLink.steps, true), [name2], false);
12727
- newPathDirLink.setChild(link.getName(), link);
12728
- };
12729
- Volume2.prototype.renameSync = function(oldPath, newPath) {
12730
- var oldPathFilename = pathToFilename(oldPath);
12731
- var newPathFilename = pathToFilename(newPath);
12732
- this.renameBase(oldPathFilename, newPathFilename);
12733
- };
12734
- Volume2.prototype.rename = function(oldPath, newPath, callback) {
12735
- var oldPathFilename = pathToFilename(oldPath);
12736
- var newPathFilename = pathToFilename(newPath);
12737
- this.wrapAsync(this.renameBase, [oldPathFilename, newPathFilename], callback);
12738
- };
12739
- Volume2.prototype.existsBase = function(filename) {
12740
- return !!this.statBase(filename);
12741
- };
12742
- Volume2.prototype.existsSync = function(path) {
12743
- try {
12744
- return this.existsBase(pathToFilename(path));
12745
- } catch (err) {
12746
- return false;
12747
- }
12748
- };
12749
- Volume2.prototype.exists = function(path, callback) {
12750
- var _this = this;
12751
- var filename = pathToFilename(path);
12752
- if (typeof callback !== "function")
12753
- throw Error(ERRSTR.CB);
12754
- (0, setImmediate_1.default)(function() {
12908
+ var filename = pathToFilename(path);
12909
+ this.wrapAsync(this.accessBase, [filename, mode], callback);
12910
+ };
12911
+ Volume2.prototype.appendFileSync = function(id, data, options) {
12912
+ if (options === void 0) {
12913
+ options = appendFileDefaults;
12914
+ }
12915
+ var opts = getAppendFileOpts(options);
12916
+ if (!opts.flag || isFd(id))
12917
+ opts.flag = "a";
12918
+ this.writeFileSync(id, data, opts);
12919
+ };
12920
+ Volume2.prototype.appendFile = function(id, data, a, b) {
12921
+ var _a2 = getAppendFileOptsAndCb(a, b), opts = _a2[0], callback = _a2[1];
12922
+ if (!opts.flag || isFd(id))
12923
+ opts.flag = "a";
12924
+ this.writeFile(id, data, opts, callback);
12925
+ };
12926
+ Volume2.prototype.readdirBase = function(filename, options) {
12927
+ var steps = filenameToSteps(filename);
12928
+ var link = this.getResolvedLink(steps);
12929
+ if (!link)
12930
+ throw createError(ENOENT, "readdir", filename);
12931
+ var node = link.getNode();
12932
+ if (!node.isDirectory())
12933
+ throw createError(ENOTDIR, "scandir", filename);
12934
+ if (options.withFileTypes) {
12935
+ var list_1 = [];
12936
+ for (var name_2 in link.children) {
12937
+ var child = link.getChild(name_2);
12938
+ if (!child) {
12939
+ continue;
12940
+ }
12941
+ list_1.push(Dirent_1.default.build(child, options.encoding));
12942
+ }
12943
+ if (!isWin && options.encoding !== "buffer")
12944
+ list_1.sort(function(a, b) {
12945
+ if (a.name < b.name)
12946
+ return -1;
12947
+ if (a.name > b.name)
12948
+ return 1;
12949
+ return 0;
12950
+ });
12951
+ return list_1;
12952
+ }
12953
+ var list = [];
12954
+ for (var name_3 in link.children) {
12955
+ list.push((0, encoding_1.strToEncoding)(name_3, options.encoding));
12956
+ }
12957
+ if (!isWin && options.encoding !== "buffer")
12958
+ list.sort();
12959
+ return list;
12960
+ };
12961
+ Volume2.prototype.readdirSync = function(path, options) {
12962
+ var opts = getReaddirOptions(options);
12963
+ var filename = pathToFilename(path);
12964
+ return this.readdirBase(filename, opts);
12965
+ };
12966
+ Volume2.prototype.readdir = function(path, a, b) {
12967
+ var _a2 = getReaddirOptsAndCb(a, b), options = _a2[0], callback = _a2[1];
12968
+ var filename = pathToFilename(path);
12969
+ this.wrapAsync(this.readdirBase, [filename, options], callback);
12970
+ };
12971
+ Volume2.prototype.readlinkBase = function(filename, encoding) {
12972
+ var link = this.getLinkOrThrow(filename, "readlink");
12973
+ var node = link.getNode();
12974
+ if (!node.isSymlink())
12975
+ throw createError(EINVAL, "readlink", filename);
12976
+ var str = sep + node.symlink.join(sep);
12977
+ return (0, encoding_1.strToEncoding)(str, encoding);
12978
+ };
12979
+ Volume2.prototype.readlinkSync = function(path, options) {
12980
+ var opts = getDefaultOpts(options);
12981
+ var filename = pathToFilename(path);
12982
+ return this.readlinkBase(filename, opts.encoding);
12983
+ };
12984
+ Volume2.prototype.readlink = function(path, a, b) {
12985
+ var _a2 = getDefaultOptsAndCb(a, b), opts = _a2[0], callback = _a2[1];
12986
+ var filename = pathToFilename(path);
12987
+ this.wrapAsync(this.readlinkBase, [filename, opts.encoding], callback);
12988
+ };
12989
+ Volume2.prototype.fsyncBase = function(fd) {
12990
+ this.getFileByFdOrThrow(fd, "fsync");
12991
+ };
12992
+ Volume2.prototype.fsyncSync = function(fd) {
12993
+ this.fsyncBase(fd);
12994
+ };
12995
+ Volume2.prototype.fsync = function(fd, callback) {
12996
+ this.wrapAsync(this.fsyncBase, [fd], callback);
12997
+ };
12998
+ Volume2.prototype.fdatasyncBase = function(fd) {
12999
+ this.getFileByFdOrThrow(fd, "fdatasync");
13000
+ };
13001
+ Volume2.prototype.fdatasyncSync = function(fd) {
13002
+ this.fdatasyncBase(fd);
13003
+ };
13004
+ Volume2.prototype.fdatasync = function(fd, callback) {
13005
+ this.wrapAsync(this.fdatasyncBase, [fd], callback);
13006
+ };
13007
+ Volume2.prototype.ftruncateBase = function(fd, len) {
13008
+ var file = this.getFileByFdOrThrow(fd, "ftruncate");
13009
+ file.truncate(len);
13010
+ };
13011
+ Volume2.prototype.ftruncateSync = function(fd, len) {
13012
+ this.ftruncateBase(fd, len);
13013
+ };
13014
+ Volume2.prototype.ftruncate = function(fd, a, b) {
13015
+ var len = typeof a === "number" ? a : 0;
13016
+ var callback = validateCallback(typeof a === "number" ? b : a);
13017
+ this.wrapAsync(this.ftruncateBase, [fd, len], callback);
13018
+ };
13019
+ Volume2.prototype.truncateBase = function(path, len) {
13020
+ var fd = this.openSync(path, "r+");
13021
+ try {
13022
+ this.ftruncateSync(fd, len);
13023
+ } finally {
13024
+ this.closeSync(fd);
13025
+ }
13026
+ };
13027
+ Volume2.prototype.truncateSync = function(id, len) {
13028
+ if (isFd(id))
13029
+ return this.ftruncateSync(id, len);
13030
+ this.truncateBase(id, len);
13031
+ };
13032
+ Volume2.prototype.truncate = function(id, a, b) {
13033
+ var len = typeof a === "number" ? a : 0;
13034
+ var callback = validateCallback(typeof a === "number" ? b : a);
13035
+ if (isFd(id))
13036
+ return this.ftruncate(id, len, callback);
13037
+ this.wrapAsync(this.truncateBase, [id, len], callback);
13038
+ };
13039
+ Volume2.prototype.futimesBase = function(fd, atime, mtime) {
13040
+ var file = this.getFileByFdOrThrow(fd, "futimes");
13041
+ var node = file.node;
13042
+ node.atime = new Date(atime * 1e3);
13043
+ node.mtime = new Date(mtime * 1e3);
13044
+ };
13045
+ Volume2.prototype.futimesSync = function(fd, atime, mtime) {
13046
+ this.futimesBase(fd, toUnixTimestamp(atime), toUnixTimestamp(mtime));
13047
+ };
13048
+ Volume2.prototype.futimes = function(fd, atime, mtime, callback) {
13049
+ this.wrapAsync(this.futimesBase, [fd, toUnixTimestamp(atime), toUnixTimestamp(mtime)], callback);
13050
+ };
13051
+ Volume2.prototype.utimesBase = function(filename, atime, mtime) {
13052
+ var fd = this.openSync(filename, "r");
13053
+ try {
13054
+ this.futimesBase(fd, atime, mtime);
13055
+ } finally {
13056
+ this.closeSync(fd);
13057
+ }
13058
+ };
13059
+ Volume2.prototype.utimesSync = function(path, atime, mtime) {
13060
+ this.utimesBase(pathToFilename(path), toUnixTimestamp(atime), toUnixTimestamp(mtime));
13061
+ };
13062
+ Volume2.prototype.utimes = function(path, atime, mtime, callback) {
13063
+ this.wrapAsync(this.utimesBase, [pathToFilename(path), toUnixTimestamp(atime), toUnixTimestamp(mtime)], callback);
13064
+ };
13065
+ Volume2.prototype.mkdirBase = function(filename, modeNum) {
13066
+ var steps = filenameToSteps(filename);
13067
+ if (!steps.length) {
13068
+ throw createError(EEXIST, "mkdir", filename);
13069
+ }
13070
+ var dir = this.getLinkParentAsDirOrThrow(filename, "mkdir");
13071
+ var name2 = steps[steps.length - 1];
13072
+ if (dir.getChild(name2))
13073
+ throw createError(EEXIST, "mkdir", filename);
13074
+ dir.createChild(name2, this.createNode(true, modeNum));
13075
+ };
13076
+ Volume2.prototype.mkdirpBase = function(filename, modeNum) {
13077
+ var fullPath = resolve(filename);
13078
+ var fullPathSansSlash = fullPath.substring(1);
13079
+ var steps = !fullPathSansSlash ? [] : fullPathSansSlash.split(sep);
13080
+ var link = this.root;
13081
+ var created = false;
13082
+ for (var i = 0; i < steps.length; i++) {
13083
+ var step = steps[i];
13084
+ if (!link.getNode().isDirectory())
13085
+ throw createError(ENOTDIR, "mkdir", link.getPath());
13086
+ var child = link.getChild(step);
13087
+ if (child) {
13088
+ if (child.getNode().isDirectory())
13089
+ link = child;
13090
+ else
13091
+ throw createError(ENOTDIR, "mkdir", child.getPath());
13092
+ } else {
13093
+ link = link.createChild(step, this.createNode(true, modeNum));
13094
+ created = true;
13095
+ }
13096
+ }
13097
+ return created ? fullPath : void 0;
13098
+ };
13099
+ Volume2.prototype.mkdirSync = function(path, options) {
13100
+ var opts = getMkdirOptions(options);
13101
+ var modeNum = modeToNumber(opts.mode, 511);
13102
+ var filename = pathToFilename(path);
13103
+ if (opts.recursive)
13104
+ return this.mkdirpBase(filename, modeNum);
13105
+ this.mkdirBase(filename, modeNum);
13106
+ };
13107
+ Volume2.prototype.mkdir = function(path, a, b) {
13108
+ var opts = getMkdirOptions(a);
13109
+ var callback = validateCallback(typeof a === "function" ? a : b);
13110
+ var modeNum = modeToNumber(opts.mode, 511);
13111
+ var filename = pathToFilename(path);
13112
+ if (opts.recursive)
13113
+ this.wrapAsync(this.mkdirpBase, [filename, modeNum], callback);
13114
+ else
13115
+ this.wrapAsync(this.mkdirBase, [filename, modeNum], callback);
13116
+ };
13117
+ Volume2.prototype.mkdirpSync = function(path, mode) {
13118
+ return this.mkdirSync(path, { mode, recursive: true });
13119
+ };
13120
+ Volume2.prototype.mkdirp = function(path, a, b) {
13121
+ var mode = typeof a === "function" ? void 0 : a;
13122
+ var callback = validateCallback(typeof a === "function" ? a : b);
13123
+ this.mkdir(path, { mode, recursive: true }, callback);
13124
+ };
13125
+ Volume2.prototype.mkdtempBase = function(prefix, encoding, retry) {
13126
+ if (retry === void 0) {
13127
+ retry = 5;
13128
+ }
13129
+ var filename = prefix + this.genRndStr();
12755
13130
  try {
12756
- callback(_this.existsBase(filename));
13131
+ this.mkdirBase(
13132
+ filename,
13133
+ 511
13134
+ /* MODE.DIR */
13135
+ );
13136
+ return (0, encoding_1.strToEncoding)(filename, encoding);
12757
13137
  } catch (err) {
12758
- callback(false);
13138
+ if (err.code === EEXIST) {
13139
+ if (retry > 1)
13140
+ return this.mkdtempBase(prefix, encoding, retry - 1);
13141
+ else
13142
+ throw Error("Could not create temp dir.");
13143
+ } else
13144
+ throw err;
12759
13145
  }
12760
- });
12761
- };
12762
- Volume2.prototype.accessBase = function(filename, mode) {
12763
- this.getLinkOrThrow(filename, "access");
12764
- };
12765
- Volume2.prototype.accessSync = function(path, mode) {
12766
- if (mode === void 0) {
12767
- mode = F_OK;
12768
- }
12769
- var filename = pathToFilename(path);
12770
- mode = mode | 0;
12771
- this.accessBase(filename, mode);
12772
- };
12773
- Volume2.prototype.access = function(path, a, b) {
12774
- var mode = F_OK;
12775
- var callback;
12776
- if (typeof a !== "function") {
12777
- mode = a | 0;
12778
- callback = validateCallback(b);
12779
- } else {
12780
- callback = a;
12781
- }
12782
- var filename = pathToFilename(path);
12783
- this.wrapAsync(this.accessBase, [filename, mode], callback);
12784
- };
12785
- Volume2.prototype.appendFileSync = function(id, data, options) {
12786
- if (options === void 0) {
12787
- options = appendFileDefaults;
12788
- }
12789
- var opts = getAppendFileOpts(options);
12790
- if (!opts.flag || isFd(id))
12791
- opts.flag = "a";
12792
- this.writeFileSync(id, data, opts);
12793
- };
12794
- Volume2.prototype.appendFile = function(id, data, a, b) {
12795
- var _a2 = getAppendFileOptsAndCb(a, b), opts = _a2[0], callback = _a2[1];
12796
- if (!opts.flag || isFd(id))
12797
- opts.flag = "a";
12798
- this.writeFile(id, data, opts, callback);
12799
- };
12800
- Volume2.prototype.readdirBase = function(filename, options) {
12801
- var steps = filenameToSteps(filename);
12802
- var link = this.getResolvedLink(steps);
12803
- if (!link)
12804
- throw createError(ENOENT, "readdir", filename);
12805
- var node = link.getNode();
12806
- if (!node.isDirectory())
12807
- throw createError(ENOTDIR, "scandir", filename);
12808
- if (options.withFileTypes) {
12809
- var list_1 = [];
12810
- for (var name_2 in link.children) {
12811
- var child = link.getChild(name_2);
12812
- if (!child) {
12813
- continue;
13146
+ };
13147
+ Volume2.prototype.mkdtempSync = function(prefix, options) {
13148
+ var encoding = getDefaultOpts(options).encoding;
13149
+ if (!prefix || typeof prefix !== "string")
13150
+ throw new TypeError("filename prefix is required");
13151
+ nullCheck(prefix);
13152
+ return this.mkdtempBase(prefix, encoding);
13153
+ };
13154
+ Volume2.prototype.mkdtemp = function(prefix, a, b) {
13155
+ var _a2 = getDefaultOptsAndCb(a, b), encoding = _a2[0].encoding, callback = _a2[1];
13156
+ if (!prefix || typeof prefix !== "string")
13157
+ throw new TypeError("filename prefix is required");
13158
+ if (!nullCheck(prefix))
13159
+ return;
13160
+ this.wrapAsync(this.mkdtempBase, [prefix, encoding], callback);
13161
+ };
13162
+ Volume2.prototype.rmdirBase = function(filename, options) {
13163
+ var opts = getRmdirOptions(options);
13164
+ var link = this.getLinkAsDirOrThrow(filename, "rmdir");
13165
+ if (link.length && !opts.recursive)
13166
+ throw createError(ENOTEMPTY, "rmdir", filename);
13167
+ this.deleteLink(link);
13168
+ };
13169
+ Volume2.prototype.rmdirSync = function(path, options) {
13170
+ this.rmdirBase(pathToFilename(path), options);
13171
+ };
13172
+ Volume2.prototype.rmdir = function(path, a, b) {
13173
+ var opts = getRmdirOptions(a);
13174
+ var callback = validateCallback(typeof a === "function" ? a : b);
13175
+ this.wrapAsync(this.rmdirBase, [pathToFilename(path), opts], callback);
13176
+ };
13177
+ Volume2.prototype.rmBase = function(filename, options) {
13178
+ if (options === void 0) {
13179
+ options = {};
13180
+ }
13181
+ var link = this.getResolvedLink(filename);
13182
+ if (!link) {
13183
+ if (!options.force)
13184
+ throw createError(ENOENT, "stat", filename);
13185
+ return;
13186
+ }
13187
+ if (link.getNode().isDirectory()) {
13188
+ if (!options.recursive) {
13189
+ throw createError(ERR_FS_EISDIR, "rm", filename);
12814
13190
  }
12815
- list_1.push(Dirent_1.default.build(child, options.encoding));
12816
13191
  }
12817
- if (!isWin && options.encoding !== "buffer")
12818
- list_1.sort(function(a, b) {
12819
- if (a.name < b.name)
12820
- return -1;
12821
- if (a.name > b.name)
12822
- return 1;
12823
- return 0;
12824
- });
12825
- return list_1;
12826
- }
12827
- var list = [];
12828
- for (var name_3 in link.children) {
12829
- list.push((0, encoding_1.strToEncoding)(name_3, options.encoding));
12830
- }
12831
- if (!isWin && options.encoding !== "buffer")
12832
- list.sort();
12833
- return list;
12834
- };
12835
- Volume2.prototype.readdirSync = function(path, options) {
12836
- var opts = getReaddirOptions(options);
12837
- var filename = pathToFilename(path);
12838
- return this.readdirBase(filename, opts);
12839
- };
12840
- Volume2.prototype.readdir = function(path, a, b) {
12841
- var _a2 = getReaddirOptsAndCb(a, b), options = _a2[0], callback = _a2[1];
12842
- var filename = pathToFilename(path);
12843
- this.wrapAsync(this.readdirBase, [filename, options], callback);
12844
- };
12845
- Volume2.prototype.readlinkBase = function(filename, encoding) {
12846
- var link = this.getLinkOrThrow(filename, "readlink");
12847
- var node = link.getNode();
12848
- if (!node.isSymlink())
12849
- throw createError(EINVAL, "readlink", filename);
12850
- var str = sep + node.symlink.join(sep);
12851
- return (0, encoding_1.strToEncoding)(str, encoding);
12852
- };
12853
- Volume2.prototype.readlinkSync = function(path, options) {
12854
- var opts = getDefaultOpts(options);
12855
- var filename = pathToFilename(path);
12856
- return this.readlinkBase(filename, opts.encoding);
12857
- };
12858
- Volume2.prototype.readlink = function(path, a, b) {
12859
- var _a2 = getDefaultOptsAndCb(a, b), opts = _a2[0], callback = _a2[1];
12860
- var filename = pathToFilename(path);
12861
- this.wrapAsync(this.readlinkBase, [filename, opts.encoding], callback);
12862
- };
12863
- Volume2.prototype.fsyncBase = function(fd) {
12864
- this.getFileByFdOrThrow(fd, "fsync");
12865
- };
12866
- Volume2.prototype.fsyncSync = function(fd) {
12867
- this.fsyncBase(fd);
12868
- };
12869
- Volume2.prototype.fsync = function(fd, callback) {
12870
- this.wrapAsync(this.fsyncBase, [fd], callback);
12871
- };
12872
- Volume2.prototype.fdatasyncBase = function(fd) {
12873
- this.getFileByFdOrThrow(fd, "fdatasync");
12874
- };
12875
- Volume2.prototype.fdatasyncSync = function(fd) {
12876
- this.fdatasyncBase(fd);
12877
- };
12878
- Volume2.prototype.fdatasync = function(fd, callback) {
12879
- this.wrapAsync(this.fdatasyncBase, [fd], callback);
12880
- };
12881
- Volume2.prototype.ftruncateBase = function(fd, len) {
12882
- var file = this.getFileByFdOrThrow(fd, "ftruncate");
12883
- file.truncate(len);
12884
- };
12885
- Volume2.prototype.ftruncateSync = function(fd, len) {
12886
- this.ftruncateBase(fd, len);
12887
- };
12888
- Volume2.prototype.ftruncate = function(fd, a, b) {
12889
- var len = typeof a === "number" ? a : 0;
12890
- var callback = validateCallback(typeof a === "number" ? b : a);
12891
- this.wrapAsync(this.ftruncateBase, [fd, len], callback);
12892
- };
12893
- Volume2.prototype.truncateBase = function(path, len) {
12894
- var fd = this.openSync(path, "r+");
12895
- try {
12896
- this.ftruncateSync(fd, len);
12897
- } finally {
12898
- this.closeSync(fd);
12899
- }
12900
- };
12901
- Volume2.prototype.truncateSync = function(id, len) {
12902
- if (isFd(id))
12903
- return this.ftruncateSync(id, len);
12904
- this.truncateBase(id, len);
12905
- };
12906
- Volume2.prototype.truncate = function(id, a, b) {
12907
- var len = typeof a === "number" ? a : 0;
12908
- var callback = validateCallback(typeof a === "number" ? b : a);
12909
- if (isFd(id))
12910
- return this.ftruncate(id, len, callback);
12911
- this.wrapAsync(this.truncateBase, [id, len], callback);
12912
- };
12913
- Volume2.prototype.futimesBase = function(fd, atime, mtime) {
12914
- var file = this.getFileByFdOrThrow(fd, "futimes");
12915
- var node = file.node;
12916
- node.atime = new Date(atime * 1e3);
12917
- node.mtime = new Date(mtime * 1e3);
12918
- };
12919
- Volume2.prototype.futimesSync = function(fd, atime, mtime) {
12920
- this.futimesBase(fd, toUnixTimestamp(atime), toUnixTimestamp(mtime));
12921
- };
12922
- Volume2.prototype.futimes = function(fd, atime, mtime, callback) {
12923
- this.wrapAsync(this.futimesBase, [fd, toUnixTimestamp(atime), toUnixTimestamp(mtime)], callback);
12924
- };
12925
- Volume2.prototype.utimesBase = function(filename, atime, mtime) {
12926
- var fd = this.openSync(filename, "r");
12927
- try {
12928
- this.futimesBase(fd, atime, mtime);
12929
- } finally {
12930
- this.closeSync(fd);
12931
- }
12932
- };
12933
- Volume2.prototype.utimesSync = function(path, atime, mtime) {
12934
- this.utimesBase(pathToFilename(path), toUnixTimestamp(atime), toUnixTimestamp(mtime));
12935
- };
12936
- Volume2.prototype.utimes = function(path, atime, mtime, callback) {
12937
- this.wrapAsync(this.utimesBase, [pathToFilename(path), toUnixTimestamp(atime), toUnixTimestamp(mtime)], callback);
12938
- };
12939
- Volume2.prototype.mkdirBase = function(filename, modeNum) {
12940
- var steps = filenameToSteps(filename);
12941
- if (!steps.length) {
12942
- throw createError(EEXIST, "mkdir", filename);
12943
- }
12944
- var dir = this.getLinkParentAsDirOrThrow(filename, "mkdir");
12945
- var name2 = steps[steps.length - 1];
12946
- if (dir.getChild(name2))
12947
- throw createError(EEXIST, "mkdir", filename);
12948
- dir.createChild(name2, this.createNode(true, modeNum));
12949
- };
12950
- Volume2.prototype.mkdirpBase = function(filename, modeNum) {
12951
- var fullPath = resolve(filename);
12952
- var fullPathSansSlash = fullPath.substring(1);
12953
- var steps = !fullPathSansSlash ? [] : fullPathSansSlash.split(sep);
12954
- var link = this.root;
12955
- var created = false;
12956
- for (var i = 0; i < steps.length; i++) {
12957
- var step = steps[i];
12958
- if (!link.getNode().isDirectory())
12959
- throw createError(ENOTDIR, "mkdir", link.getPath());
12960
- var child = link.getChild(step);
12961
- if (child) {
12962
- if (child.getNode().isDirectory())
12963
- link = child;
12964
- else
12965
- throw createError(ENOTDIR, "mkdir", child.getPath());
12966
- } else {
12967
- link = link.createChild(step, this.createNode(true, modeNum));
12968
- created = true;
13192
+ this.deleteLink(link);
13193
+ };
13194
+ Volume2.prototype.rmSync = function(path, options) {
13195
+ this.rmBase(pathToFilename(path), options);
13196
+ };
13197
+ Volume2.prototype.rm = function(path, a, b) {
13198
+ var _a2 = getRmOptsAndCb(a, b), opts = _a2[0], callback = _a2[1];
13199
+ this.wrapAsync(this.rmBase, [pathToFilename(path), opts], callback);
13200
+ };
13201
+ Volume2.prototype.fchmodBase = function(fd, modeNum) {
13202
+ var file = this.getFileByFdOrThrow(fd, "fchmod");
13203
+ file.chmod(modeNum);
13204
+ };
13205
+ Volume2.prototype.fchmodSync = function(fd, mode) {
13206
+ this.fchmodBase(fd, modeToNumber(mode));
13207
+ };
13208
+ Volume2.prototype.fchmod = function(fd, mode, callback) {
13209
+ this.wrapAsync(this.fchmodBase, [fd, modeToNumber(mode)], callback);
13210
+ };
13211
+ Volume2.prototype.chmodBase = function(filename, modeNum) {
13212
+ var fd = this.openSync(filename, "r");
13213
+ try {
13214
+ this.fchmodBase(fd, modeNum);
13215
+ } finally {
13216
+ this.closeSync(fd);
12969
13217
  }
12970
- }
12971
- return created ? fullPath : void 0;
12972
- };
12973
- Volume2.prototype.mkdirSync = function(path, options) {
12974
- var opts = getMkdirOptions(options);
12975
- var modeNum = modeToNumber(opts.mode, 511);
12976
- var filename = pathToFilename(path);
12977
- if (opts.recursive)
12978
- return this.mkdirpBase(filename, modeNum);
12979
- this.mkdirBase(filename, modeNum);
12980
- };
12981
- Volume2.prototype.mkdir = function(path, a, b) {
12982
- var opts = getMkdirOptions(a);
12983
- var callback = validateCallback(typeof a === "function" ? a : b);
12984
- var modeNum = modeToNumber(opts.mode, 511);
12985
- var filename = pathToFilename(path);
12986
- if (opts.recursive)
12987
- this.wrapAsync(this.mkdirpBase, [filename, modeNum], callback);
12988
- else
12989
- this.wrapAsync(this.mkdirBase, [filename, modeNum], callback);
12990
- };
12991
- Volume2.prototype.mkdirpSync = function(path, mode) {
12992
- return this.mkdirSync(path, { mode, recursive: true });
12993
- };
12994
- Volume2.prototype.mkdirp = function(path, a, b) {
12995
- var mode = typeof a === "function" ? void 0 : a;
12996
- var callback = validateCallback(typeof a === "function" ? a : b);
12997
- this.mkdir(path, { mode, recursive: true }, callback);
12998
- };
12999
- Volume2.prototype.mkdtempBase = function(prefix, encoding, retry) {
13000
- if (retry === void 0) {
13001
- retry = 5;
13002
- }
13003
- var filename = prefix + this.genRndStr();
13004
- try {
13005
- this.mkdirBase(filename, 511);
13006
- return (0, encoding_1.strToEncoding)(filename, encoding);
13007
- } catch (err) {
13008
- if (err.code === EEXIST) {
13009
- if (retry > 1)
13010
- return this.mkdtempBase(prefix, encoding, retry - 1);
13011
- else
13012
- throw Error("Could not create temp dir.");
13013
- } else
13014
- throw err;
13015
- }
13016
- };
13017
- Volume2.prototype.mkdtempSync = function(prefix, options) {
13018
- var encoding = getDefaultOpts(options).encoding;
13019
- if (!prefix || typeof prefix !== "string")
13020
- throw new TypeError("filename prefix is required");
13021
- nullCheck(prefix);
13022
- return this.mkdtempBase(prefix, encoding);
13023
- };
13024
- Volume2.prototype.mkdtemp = function(prefix, a, b) {
13025
- var _a2 = getDefaultOptsAndCb(a, b), encoding = _a2[0].encoding, callback = _a2[1];
13026
- if (!prefix || typeof prefix !== "string")
13027
- throw new TypeError("filename prefix is required");
13028
- if (!nullCheck(prefix))
13029
- return;
13030
- this.wrapAsync(this.mkdtempBase, [prefix, encoding], callback);
13031
- };
13032
- Volume2.prototype.rmdirBase = function(filename, options) {
13033
- var opts = getRmdirOptions(options);
13034
- var link = this.getLinkAsDirOrThrow(filename, "rmdir");
13035
- if (link.length && !opts.recursive)
13036
- throw createError(ENOTEMPTY, "rmdir", filename);
13037
- this.deleteLink(link);
13038
- };
13039
- Volume2.prototype.rmdirSync = function(path, options) {
13040
- this.rmdirBase(pathToFilename(path), options);
13041
- };
13042
- Volume2.prototype.rmdir = function(path, a, b) {
13043
- var opts = getRmdirOptions(a);
13044
- var callback = validateCallback(typeof a === "function" ? a : b);
13045
- this.wrapAsync(this.rmdirBase, [pathToFilename(path), opts], callback);
13046
- };
13047
- Volume2.prototype.rmBase = function(filename, options) {
13048
- if (options === void 0) {
13049
- options = {};
13050
- }
13051
- var link = this.getResolvedLink(filename);
13052
- if (!link) {
13053
- if (!options.force)
13054
- throw createError(ENOENT, "stat", filename);
13055
- return;
13056
- }
13057
- if (link.getNode().isDirectory()) {
13058
- if (!options.recursive) {
13059
- throw createError(ERR_FS_EISDIR, "rm", filename);
13218
+ };
13219
+ Volume2.prototype.chmodSync = function(path, mode) {
13220
+ var modeNum = modeToNumber(mode);
13221
+ var filename = pathToFilename(path);
13222
+ this.chmodBase(filename, modeNum);
13223
+ };
13224
+ Volume2.prototype.chmod = function(path, mode, callback) {
13225
+ var modeNum = modeToNumber(mode);
13226
+ var filename = pathToFilename(path);
13227
+ this.wrapAsync(this.chmodBase, [filename, modeNum], callback);
13228
+ };
13229
+ Volume2.prototype.lchmodBase = function(filename, modeNum) {
13230
+ var fd = this.openBase(filename, O_RDWR, 0, false);
13231
+ try {
13232
+ this.fchmodBase(fd, modeNum);
13233
+ } finally {
13234
+ this.closeSync(fd);
13235
+ }
13236
+ };
13237
+ Volume2.prototype.lchmodSync = function(path, mode) {
13238
+ var modeNum = modeToNumber(mode);
13239
+ var filename = pathToFilename(path);
13240
+ this.lchmodBase(filename, modeNum);
13241
+ };
13242
+ Volume2.prototype.lchmod = function(path, mode, callback) {
13243
+ var modeNum = modeToNumber(mode);
13244
+ var filename = pathToFilename(path);
13245
+ this.wrapAsync(this.lchmodBase, [filename, modeNum], callback);
13246
+ };
13247
+ Volume2.prototype.fchownBase = function(fd, uid, gid) {
13248
+ this.getFileByFdOrThrow(fd, "fchown").chown(uid, gid);
13249
+ };
13250
+ Volume2.prototype.fchownSync = function(fd, uid, gid) {
13251
+ validateUid(uid);
13252
+ validateGid(gid);
13253
+ this.fchownBase(fd, uid, gid);
13254
+ };
13255
+ Volume2.prototype.fchown = function(fd, uid, gid, callback) {
13256
+ validateUid(uid);
13257
+ validateGid(gid);
13258
+ this.wrapAsync(this.fchownBase, [fd, uid, gid], callback);
13259
+ };
13260
+ Volume2.prototype.chownBase = function(filename, uid, gid) {
13261
+ var link = this.getResolvedLinkOrThrow(filename, "chown");
13262
+ var node = link.getNode();
13263
+ node.chown(uid, gid);
13264
+ };
13265
+ Volume2.prototype.chownSync = function(path, uid, gid) {
13266
+ validateUid(uid);
13267
+ validateGid(gid);
13268
+ this.chownBase(pathToFilename(path), uid, gid);
13269
+ };
13270
+ Volume2.prototype.chown = function(path, uid, gid, callback) {
13271
+ validateUid(uid);
13272
+ validateGid(gid);
13273
+ this.wrapAsync(this.chownBase, [pathToFilename(path), uid, gid], callback);
13274
+ };
13275
+ Volume2.prototype.lchownBase = function(filename, uid, gid) {
13276
+ this.getLinkOrThrow(filename, "lchown").getNode().chown(uid, gid);
13277
+ };
13278
+ Volume2.prototype.lchownSync = function(path, uid, gid) {
13279
+ validateUid(uid);
13280
+ validateGid(gid);
13281
+ this.lchownBase(pathToFilename(path), uid, gid);
13282
+ };
13283
+ Volume2.prototype.lchown = function(path, uid, gid, callback) {
13284
+ validateUid(uid);
13285
+ validateGid(gid);
13286
+ this.wrapAsync(this.lchownBase, [pathToFilename(path), uid, gid], callback);
13287
+ };
13288
+ Volume2.prototype.watchFile = function(path, a, b) {
13289
+ var filename = pathToFilename(path);
13290
+ var options = a;
13291
+ var listener = b;
13292
+ if (typeof options === "function") {
13293
+ listener = a;
13294
+ options = null;
13295
+ }
13296
+ if (typeof listener !== "function") {
13297
+ throw Error('"watchFile()" requires a listener function');
13298
+ }
13299
+ var interval = 5007;
13300
+ var persistent = true;
13301
+ if (options && typeof options === "object") {
13302
+ if (typeof options.interval === "number")
13303
+ interval = options.interval;
13304
+ if (typeof options.persistent === "boolean")
13305
+ persistent = options.persistent;
13306
+ }
13307
+ var watcher = this.statWatchers[filename];
13308
+ if (!watcher) {
13309
+ watcher = new this.StatWatcher();
13310
+ watcher.start(filename, persistent, interval);
13311
+ this.statWatchers[filename] = watcher;
13060
13312
  }
13061
- }
13062
- this.deleteLink(link);
13063
- };
13064
- Volume2.prototype.rmSync = function(path, options) {
13065
- this.rmBase(pathToFilename(path), options);
13066
- };
13067
- Volume2.prototype.rm = function(path, a, b) {
13068
- var _a2 = getRmOptsAndCb(a, b), opts = _a2[0], callback = _a2[1];
13069
- this.wrapAsync(this.rmBase, [pathToFilename(path), opts], callback);
13070
- };
13071
- Volume2.prototype.fchmodBase = function(fd, modeNum) {
13072
- var file = this.getFileByFdOrThrow(fd, "fchmod");
13073
- file.chmod(modeNum);
13074
- };
13075
- Volume2.prototype.fchmodSync = function(fd, mode) {
13076
- this.fchmodBase(fd, modeToNumber(mode));
13077
- };
13078
- Volume2.prototype.fchmod = function(fd, mode, callback) {
13079
- this.wrapAsync(this.fchmodBase, [fd, modeToNumber(mode)], callback);
13080
- };
13081
- Volume2.prototype.chmodBase = function(filename, modeNum) {
13082
- var fd = this.openSync(filename, "r");
13083
- try {
13084
- this.fchmodBase(fd, modeNum);
13085
- } finally {
13086
- this.closeSync(fd);
13087
- }
13088
- };
13089
- Volume2.prototype.chmodSync = function(path, mode) {
13090
- var modeNum = modeToNumber(mode);
13091
- var filename = pathToFilename(path);
13092
- this.chmodBase(filename, modeNum);
13093
- };
13094
- Volume2.prototype.chmod = function(path, mode, callback) {
13095
- var modeNum = modeToNumber(mode);
13096
- var filename = pathToFilename(path);
13097
- this.wrapAsync(this.chmodBase, [filename, modeNum], callback);
13098
- };
13099
- Volume2.prototype.lchmodBase = function(filename, modeNum) {
13100
- var fd = this.openBase(filename, O_RDWR, 0, false);
13101
- try {
13102
- this.fchmodBase(fd, modeNum);
13103
- } finally {
13104
- this.closeSync(fd);
13105
- }
13106
- };
13107
- Volume2.prototype.lchmodSync = function(path, mode) {
13108
- var modeNum = modeToNumber(mode);
13109
- var filename = pathToFilename(path);
13110
- this.lchmodBase(filename, modeNum);
13111
- };
13112
- Volume2.prototype.lchmod = function(path, mode, callback) {
13113
- var modeNum = modeToNumber(mode);
13114
- var filename = pathToFilename(path);
13115
- this.wrapAsync(this.lchmodBase, [filename, modeNum], callback);
13116
- };
13117
- Volume2.prototype.fchownBase = function(fd, uid, gid) {
13118
- this.getFileByFdOrThrow(fd, "fchown").chown(uid, gid);
13119
- };
13120
- Volume2.prototype.fchownSync = function(fd, uid, gid) {
13121
- validateUid(uid);
13122
- validateGid(gid);
13123
- this.fchownBase(fd, uid, gid);
13124
- };
13125
- Volume2.prototype.fchown = function(fd, uid, gid, callback) {
13126
- validateUid(uid);
13127
- validateGid(gid);
13128
- this.wrapAsync(this.fchownBase, [fd, uid, gid], callback);
13129
- };
13130
- Volume2.prototype.chownBase = function(filename, uid, gid) {
13131
- var link = this.getResolvedLinkOrThrow(filename, "chown");
13132
- var node = link.getNode();
13133
- node.chown(uid, gid);
13134
- };
13135
- Volume2.prototype.chownSync = function(path, uid, gid) {
13136
- validateUid(uid);
13137
- validateGid(gid);
13138
- this.chownBase(pathToFilename(path), uid, gid);
13139
- };
13140
- Volume2.prototype.chown = function(path, uid, gid, callback) {
13141
- validateUid(uid);
13142
- validateGid(gid);
13143
- this.wrapAsync(this.chownBase, [pathToFilename(path), uid, gid], callback);
13144
- };
13145
- Volume2.prototype.lchownBase = function(filename, uid, gid) {
13146
- this.getLinkOrThrow(filename, "lchown").getNode().chown(uid, gid);
13147
- };
13148
- Volume2.prototype.lchownSync = function(path, uid, gid) {
13149
- validateUid(uid);
13150
- validateGid(gid);
13151
- this.lchownBase(pathToFilename(path), uid, gid);
13152
- };
13153
- Volume2.prototype.lchown = function(path, uid, gid, callback) {
13154
- validateUid(uid);
13155
- validateGid(gid);
13156
- this.wrapAsync(this.lchownBase, [pathToFilename(path), uid, gid], callback);
13157
- };
13158
- Volume2.prototype.watchFile = function(path, a, b) {
13159
- var filename = pathToFilename(path);
13160
- var options = a;
13161
- var listener = b;
13162
- if (typeof options === "function") {
13163
- listener = a;
13164
- options = null;
13165
- }
13166
- if (typeof listener !== "function") {
13167
- throw Error('"watchFile()" requires a listener function');
13168
- }
13169
- var interval = 5007;
13170
- var persistent = true;
13171
- if (options && typeof options === "object") {
13172
- if (typeof options.interval === "number")
13173
- interval = options.interval;
13174
- if (typeof options.persistent === "boolean")
13175
- persistent = options.persistent;
13176
- }
13177
- var watcher = this.statWatchers[filename];
13178
- if (!watcher) {
13179
- watcher = new this.StatWatcher();
13180
- watcher.start(filename, persistent, interval);
13181
- this.statWatchers[filename] = watcher;
13182
- }
13183
- watcher.addListener("change", listener);
13184
- return watcher;
13185
- };
13186
- Volume2.prototype.unwatchFile = function(path, listener) {
13187
- var filename = pathToFilename(path);
13188
- var watcher = this.statWatchers[filename];
13189
- if (!watcher)
13190
- return;
13191
- if (typeof listener === "function") {
13192
- watcher.removeListener("change", listener);
13193
- } else {
13194
- watcher.removeAllListeners("change");
13195
- }
13196
- if (watcher.listenerCount("change") === 0) {
13197
- watcher.stop();
13198
- delete this.statWatchers[filename];
13199
- }
13200
- };
13201
- Volume2.prototype.createReadStream = function(path, options) {
13202
- return new this.ReadStream(path, options);
13203
- };
13204
- Volume2.prototype.createWriteStream = function(path, options) {
13205
- return new this.WriteStream(path, options);
13206
- };
13207
- Volume2.prototype.watch = function(path, options, listener) {
13208
- var filename = pathToFilename(path);
13209
- var givenOptions = options;
13210
- if (typeof options === "function") {
13211
- listener = options;
13212
- givenOptions = null;
13213
- }
13214
- var _a2 = getDefaultOpts(givenOptions), persistent = _a2.persistent, recursive = _a2.recursive, encoding = _a2.encoding;
13215
- if (persistent === void 0)
13216
- persistent = true;
13217
- if (recursive === void 0)
13218
- recursive = false;
13219
- var watcher = new this.FSWatcher();
13220
- watcher.start(filename, persistent, recursive, encoding);
13221
- if (listener) {
13222
13313
  watcher.addListener("change", listener);
13223
- }
13224
- return watcher;
13225
- };
13226
- Volume2.fd = 2147483647;
13227
- return Volume2;
13228
- }();
13314
+ return watcher;
13315
+ };
13316
+ Volume2.prototype.unwatchFile = function(path, listener) {
13317
+ var filename = pathToFilename(path);
13318
+ var watcher = this.statWatchers[filename];
13319
+ if (!watcher)
13320
+ return;
13321
+ if (typeof listener === "function") {
13322
+ watcher.removeListener("change", listener);
13323
+ } else {
13324
+ watcher.removeAllListeners("change");
13325
+ }
13326
+ if (watcher.listenerCount("change") === 0) {
13327
+ watcher.stop();
13328
+ delete this.statWatchers[filename];
13329
+ }
13330
+ };
13331
+ Volume2.prototype.createReadStream = function(path, options) {
13332
+ return new this.ReadStream(path, options);
13333
+ };
13334
+ Volume2.prototype.createWriteStream = function(path, options) {
13335
+ return new this.WriteStream(path, options);
13336
+ };
13337
+ Volume2.prototype.watch = function(path, options, listener) {
13338
+ var filename = pathToFilename(path);
13339
+ var givenOptions = options;
13340
+ if (typeof options === "function") {
13341
+ listener = options;
13342
+ givenOptions = null;
13343
+ }
13344
+ var _a2 = getDefaultOpts(givenOptions), persistent = _a2.persistent, recursive = _a2.recursive, encoding = _a2.encoding;
13345
+ if (persistent === void 0)
13346
+ persistent = true;
13347
+ if (recursive === void 0)
13348
+ recursive = false;
13349
+ var watcher = new this.FSWatcher();
13350
+ watcher.start(filename, persistent, recursive, encoding);
13351
+ if (listener) {
13352
+ watcher.addListener("change", listener);
13353
+ }
13354
+ return watcher;
13355
+ };
13356
+ Volume2.fd = 2147483647;
13357
+ return Volume2;
13358
+ }()
13359
+ );
13229
13360
  exports.Volume = Volume;
13230
13361
  function emitStop(self) {
13231
13362
  self.emit("stop");
13232
13363
  }
13233
- var StatWatcher = function(_super) {
13234
- __extends(StatWatcher2, _super);
13235
- function StatWatcher2(vol) {
13236
- var _this = _super.call(this) || this;
13237
- _this.onInterval = function() {
13238
- try {
13239
- var stats = _this.vol.statSync(_this.filename);
13240
- if (_this.hasChanged(stats)) {
13241
- _this.emit("change", stats, _this.prev);
13242
- _this.prev = stats;
13364
+ var StatWatcher = (
13365
+ /** @class */
13366
+ function(_super) {
13367
+ __extends(StatWatcher2, _super);
13368
+ function StatWatcher2(vol) {
13369
+ var _this = _super.call(this) || this;
13370
+ _this.onInterval = function() {
13371
+ try {
13372
+ var stats = _this.vol.statSync(_this.filename);
13373
+ if (_this.hasChanged(stats)) {
13374
+ _this.emit("change", stats, _this.prev);
13375
+ _this.prev = stats;
13376
+ }
13377
+ } finally {
13378
+ _this.loop();
13243
13379
  }
13244
- } finally {
13245
- _this.loop();
13380
+ };
13381
+ _this.vol = vol;
13382
+ return _this;
13383
+ }
13384
+ StatWatcher2.prototype.loop = function() {
13385
+ this.timeoutRef = this.setTimeout(this.onInterval, this.interval);
13386
+ };
13387
+ StatWatcher2.prototype.hasChanged = function(stats) {
13388
+ if (stats.mtimeMs > this.prev.mtimeMs)
13389
+ return true;
13390
+ if (stats.nlink !== this.prev.nlink)
13391
+ return true;
13392
+ return false;
13393
+ };
13394
+ StatWatcher2.prototype.start = function(path, persistent, interval) {
13395
+ if (persistent === void 0) {
13396
+ persistent = true;
13397
+ }
13398
+ if (interval === void 0) {
13399
+ interval = 5007;
13246
13400
  }
13401
+ this.filename = pathToFilename(path);
13402
+ this.setTimeout = persistent ? setTimeout.bind(typeof globalThis !== "undefined" ? globalThis : globalThis) : setTimeoutUnref_1.default;
13403
+ this.interval = interval;
13404
+ this.prev = this.vol.statSync(this.filename);
13405
+ this.loop();
13247
13406
  };
13248
- _this.vol = vol;
13249
- return _this;
13250
- }
13251
- StatWatcher2.prototype.loop = function() {
13252
- this.timeoutRef = this.setTimeout(this.onInterval, this.interval);
13253
- };
13254
- StatWatcher2.prototype.hasChanged = function(stats) {
13255
- if (stats.mtimeMs > this.prev.mtimeMs)
13256
- return true;
13257
- if (stats.nlink !== this.prev.nlink)
13258
- return true;
13259
- return false;
13260
- };
13261
- StatWatcher2.prototype.start = function(path, persistent, interval) {
13262
- if (persistent === void 0) {
13263
- persistent = true;
13264
- }
13265
- if (interval === void 0) {
13266
- interval = 5007;
13267
- }
13268
- this.filename = pathToFilename(path);
13269
- this.setTimeout = persistent ? setTimeout.bind(typeof globalThis !== "undefined" ? globalThis : globalThis) : setTimeoutUnref_1.default;
13270
- this.interval = interval;
13271
- this.prev = this.vol.statSync(this.filename);
13272
- this.loop();
13273
- };
13274
- StatWatcher2.prototype.stop = function() {
13275
- clearTimeout(this.timeoutRef);
13276
- process_1.default.nextTick(emitStop, this);
13277
- };
13278
- return StatWatcher2;
13279
- }(events_1.EventEmitter);
13407
+ StatWatcher2.prototype.stop = function() {
13408
+ clearTimeout(this.timeoutRef);
13409
+ process_1.default.nextTick(emitStop, this);
13410
+ };
13411
+ return StatWatcher2;
13412
+ }(events_1.EventEmitter)
13413
+ );
13280
13414
  exports.StatWatcher = StatWatcher;
13281
13415
  var pool;
13282
13416
  function allocNewPool(poolSize) {
@@ -13542,78 +13676,81 @@ var kubb = (function (exports) {
13542
13676
  };
13543
13677
  FsWriteStream.prototype._destroy = FsReadStream.prototype._destroy;
13544
13678
  FsWriteStream.prototype.destroySoon = FsWriteStream.prototype.end;
13545
- var FSWatcher = function(_super) {
13546
- __extends(FSWatcher2, _super);
13547
- function FSWatcher2(vol) {
13548
- var _this = _super.call(this) || this;
13549
- _this._filename = "";
13550
- _this._filenameEncoded = "";
13551
- _this._recursive = false;
13552
- _this._encoding = encoding_1.ENCODING_UTF8;
13553
- _this._onNodeChange = function() {
13554
- _this._emit("change");
13679
+ var FSWatcher = (
13680
+ /** @class */
13681
+ function(_super) {
13682
+ __extends(FSWatcher2, _super);
13683
+ function FSWatcher2(vol) {
13684
+ var _this = _super.call(this) || this;
13685
+ _this._filename = "";
13686
+ _this._filenameEncoded = "";
13687
+ _this._recursive = false;
13688
+ _this._encoding = encoding_1.ENCODING_UTF8;
13689
+ _this._onNodeChange = function() {
13690
+ _this._emit("change");
13691
+ };
13692
+ _this._onParentChild = function(link) {
13693
+ if (link.getName() === _this._getName()) {
13694
+ _this._emit("rename");
13695
+ }
13696
+ };
13697
+ _this._emit = function(type) {
13698
+ _this.emit("change", type, _this._filenameEncoded);
13699
+ };
13700
+ _this._persist = function() {
13701
+ _this._timer = setTimeout(_this._persist, 1e6);
13702
+ };
13703
+ _this._vol = vol;
13704
+ return _this;
13705
+ }
13706
+ FSWatcher2.prototype._getName = function() {
13707
+ return this._steps[this._steps.length - 1];
13555
13708
  };
13556
- _this._onParentChild = function(link) {
13557
- if (link.getName() === _this._getName()) {
13558
- _this._emit("rename");
13709
+ FSWatcher2.prototype.start = function(path, persistent, recursive, encoding) {
13710
+ if (persistent === void 0) {
13711
+ persistent = true;
13559
13712
  }
13713
+ if (recursive === void 0) {
13714
+ recursive = false;
13715
+ }
13716
+ if (encoding === void 0) {
13717
+ encoding = encoding_1.ENCODING_UTF8;
13718
+ }
13719
+ this._filename = pathToFilename(path);
13720
+ this._steps = filenameToSteps(this._filename);
13721
+ this._filenameEncoded = (0, encoding_1.strToEncoding)(this._filename);
13722
+ this._recursive = recursive;
13723
+ this._encoding = encoding;
13724
+ try {
13725
+ this._link = this._vol.getLinkOrThrow(this._filename, "FSWatcher");
13726
+ } catch (err) {
13727
+ var error = new Error("watch ".concat(this._filename, " ").concat(err.code));
13728
+ error.code = err.code;
13729
+ error.errno = err.code;
13730
+ throw error;
13731
+ }
13732
+ this._link.getNode().on("change", this._onNodeChange);
13733
+ this._link.on("child:add", this._onNodeChange);
13734
+ this._link.on("child:delete", this._onNodeChange);
13735
+ var parent = this._link.parent;
13736
+ if (parent) {
13737
+ parent.setMaxListeners(parent.getMaxListeners() + 1);
13738
+ parent.on("child:delete", this._onParentChild);
13739
+ }
13740
+ if (persistent)
13741
+ this._persist();
13560
13742
  };
13561
- _this._emit = function(type) {
13562
- _this.emit("change", type, _this._filenameEncoded);
13563
- };
13564
- _this._persist = function() {
13565
- _this._timer = setTimeout(_this._persist, 1e6);
13743
+ FSWatcher2.prototype.close = function() {
13744
+ clearTimeout(this._timer);
13745
+ this._link.getNode().removeListener("change", this._onNodeChange);
13746
+ var parent = this._link.parent;
13747
+ if (parent) {
13748
+ parent.removeListener("child:delete", this._onParentChild);
13749
+ }
13566
13750
  };
13567
- _this._vol = vol;
13568
- return _this;
13569
- }
13570
- FSWatcher2.prototype._getName = function() {
13571
- return this._steps[this._steps.length - 1];
13572
- };
13573
- FSWatcher2.prototype.start = function(path, persistent, recursive, encoding) {
13574
- if (persistent === void 0) {
13575
- persistent = true;
13576
- }
13577
- if (recursive === void 0) {
13578
- recursive = false;
13579
- }
13580
- if (encoding === void 0) {
13581
- encoding = encoding_1.ENCODING_UTF8;
13582
- }
13583
- this._filename = pathToFilename(path);
13584
- this._steps = filenameToSteps(this._filename);
13585
- this._filenameEncoded = (0, encoding_1.strToEncoding)(this._filename);
13586
- this._recursive = recursive;
13587
- this._encoding = encoding;
13588
- try {
13589
- this._link = this._vol.getLinkOrThrow(this._filename, "FSWatcher");
13590
- } catch (err) {
13591
- var error = new Error("watch ".concat(this._filename, " ").concat(err.code));
13592
- error.code = err.code;
13593
- error.errno = err.code;
13594
- throw error;
13595
- }
13596
- this._link.getNode().on("change", this._onNodeChange);
13597
- this._link.on("child:add", this._onNodeChange);
13598
- this._link.on("child:delete", this._onNodeChange);
13599
- var parent = this._link.parent;
13600
- if (parent) {
13601
- parent.setMaxListeners(parent.getMaxListeners() + 1);
13602
- parent.on("child:delete", this._onParentChild);
13603
- }
13604
- if (persistent)
13605
- this._persist();
13606
- };
13607
- FSWatcher2.prototype.close = function() {
13608
- clearTimeout(this._timer);
13609
- this._link.getNode().removeListener("change", this._onNodeChange);
13610
- var parent = this._link.parent;
13611
- if (parent) {
13612
- parent.removeListener("child:delete", this._onParentChild);
13613
- }
13614
- };
13615
- return FSWatcher2;
13616
- }(events_1.EventEmitter);
13751
+ return FSWatcher2;
13752
+ }(events_1.EventEmitter)
13753
+ );
13617
13754
  exports.FSWatcher = FSWatcher;
13618
13755
  }
13619
13756
  });
@@ -16669,6 +16806,9 @@ var kubb = (function (exports) {
16669
16806
  };
16670
16807
  var getFileManagerEvents = (emitter) => {
16671
16808
  return {
16809
+ /**
16810
+ * Emiter
16811
+ */
16672
16812
  emitFile: (id, file) => {
16673
16813
  emitter.emit(keys.getFileKey(), id, file);
16674
16814
  },
@@ -16684,6 +16824,9 @@ var kubb = (function (exports) {
16684
16824
  emitRemove: (id, file) => {
16685
16825
  emitter.emit(keys.getRemoveKey(id), file);
16686
16826
  },
16827
+ /**
16828
+ * Listeners
16829
+ */
16687
16830
  onAdd: (callback) => {
16688
16831
  emitter.on(keys.getFileKey(), callback);
16689
16832
  return () => emitter.removeListener(keys.getFileKey(), callback);
@@ -16921,6 +17064,7 @@ ${file.source}`
16921
17064
  load = async (id) => {
16922
17065
  return this.hookFirst("load", [id]);
16923
17066
  };
17067
+ // run only hook for a specific plugin name
16924
17068
  hookForPlugin(pluginName, hookName, parameters, skipped) {
16925
17069
  let promise = Promise.resolve(null);
16926
17070
  for (const plugin of this.getSortedPlugins(hookName, pluginName)) {
@@ -16934,6 +17078,7 @@ ${file.source}`
16934
17078
  }
16935
17079
  return promise;
16936
17080
  }
17081
+ // chains, first non-null result stops and returns
16937
17082
  hookFirst(hookName, parameters, skipped) {
16938
17083
  let promise = Promise.resolve(null);
16939
17084
  for (const plugin of this.getSortedPlugins(hookName)) {
@@ -16947,6 +17092,7 @@ ${file.source}`
16947
17092
  }
16948
17093
  return promise;
16949
17094
  }
17095
+ // parallel
16950
17096
  async hookParallel(hookName, parameters) {
16951
17097
  const parallelPromises = [];
16952
17098
  for (const plugin of this.getSortedPlugins(hookName)) {
@@ -16961,6 +17107,7 @@ ${file.source}`
16961
17107
  }
16962
17108
  return Promise.all(parallelPromises);
16963
17109
  }
17110
+ // chains, reduces returned value, handling the reduced value as the first hook argument
16964
17111
  hookReduceArg0(hookName, [argument0, ...rest], reduce) {
16965
17112
  let promise = Promise.resolve(argument0);
16966
17113
  for (const plugin of this.getSortedPlugins(hookName)) {
@@ -16972,6 +17119,7 @@ ${file.source}`
16972
17119
  }
16973
17120
  return promise;
16974
17121
  }
17122
+ // chains
16975
17123
  hookSeq(hookName, parameters) {
16976
17124
  let promise = Promise.resolve();
16977
17125
  for (const plugin of this.getSortedPlugins(hookName)) {
@@ -16993,6 +17141,13 @@ ${file.source}`
16993
17141
  }
16994
17142
  return plugins;
16995
17143
  }
17144
+ /**
17145
+ * Run an async plugin hook and return the result.
17146
+ * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
17147
+ * @param args Arguments passed to the plugin hook.
17148
+ * @param plugin The actual pluginObject to run.
17149
+ */
17150
+ // Implementation signature
16996
17151
  run(strategy, hookName, parameters, plugin) {
16997
17152
  const hook = plugin[hookName];
16998
17153
  return Promise.resolve().then(() => {
@@ -17022,6 +17177,13 @@ ${file.source}`
17022
17177
  this.catcher(e, plugin, hookName);
17023
17178
  });
17024
17179
  }
17180
+ /**
17181
+ * Run a sync plugin hook and return the result.
17182
+ * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
17183
+ * @param args Arguments passed to the plugin hook.
17184
+ * @param plugin The acutal plugin
17185
+ * @param replaceContext When passed, the plugin context can be overridden.
17186
+ */
17025
17187
  runSync(hookName, parameters, plugin) {
17026
17188
  const hook = plugin[hookName];
17027
17189
  try {
@@ -17144,21 +17306,33 @@ ${file.source}`
17144
17306
 
17145
17307
  // src/index.ts
17146
17308
  var src_default = build;
17147
- /*!
17148
- * The buffer module from node.js, for the browser.
17149
- *
17150
- * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
17151
- * @license MIT
17152
- */
17153
- /*!
17154
- * The buffer module from node.js, for the browser.
17155
- *
17156
- * @author Feross Aboukhadijeh <https://feross.org>
17157
- * @license MIT
17158
- */
17159
- /*! https://mths.be/punycode v1.3.2 by @mathias */
17160
- /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
17161
- /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
17309
+ /*! Bundled license information:
17310
+
17311
+ ieee754/index.js:
17312
+ (*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)
17313
+
17314
+ buffer/index.js:
17315
+ (*!
17316
+ * The buffer module from node.js, for the browser.
17317
+ *
17318
+ * @author Feross Aboukhadijeh <https://feross.org>
17319
+ * @license MIT
17320
+ *)
17321
+
17322
+ assert/build/internal/util/comparisons.js:
17323
+ (*!
17324
+ * The buffer module from node.js, for the browser.
17325
+ *
17326
+ * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
17327
+ * @license MIT
17328
+ *)
17329
+
17330
+ safe-buffer/index.js:
17331
+ (*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> *)
17332
+
17333
+ punycode/punycode.js:
17334
+ (*! https://mths.be/punycode v1.3.2 by @mathias *)
17335
+ */
17162
17336
 
17163
17337
  exports.FileManager = FileManager;
17164
17338
  exports.Generator = Generator;