@scrabble-solver/scrabble-solver 2.9.2 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/build-manifest.json +11 -11
  3. package/.next/cache/.tsbuildinfo +1 -1
  4. package/.next/cache/eslint/.cache_8dgz12 +1 -1
  5. package/.next/cache/next-server.js.nft.json +1 -1
  6. package/.next/cache/webpack/client-production/0.pack +0 -0
  7. package/.next/cache/webpack/client-production/index.pack +0 -0
  8. package/.next/cache/webpack/edge-server-production/0.pack +0 -0
  9. package/.next/cache/webpack/edge-server-production/index.pack +0 -0
  10. package/.next/cache/webpack/server-production/0.pack +0 -0
  11. package/.next/cache/webpack/server-production/index.pack +0 -0
  12. package/.next/next-server.js.nft.json +1 -1
  13. package/.next/prerender-manifest.json +1 -1
  14. package/.next/routes-manifest.json +1 -1
  15. package/.next/server/chunks/{429.js → 131.js} +2 -3652
  16. package/.next/server/chunks/413.js +367 -185
  17. package/.next/server/chunks/44.js +71 -45
  18. package/.next/server/chunks/515.js +1135 -504
  19. package/.next/server/chunks/911.js +96 -2
  20. package/.next/server/middleware-build-manifest.js +1 -1
  21. package/.next/server/pages/404.html +2 -2
  22. package/.next/server/pages/404.js.nft.json +1 -1
  23. package/.next/server/pages/500.html +2 -2
  24. package/.next/server/pages/_app.js.nft.json +1 -1
  25. package/.next/server/pages/_error.js.nft.json +1 -1
  26. package/.next/server/pages/api/dictionary/[locale]/[word].js +48 -10
  27. package/.next/server/pages/api/dictionary/[locale]/[word].js.nft.json +1 -1
  28. package/.next/server/pages/api/dictionary/[locale].js +1 -8
  29. package/.next/server/pages/api/dictionary/[locale].js.nft.json +1 -1
  30. package/.next/server/pages/api/solve.js +62 -49
  31. package/.next/server/pages/api/solve.js.nft.json +1 -1
  32. package/.next/server/pages/api/verify.js +2 -9
  33. package/.next/server/pages/api/verify.js.nft.json +1 -1
  34. package/.next/server/pages/index.html +4 -8
  35. package/.next/server/pages/index.js +43 -36
  36. package/.next/server/pages/index.js.nft.json +1 -1
  37. package/.next/server/pages/index.json +1 -1
  38. package/.next/server/pages-manifest.json +2 -2
  39. package/.next/static/chunks/368-d423e70be6c0c473.js +1 -0
  40. package/.next/static/chunks/pages/{404-7082923654d5996f.js → 404-932294135c3206dd.js} +1 -1
  41. package/.next/static/chunks/pages/_app-3f5508a5f544d9eb.js +1 -0
  42. package/.next/static/chunks/pages/index-8af7a9d7a2cd98a7.js +1 -0
  43. package/.next/static/css/6b1833fd19d3a74a.css +1 -0
  44. package/.next/static/css/a6154e4ca046ca13.css +1 -0
  45. package/.next/static/css/bad53af6f8616677.css +1 -0
  46. package/.next/static/vscqn7BEtAxJteWSwNnas/_buildManifest.js +1 -0
  47. package/.next/static/{Ntg-ilwD7GqTIFwRpSaTQ → vscqn7BEtAxJteWSwNnas}/_ssgManifest.js +0 -0
  48. package/.next/trace +52 -52
  49. package/package.json +9 -9
  50. package/src/components/Board/components/Cell/Cell.module.scss +45 -9
  51. package/src/components/Board/hooks/useGrid.ts +4 -2
  52. package/src/components/Dictionary/Dictionary.module.scss +8 -1
  53. package/src/components/EmptyState/EmptyState.tsx +6 -2
  54. package/src/components/Loading/Loading.tsx +13 -2
  55. package/src/components/Logo/Logo.svg +62 -0
  56. package/src/components/Logo/index.ts +1 -1
  57. package/src/components/NavButtons/NavButtons.module.scss +8 -7
  58. package/src/components/NavButtons/NavButtons.tsx +35 -28
  59. package/src/components/PlainTiles/PlainTiles.tsx +7 -1
  60. package/src/components/PlainTiles/Tile.tsx +4 -3
  61. package/src/components/Rack/Rack.tsx +4 -2
  62. package/src/components/Radio/Radio.module.scss +1 -1
  63. package/src/components/RemainingTiles/Character.tsx +7 -2
  64. package/src/components/RemainingTiles/RemainingTiles.tsx +28 -20
  65. package/src/components/Results/Cell.tsx +5 -3
  66. package/src/components/Results/Result.tsx +8 -3
  67. package/src/components/Results/Results.module.scss +31 -9
  68. package/src/components/Results/Results.tsx +6 -2
  69. package/src/components/Results/getColumns.ts +58 -0
  70. package/src/components/Settings/components/ConfigSetting/ConfigSetting.module.scss +1 -0
  71. package/src/components/Settings/components/LocaleSetting/LocaleSetting.module.scss +12 -1
  72. package/src/components/Settings/components/LocaleSetting/LocaleSetting.tsx +1 -1
  73. package/src/components/Settings/components/LocaleSetting/options.ts +7 -1
  74. package/src/components/Sidebar/Sidebar.module.scss +42 -8
  75. package/src/components/SvgFontCss/SvgFontCss.tsx +8 -7
  76. package/src/components/SvgFontCss/createCss.ts +11 -0
  77. package/src/components/SvgFontCss/createStyle.ts +9 -0
  78. package/src/components/SvgFontCss/createSvg.ts +10 -0
  79. package/src/components/SvgFontFix/SvgFontFix.module.scss +5 -0
  80. package/src/components/SvgFontFix/SvgFontFix.tsx +21 -0
  81. package/src/components/SvgFontFix/index.ts +1 -0
  82. package/src/components/Tile/Tile.module.scss +10 -2
  83. package/src/components/Tile/Tile.tsx +4 -0
  84. package/src/components/Tile/TilePure.tsx +3 -1
  85. package/src/components/Words/Words.tsx +4 -3
  86. package/src/components/index.ts +1 -0
  87. package/src/hooks/index.ts +2 -0
  88. package/src/hooks/useDirection.ts +22 -0
  89. package/src/hooks/useLanguage.ts +22 -0
  90. package/src/i18n/constants.ts +53 -0
  91. package/src/i18n/fa.json +56 -0
  92. package/src/i18n/i18n.ts +22 -0
  93. package/src/i18n/index.ts +2 -20
  94. package/src/icons/FlagFa.svg +95 -0
  95. package/src/icons/index.ts +1 -0
  96. package/src/lib/createComparator.ts +22 -0
  97. package/src/lib/createKeyComparator.ts +4 -2
  98. package/src/lib/createStringComparator.ts +5 -0
  99. package/src/lib/detectLocale.ts +4 -0
  100. package/src/lib/getRemainingTiles.ts +4 -2
  101. package/src/lib/getRemainingTilesGroups.ts +48 -23
  102. package/src/lib/index.ts +2 -2
  103. package/src/lib/sortResults.ts +11 -9
  104. package/src/lib/unorderedArraysEqual.ts +3 -2
  105. package/src/pages/api/verify.ts +1 -1
  106. package/src/pages/index.module.scss +7 -18
  107. package/src/pages/index.tsx +10 -2
  108. package/src/service-worker/routeVerifyRequests.ts +1 -1
  109. package/src/state/selectors.ts +5 -5
  110. package/src/styles/global.scss +6 -1
  111. package/.next/static/Ntg-ilwD7GqTIFwRpSaTQ/_buildManifest.js +0 -1
  112. package/.next/static/chunks/317-5e5334962dd7c681.js +0 -1
  113. package/.next/static/chunks/pages/_app-183f598b1d4d480b.js +0 -1
  114. package/.next/static/chunks/pages/index-b1ffeaddd9fb64b5.js +0 -1
  115. package/.next/static/css/751e8a14776d05d8.css +0 -1
  116. package/.next/static/css/ad2a08918868cad8.css +0 -1
  117. package/.next/static/css/e8de67ad5ea35427.css +0 -1
  118. package/src/components/Results/constants.ts +0 -42
  119. package/src/lib/comparator.ts +0 -16
  120. package/src/lib/stringComparator.ts +0 -5
@@ -1,5 +1,5 @@
1
- exports.id = 429;
2
- exports.ids = [429];
1
+ exports.id = 131;
2
+ exports.ids = [131];
3
3
  exports.modules = {
4
4
 
5
5
  /***/ 43210:
@@ -18690,89 +18690,6 @@ module.exports = wrap({ http: http, https: https });
18690
18690
  module.exports.wrap = wrap;
18691
18691
 
18692
18692
 
18693
- /***/ }),
18694
-
18695
- /***/ 45867:
18696
- /***/ ((__unused_webpack_module, exports) => {
18697
-
18698
- "use strict";
18699
- var __webpack_unused_export__;
18700
-
18701
-
18702
- __webpack_unused_export__ = ({
18703
- value: true
18704
- });
18705
- exports.Z4 = unixify;
18706
- __webpack_unused_export__ = correctPath;
18707
- var isWin = process.platform === 'win32';
18708
-
18709
- function removeTrailingSeparator(str) {
18710
- var i = str.length - 1;
18711
-
18712
- if (i < 2) {
18713
- return str;
18714
- }
18715
-
18716
- while (isSeparator(str, i)) {
18717
- i--;
18718
- }
18719
-
18720
- return str.substr(0, i + 1);
18721
- }
18722
-
18723
- function isSeparator(str, i) {
18724
- var _char = str[i];
18725
- return i > 0 && (_char === '/' || isWin && _char === '\\');
18726
- }
18727
-
18728
- function normalizePath(str, stripTrailing) {
18729
- if (typeof str !== 'string') {
18730
- throw new TypeError('expected a string');
18731
- }
18732
-
18733
- str = str.replace(/[\\\/]+/g, '/');
18734
-
18735
- if (stripTrailing !== false) {
18736
- str = removeTrailingSeparator(str);
18737
- }
18738
-
18739
- return str;
18740
- }
18741
-
18742
- function unixify(filepath) {
18743
- var stripTrailing = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
18744
-
18745
- if (isWin) {
18746
- filepath = normalizePath(filepath, stripTrailing);
18747
- return filepath.replace(/^([a-zA-Z]+:|\.\/)/, '');
18748
- }
18749
-
18750
- return filepath;
18751
- }
18752
-
18753
- function correctPath(filepath) {
18754
- return unixify(filepath.replace(/^\\\\\?\\.:\\/, '\\'));
18755
- }
18756
-
18757
- /***/ }),
18758
-
18759
- /***/ 2533:
18760
- /***/ ((__unused_webpack_module, exports) => {
18761
-
18762
- "use strict";
18763
-
18764
-
18765
- Object.defineProperty(exports, "__esModule", ({
18766
- value: true
18767
- }));
18768
- exports.fsAsyncMethods = exports.fsSyncMethods = exports.fsProps = void 0;
18769
- var fsProps = ['constants', 'F_OK', 'R_OK', 'W_OK', 'X_OK', 'Stats'];
18770
- exports.fsProps = fsProps;
18771
- var fsSyncMethods = ['renameSync', 'ftruncateSync', 'truncateSync', 'chownSync', 'fchownSync', 'lchownSync', 'chmodSync', 'fchmodSync', 'lchmodSync', 'statSync', 'lstatSync', 'fstatSync', 'linkSync', 'symlinkSync', 'readlinkSync', 'realpathSync', 'unlinkSync', 'rmdirSync', 'mkdirSync', 'mkdirpSync', 'readdirSync', 'closeSync', 'openSync', 'utimesSync', 'futimesSync', 'fsyncSync', 'writeSync', 'readSync', 'readFileSync', 'writeFileSync', 'appendFileSync', 'existsSync', 'accessSync', 'fdatasyncSync', 'mkdtempSync', 'copyFileSync', 'createReadStream', 'createWriteStream'];
18772
- exports.fsSyncMethods = fsSyncMethods;
18773
- var fsAsyncMethods = ['rename', 'ftruncate', 'truncate', 'chown', 'fchown', 'lchown', 'chmod', 'fchmod', 'lchmod', 'stat', 'lstat', 'fstat', 'link', 'symlink', 'readlink', 'realpath', 'unlink', 'rmdir', 'mkdir', 'mkdirp', 'readdir', 'close', 'open', 'utimes', 'futimes', 'fsync', 'write', 'read', 'readFile', 'writeFile', 'appendFile', 'exists', 'access', 'fdatasync', 'mkdtemp', 'copyFile', 'watchFile', 'unwatchFile', 'watch'];
18774
- exports.fsAsyncMethods = fsAsyncMethods;
18775
-
18776
18693
  /***/ }),
18777
18694
 
18778
18695
  /***/ 9242:
@@ -25397,3573 +25314,6 @@ listenerCount = listenerCount || function (ee, event) {
25397
25314
  module.exports = listenerCount
25398
25315
 
25399
25316
 
25400
- /***/ }),
25401
-
25402
- /***/ 90079:
25403
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
25404
-
25405
- "use strict";
25406
-
25407
- Object.defineProperty(exports, "__esModule", ({ value: true }));
25408
- exports.Dirent = void 0;
25409
- var constants_1 = __webpack_require__(34413);
25410
- var encoding_1 = __webpack_require__(68385);
25411
- var S_IFMT = constants_1.constants.S_IFMT, S_IFDIR = constants_1.constants.S_IFDIR, S_IFREG = constants_1.constants.S_IFREG, S_IFBLK = constants_1.constants.S_IFBLK, S_IFCHR = constants_1.constants.S_IFCHR, S_IFLNK = constants_1.constants.S_IFLNK, S_IFIFO = constants_1.constants.S_IFIFO, S_IFSOCK = constants_1.constants.S_IFSOCK;
25412
- /**
25413
- * A directory entry, like `fs.Dirent`.
25414
- */
25415
- var Dirent = /** @class */ (function () {
25416
- function Dirent() {
25417
- this.name = '';
25418
- this.mode = 0;
25419
- }
25420
- Dirent.build = function (link, encoding) {
25421
- var dirent = new Dirent();
25422
- var mode = link.getNode().mode;
25423
- dirent.name = (0, encoding_1.strToEncoding)(link.getName(), encoding);
25424
- dirent.mode = mode;
25425
- return dirent;
25426
- };
25427
- Dirent.prototype._checkModeProperty = function (property) {
25428
- return (this.mode & S_IFMT) === property;
25429
- };
25430
- Dirent.prototype.isDirectory = function () {
25431
- return this._checkModeProperty(S_IFDIR);
25432
- };
25433
- Dirent.prototype.isFile = function () {
25434
- return this._checkModeProperty(S_IFREG);
25435
- };
25436
- Dirent.prototype.isBlockDevice = function () {
25437
- return this._checkModeProperty(S_IFBLK);
25438
- };
25439
- Dirent.prototype.isCharacterDevice = function () {
25440
- return this._checkModeProperty(S_IFCHR);
25441
- };
25442
- Dirent.prototype.isSymbolicLink = function () {
25443
- return this._checkModeProperty(S_IFLNK);
25444
- };
25445
- Dirent.prototype.isFIFO = function () {
25446
- return this._checkModeProperty(S_IFIFO);
25447
- };
25448
- Dirent.prototype.isSocket = function () {
25449
- return this._checkModeProperty(S_IFSOCK);
25450
- };
25451
- return Dirent;
25452
- }());
25453
- exports.Dirent = Dirent;
25454
- exports["default"] = Dirent;
25455
-
25456
-
25457
- /***/ }),
25458
-
25459
- /***/ 21860:
25460
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
25461
-
25462
- "use strict";
25463
-
25464
- Object.defineProperty(exports, "__esModule", ({ value: true }));
25465
- exports.Stats = void 0;
25466
- var constants_1 = __webpack_require__(34413);
25467
- var getBigInt_1 = __webpack_require__(917);
25468
- var S_IFMT = constants_1.constants.S_IFMT, S_IFDIR = constants_1.constants.S_IFDIR, S_IFREG = constants_1.constants.S_IFREG, S_IFBLK = constants_1.constants.S_IFBLK, S_IFCHR = constants_1.constants.S_IFCHR, S_IFLNK = constants_1.constants.S_IFLNK, S_IFIFO = constants_1.constants.S_IFIFO, S_IFSOCK = constants_1.constants.S_IFSOCK;
25469
- /**
25470
- * Statistics about a file/directory, like `fs.Stats`.
25471
- */
25472
- var Stats = /** @class */ (function () {
25473
- function Stats() {
25474
- }
25475
- Stats.build = function (node, bigint) {
25476
- if (bigint === void 0) { bigint = false; }
25477
- var stats = new Stats();
25478
- var uid = node.uid, gid = node.gid, atime = node.atime, mtime = node.mtime, ctime = node.ctime;
25479
- var getStatNumber = !bigint ? function (number) { return number; } : getBigInt_1.default;
25480
- // Copy all values on Stats from Node, so that if Node values
25481
- // change, values on Stats would still be the old ones,
25482
- // just like in Node fs.
25483
- stats.uid = getStatNumber(uid);
25484
- stats.gid = getStatNumber(gid);
25485
- stats.rdev = getStatNumber(0);
25486
- stats.blksize = getStatNumber(4096);
25487
- stats.ino = getStatNumber(node.ino);
25488
- stats.size = getStatNumber(node.getSize());
25489
- stats.blocks = getStatNumber(1);
25490
- stats.atime = atime;
25491
- stats.mtime = mtime;
25492
- stats.ctime = ctime;
25493
- stats.birthtime = ctime;
25494
- stats.atimeMs = getStatNumber(atime.getTime());
25495
- stats.mtimeMs = getStatNumber(mtime.getTime());
25496
- var ctimeMs = getStatNumber(ctime.getTime());
25497
- stats.ctimeMs = ctimeMs;
25498
- stats.birthtimeMs = ctimeMs;
25499
- stats.dev = getStatNumber(0);
25500
- stats.mode = getStatNumber(node.mode);
25501
- stats.nlink = getStatNumber(node.nlink);
25502
- return stats;
25503
- };
25504
- Stats.prototype._checkModeProperty = function (property) {
25505
- return (Number(this.mode) & S_IFMT) === property;
25506
- };
25507
- Stats.prototype.isDirectory = function () {
25508
- return this._checkModeProperty(S_IFDIR);
25509
- };
25510
- Stats.prototype.isFile = function () {
25511
- return this._checkModeProperty(S_IFREG);
25512
- };
25513
- Stats.prototype.isBlockDevice = function () {
25514
- return this._checkModeProperty(S_IFBLK);
25515
- };
25516
- Stats.prototype.isCharacterDevice = function () {
25517
- return this._checkModeProperty(S_IFCHR);
25518
- };
25519
- Stats.prototype.isSymbolicLink = function () {
25520
- return this._checkModeProperty(S_IFLNK);
25521
- };
25522
- Stats.prototype.isFIFO = function () {
25523
- return this._checkModeProperty(S_IFIFO);
25524
- };
25525
- Stats.prototype.isSocket = function () {
25526
- return this._checkModeProperty(S_IFSOCK);
25527
- };
25528
- return Stats;
25529
- }());
25530
- exports.Stats = Stats;
25531
- exports["default"] = Stats;
25532
-
25533
-
25534
- /***/ }),
25535
-
25536
- /***/ 34413:
25537
- /***/ ((__unused_webpack_module, exports) => {
25538
-
25539
- "use strict";
25540
-
25541
- Object.defineProperty(exports, "__esModule", ({ value: true }));
25542
- exports.constants = void 0;
25543
- exports.constants = {
25544
- O_RDONLY: 0,
25545
- O_WRONLY: 1,
25546
- O_RDWR: 2,
25547
- S_IFMT: 61440,
25548
- S_IFREG: 32768,
25549
- S_IFDIR: 16384,
25550
- S_IFCHR: 8192,
25551
- S_IFBLK: 24576,
25552
- S_IFIFO: 4096,
25553
- S_IFLNK: 40960,
25554
- S_IFSOCK: 49152,
25555
- O_CREAT: 64,
25556
- O_EXCL: 128,
25557
- O_NOCTTY: 256,
25558
- O_TRUNC: 512,
25559
- O_APPEND: 1024,
25560
- O_DIRECTORY: 65536,
25561
- O_NOATIME: 262144,
25562
- O_NOFOLLOW: 131072,
25563
- O_SYNC: 1052672,
25564
- O_DIRECT: 16384,
25565
- O_NONBLOCK: 2048,
25566
- S_IRWXU: 448,
25567
- S_IRUSR: 256,
25568
- S_IWUSR: 128,
25569
- S_IXUSR: 64,
25570
- S_IRWXG: 56,
25571
- S_IRGRP: 32,
25572
- S_IWGRP: 16,
25573
- S_IXGRP: 8,
25574
- S_IRWXO: 7,
25575
- S_IROTH: 4,
25576
- S_IWOTH: 2,
25577
- S_IXOTH: 1,
25578
- F_OK: 0,
25579
- R_OK: 4,
25580
- W_OK: 2,
25581
- X_OK: 1,
25582
- UV_FS_SYMLINK_DIR: 1,
25583
- UV_FS_SYMLINK_JUNCTION: 2,
25584
- UV_FS_COPYFILE_EXCL: 1,
25585
- UV_FS_COPYFILE_FICLONE: 2,
25586
- UV_FS_COPYFILE_FICLONE_FORCE: 4,
25587
- COPYFILE_EXCL: 1,
25588
- COPYFILE_FICLONE: 2,
25589
- COPYFILE_FICLONE_FORCE: 4,
25590
- };
25591
-
25592
-
25593
- /***/ }),
25594
-
25595
- /***/ 68385:
25596
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
25597
-
25598
- "use strict";
25599
-
25600
- Object.defineProperty(exports, "__esModule", ({ value: true }));
25601
- exports.strToEncoding = exports.assertEncoding = exports.ENCODING_UTF8 = void 0;
25602
- var buffer_1 = __webpack_require__(52975);
25603
- var errors = __webpack_require__(11904);
25604
- exports.ENCODING_UTF8 = 'utf8';
25605
- function assertEncoding(encoding) {
25606
- if (encoding && !buffer_1.Buffer.isEncoding(encoding))
25607
- throw new errors.TypeError('ERR_INVALID_OPT_VALUE_ENCODING', encoding);
25608
- }
25609
- exports.assertEncoding = assertEncoding;
25610
- function strToEncoding(str, encoding) {
25611
- if (!encoding || encoding === exports.ENCODING_UTF8)
25612
- return str; // UTF-8
25613
- if (encoding === 'buffer')
25614
- return new buffer_1.Buffer(str); // `buffer` encoding
25615
- return new buffer_1.Buffer(str).toString(encoding); // Custom encoding
25616
- }
25617
- exports.strToEncoding = strToEncoding;
25618
-
25619
-
25620
- /***/ }),
25621
-
25622
- /***/ 917:
25623
- /***/ ((__unused_webpack_module, exports) => {
25624
-
25625
- if (typeof BigInt === 'function') exports["default"] = BigInt;
25626
- else
25627
- exports["default"] = function BigIntNotSupported() {
25628
- throw new Error('BigInt is not supported in this environment.');
25629
- };
25630
-
25631
-
25632
- /***/ }),
25633
-
25634
- /***/ 28098:
25635
- /***/ (function(module, exports, __webpack_require__) {
25636
-
25637
- "use strict";
25638
-
25639
- var __assign = (this && this.__assign) || function () {
25640
- __assign = Object.assign || function(t) {
25641
- for (var s, i = 1, n = arguments.length; i < n; i++) {
25642
- s = arguments[i];
25643
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
25644
- t[p] = s[p];
25645
- }
25646
- return t;
25647
- };
25648
- return __assign.apply(this, arguments);
25649
- };
25650
- Object.defineProperty(exports, "__esModule", ({ value: true }));
25651
- exports.fs = exports.createFsFromVolume = exports.vol = exports.Volume = void 0;
25652
- var Stats_1 = __webpack_require__(21860);
25653
- var Dirent_1 = __webpack_require__(90079);
25654
- var volume_1 = __webpack_require__(22682);
25655
- var _a = __webpack_require__(2533), fsSyncMethods = _a.fsSyncMethods, fsAsyncMethods = _a.fsAsyncMethods;
25656
- var constants_1 = __webpack_require__(34413);
25657
- var F_OK = constants_1.constants.F_OK, R_OK = constants_1.constants.R_OK, W_OK = constants_1.constants.W_OK, X_OK = constants_1.constants.X_OK;
25658
- exports.Volume = volume_1.Volume;
25659
- // Default volume.
25660
- exports.vol = new volume_1.Volume();
25661
- function createFsFromVolume(vol) {
25662
- var fs = { F_OK: F_OK, R_OK: R_OK, W_OK: W_OK, X_OK: X_OK, constants: constants_1.constants, Stats: Stats_1.default, Dirent: Dirent_1.default };
25663
- // Bind FS methods.
25664
- for (var _i = 0, fsSyncMethods_1 = fsSyncMethods; _i < fsSyncMethods_1.length; _i++) {
25665
- var method = fsSyncMethods_1[_i];
25666
- if (typeof vol[method] === 'function')
25667
- fs[method] = vol[method].bind(vol);
25668
- }
25669
- for (var _a = 0, fsAsyncMethods_1 = fsAsyncMethods; _a < fsAsyncMethods_1.length; _a++) {
25670
- var method = fsAsyncMethods_1[_a];
25671
- if (typeof vol[method] === 'function')
25672
- fs[method] = vol[method].bind(vol);
25673
- }
25674
- fs.StatWatcher = vol.StatWatcher;
25675
- fs.FSWatcher = vol.FSWatcher;
25676
- fs.WriteStream = vol.WriteStream;
25677
- fs.ReadStream = vol.ReadStream;
25678
- fs.promises = vol.promises;
25679
- fs._toUnixTimestamp = volume_1.toUnixTimestamp;
25680
- return fs;
25681
- }
25682
- exports.createFsFromVolume = createFsFromVolume;
25683
- exports.fs = createFsFromVolume(exports.vol);
25684
- module.exports = __assign(__assign({}, module.exports), exports.fs);
25685
- module.exports.semantic = true;
25686
-
25687
-
25688
- /***/ }),
25689
-
25690
- /***/ 52975:
25691
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
25692
-
25693
- "use strict";
25694
-
25695
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
25696
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
25697
- if (ar || !(i in from)) {
25698
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
25699
- ar[i] = from[i];
25700
- }
25701
- }
25702
- return to.concat(ar || Array.prototype.slice.call(from));
25703
- };
25704
- Object.defineProperty(exports, "__esModule", ({ value: true }));
25705
- exports.bufferFrom = exports.bufferAllocUnsafe = exports.Buffer = void 0;
25706
- var buffer_1 = __webpack_require__(60871);
25707
- Object.defineProperty(exports, "Buffer", ({ enumerable: true, get: function () { return buffer_1.Buffer; } }));
25708
- function bufferV0P12Ponyfill(arg0) {
25709
- var args = [];
25710
- for (var _i = 1; _i < arguments.length; _i++) {
25711
- args[_i - 1] = arguments[_i];
25712
- }
25713
- return new (buffer_1.Buffer.bind.apply(buffer_1.Buffer, __spreadArray([void 0, arg0], args, false)))();
25714
- }
25715
- var bufferAllocUnsafe = buffer_1.Buffer.allocUnsafe || bufferV0P12Ponyfill;
25716
- exports.bufferAllocUnsafe = bufferAllocUnsafe;
25717
- var bufferFrom = buffer_1.Buffer.from || bufferV0P12Ponyfill;
25718
- exports.bufferFrom = bufferFrom;
25719
-
25720
-
25721
- /***/ }),
25722
-
25723
- /***/ 11904:
25724
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
25725
-
25726
- "use strict";
25727
-
25728
- // The whole point behind this internal module is to allow Node.js to no
25729
- // longer be forced to treat every error message change as a semver-major
25730
- // change. The NodeError classes here all expose a `code` property whose
25731
- // value statically and permanently identifies the error. While the error
25732
- // message may change, the code should not.
25733
- var __extends = (this && this.__extends) || (function () {
25734
- var extendStatics = function (d, b) {
25735
- extendStatics = Object.setPrototypeOf ||
25736
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
25737
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
25738
- return extendStatics(d, b);
25739
- };
25740
- return function (d, b) {
25741
- if (typeof b !== "function" && b !== null)
25742
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
25743
- extendStatics(d, b);
25744
- function __() { this.constructor = d; }
25745
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
25746
- };
25747
- })();
25748
- Object.defineProperty(exports, "__esModule", ({ value: true }));
25749
- exports.E = exports.AssertionError = exports.message = exports.RangeError = exports.TypeError = exports.Error = void 0;
25750
- var assert = __webpack_require__(39491);
25751
- var util = __webpack_require__(73837);
25752
- var kCode = typeof Symbol === 'undefined' ? '_kCode' : Symbol('code');
25753
- var messages = {}; // new Map();
25754
- function makeNodeError(Base) {
25755
- return /** @class */ (function (_super) {
25756
- __extends(NodeError, _super);
25757
- function NodeError(key) {
25758
- var args = [];
25759
- for (var _i = 1; _i < arguments.length; _i++) {
25760
- args[_i - 1] = arguments[_i];
25761
- }
25762
- var _this = _super.call(this, message(key, args)) || this;
25763
- _this.code = key;
25764
- _this[kCode] = key;
25765
- _this.name = "".concat(_super.prototype.name, " [").concat(_this[kCode], "]");
25766
- return _this;
25767
- }
25768
- return NodeError;
25769
- }(Base));
25770
- }
25771
- var g = typeof globalThis !== 'undefined' ? globalThis : global;
25772
- var AssertionError = /** @class */ (function (_super) {
25773
- __extends(AssertionError, _super);
25774
- function AssertionError(options) {
25775
- var _this = this;
25776
- if (typeof options !== 'object' || options === null) {
25777
- throw new exports.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object');
25778
- }
25779
- if (options.message) {
25780
- _this = _super.call(this, options.message) || this;
25781
- }
25782
- else {
25783
- _this = _super.call(this, "".concat(util.inspect(options.actual).slice(0, 128), " ") +
25784
- "".concat(options.operator, " ").concat(util.inspect(options.expected).slice(0, 128))) || this;
25785
- }
25786
- _this.generatedMessage = !options.message;
25787
- _this.name = 'AssertionError [ERR_ASSERTION]';
25788
- _this.code = 'ERR_ASSERTION';
25789
- _this.actual = options.actual;
25790
- _this.expected = options.expected;
25791
- _this.operator = options.operator;
25792
- exports.Error.captureStackTrace(_this, options.stackStartFunction);
25793
- return _this;
25794
- }
25795
- return AssertionError;
25796
- }(g.Error));
25797
- exports.AssertionError = AssertionError;
25798
- function message(key, args) {
25799
- assert.strictEqual(typeof key, 'string');
25800
- // const msg = messages.get(key);
25801
- var msg = messages[key];
25802
- assert(msg, "An invalid error message key was used: ".concat(key, "."));
25803
- var fmt;
25804
- if (typeof msg === 'function') {
25805
- fmt = msg;
25806
- }
25807
- else {
25808
- fmt = util.format;
25809
- if (args === undefined || args.length === 0)
25810
- return msg;
25811
- args.unshift(msg);
25812
- }
25813
- return String(fmt.apply(null, args));
25814
- }
25815
- exports.message = message;
25816
- // Utility function for registering the error codes. Only used here. Exported
25817
- // *only* to allow for testing.
25818
- function E(sym, val) {
25819
- messages[sym] = typeof val === 'function' ? val : String(val);
25820
- }
25821
- exports.E = E;
25822
- exports.Error = makeNodeError(g.Error);
25823
- exports.TypeError = makeNodeError(g.TypeError);
25824
- exports.RangeError = makeNodeError(g.RangeError);
25825
- // To declare an error message, use the E(sym, val) function above. The sym
25826
- // must be an upper case string. The val can be either a function or a string.
25827
- // The return value of the function must be a string.
25828
- // Examples:
25829
- // E('EXAMPLE_KEY1', 'This is the error value');
25830
- // E('EXAMPLE_KEY2', (a, b) => return `${a} ${b}`);
25831
- //
25832
- // Once an error code has been assigned, the code itself MUST NOT change and
25833
- // any given error code must never be reused to identify a different error.
25834
- //
25835
- // Any error code added here should also be added to the documentation
25836
- //
25837
- // Note: Please try to keep these in alphabetical order
25838
- E('ERR_ARG_NOT_ITERABLE', '%s must be iterable');
25839
- E('ERR_ASSERTION', '%s');
25840
- E('ERR_BUFFER_OUT_OF_BOUNDS', bufferOutOfBounds);
25841
- E('ERR_CHILD_CLOSED_BEFORE_REPLY', 'Child closed before reply received');
25842
- E('ERR_CONSOLE_WRITABLE_STREAM', 'Console expects a writable stream instance for %s');
25843
- E('ERR_CPU_USAGE', 'Unable to obtain cpu usage %s');
25844
- E('ERR_DNS_SET_SERVERS_FAILED', function (err, servers) { return "c-ares failed to set servers: \"".concat(err, "\" [").concat(servers, "]"); });
25845
- E('ERR_FALSY_VALUE_REJECTION', 'Promise was rejected with falsy value');
25846
- E('ERR_ENCODING_NOT_SUPPORTED', function (enc) { return "The \"".concat(enc, "\" encoding is not supported"); });
25847
- E('ERR_ENCODING_INVALID_ENCODED_DATA', function (enc) { return "The encoded data was not valid for encoding ".concat(enc); });
25848
- E('ERR_HTTP_HEADERS_SENT', 'Cannot render headers after they are sent to the client');
25849
- E('ERR_HTTP_INVALID_STATUS_CODE', 'Invalid status code: %s');
25850
- E('ERR_HTTP_TRAILER_INVALID', 'Trailers are invalid with this transfer encoding');
25851
- E('ERR_INDEX_OUT_OF_RANGE', 'Index out of range');
25852
- E('ERR_INVALID_ARG_TYPE', invalidArgType);
25853
- E('ERR_INVALID_ARRAY_LENGTH', function (name, len, actual) {
25854
- assert.strictEqual(typeof actual, 'number');
25855
- return "The array \"".concat(name, "\" (length ").concat(actual, ") must be of length ").concat(len, ".");
25856
- });
25857
- E('ERR_INVALID_BUFFER_SIZE', 'Buffer size must be a multiple of %s');
25858
- E('ERR_INVALID_CALLBACK', 'Callback must be a function');
25859
- E('ERR_INVALID_CHAR', 'Invalid character in %s');
25860
- E('ERR_INVALID_CURSOR_POS', 'Cannot set cursor row without setting its column');
25861
- E('ERR_INVALID_FD', '"fd" must be a positive integer: %s');
25862
- E('ERR_INVALID_FILE_URL_HOST', 'File URL host must be "localhost" or empty on %s');
25863
- E('ERR_INVALID_FILE_URL_PATH', 'File URL path %s');
25864
- E('ERR_INVALID_HANDLE_TYPE', 'This handle type cannot be sent');
25865
- E('ERR_INVALID_IP_ADDRESS', 'Invalid IP address: %s');
25866
- E('ERR_INVALID_OPT_VALUE', function (name, value) {
25867
- return "The value \"".concat(String(value), "\" is invalid for option \"").concat(name, "\"");
25868
- });
25869
- E('ERR_INVALID_OPT_VALUE_ENCODING', function (value) { return "The value \"".concat(String(value), "\" is invalid for option \"encoding\""); });
25870
- E('ERR_INVALID_REPL_EVAL_CONFIG', 'Cannot specify both "breakEvalOnSigint" and "eval" for REPL');
25871
- E('ERR_INVALID_SYNC_FORK_INPUT', 'Asynchronous forks do not support Buffer, Uint8Array or string input: %s');
25872
- E('ERR_INVALID_THIS', 'Value of "this" must be of type %s');
25873
- E('ERR_INVALID_TUPLE', '%s must be an iterable %s tuple');
25874
- E('ERR_INVALID_URL', 'Invalid URL: %s');
25875
- E('ERR_INVALID_URL_SCHEME', function (expected) { return "The URL must be ".concat(oneOf(expected, 'scheme')); });
25876
- E('ERR_IPC_CHANNEL_CLOSED', 'Channel closed');
25877
- E('ERR_IPC_DISCONNECTED', 'IPC channel is already disconnected');
25878
- E('ERR_IPC_ONE_PIPE', 'Child process can have only one IPC pipe');
25879
- E('ERR_IPC_SYNC_FORK', 'IPC cannot be used with synchronous forks');
25880
- E('ERR_MISSING_ARGS', missingArgs);
25881
- E('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times');
25882
- E('ERR_NAPI_CONS_FUNCTION', 'Constructor must be a function');
25883
- E('ERR_NAPI_CONS_PROTOTYPE_OBJECT', 'Constructor.prototype must be an object');
25884
- E('ERR_NO_CRYPTO', 'Node.js is not compiled with OpenSSL crypto support');
25885
- E('ERR_NO_LONGER_SUPPORTED', '%s is no longer supported');
25886
- E('ERR_PARSE_HISTORY_DATA', 'Could not parse history data in %s');
25887
- E('ERR_SOCKET_ALREADY_BOUND', 'Socket is already bound');
25888
- E('ERR_SOCKET_BAD_PORT', 'Port should be > 0 and < 65536');
25889
- E('ERR_SOCKET_BAD_TYPE', 'Bad socket type specified. Valid types are: udp4, udp6');
25890
- E('ERR_SOCKET_CANNOT_SEND', 'Unable to send data');
25891
- E('ERR_SOCKET_CLOSED', 'Socket is closed');
25892
- E('ERR_SOCKET_DGRAM_NOT_RUNNING', 'Not running');
25893
- E('ERR_STDERR_CLOSE', 'process.stderr cannot be closed');
25894
- E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed');
25895
- E('ERR_STREAM_WRAP', 'Stream has StringDecoder set or is in objectMode');
25896
- E('ERR_TLS_CERT_ALTNAME_INVALID', "Hostname/IP does not match certificate's altnames: %s");
25897
- E('ERR_TLS_DH_PARAM_SIZE', function (size) { return "DH parameter size ".concat(size, " is less than 2048"); });
25898
- E('ERR_TLS_HANDSHAKE_TIMEOUT', 'TLS handshake timeout');
25899
- E('ERR_TLS_RENEGOTIATION_FAILED', 'Failed to renegotiate');
25900
- E('ERR_TLS_REQUIRED_SERVER_NAME', '"servername" is required parameter for Server.addContext');
25901
- E('ERR_TLS_SESSION_ATTACK', 'TSL session renegotiation attack detected');
25902
- E('ERR_TRANSFORM_ALREADY_TRANSFORMING', 'Calling transform done when still transforming');
25903
- E('ERR_TRANSFORM_WITH_LENGTH_0', 'Calling transform done when writableState.length != 0');
25904
- E('ERR_UNKNOWN_ENCODING', 'Unknown encoding: %s');
25905
- E('ERR_UNKNOWN_SIGNAL', 'Unknown signal: %s');
25906
- E('ERR_UNKNOWN_STDIN_TYPE', 'Unknown stdin file type');
25907
- E('ERR_UNKNOWN_STREAM_TYPE', 'Unknown stream file type');
25908
- E('ERR_V8BREAKITERATOR', 'Full ICU data not installed. ' + 'See https://github.com/nodejs/node/wiki/Intl');
25909
- function invalidArgType(name, expected, actual) {
25910
- assert(name, 'name is required');
25911
- // determiner: 'must be' or 'must not be'
25912
- var determiner;
25913
- if (expected.includes('not ')) {
25914
- determiner = 'must not be';
25915
- expected = expected.split('not ')[1];
25916
- }
25917
- else {
25918
- determiner = 'must be';
25919
- }
25920
- var msg;
25921
- if (Array.isArray(name)) {
25922
- var names = name.map(function (val) { return "\"".concat(val, "\""); }).join(', ');
25923
- msg = "The ".concat(names, " arguments ").concat(determiner, " ").concat(oneOf(expected, 'type'));
25924
- }
25925
- else if (name.includes(' argument')) {
25926
- // for the case like 'first argument'
25927
- msg = "The ".concat(name, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
25928
- }
25929
- else {
25930
- var type = name.includes('.') ? 'property' : 'argument';
25931
- msg = "The \"".concat(name, "\" ").concat(type, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
25932
- }
25933
- // if actual value received, output it
25934
- if (arguments.length >= 3) {
25935
- msg += ". Received type ".concat(actual !== null ? typeof actual : 'null');
25936
- }
25937
- return msg;
25938
- }
25939
- function missingArgs() {
25940
- var args = [];
25941
- for (var _i = 0; _i < arguments.length; _i++) {
25942
- args[_i] = arguments[_i];
25943
- }
25944
- assert(args.length > 0, 'At least one arg needs to be specified');
25945
- var msg = 'The ';
25946
- var len = args.length;
25947
- args = args.map(function (a) { return "\"".concat(a, "\""); });
25948
- switch (len) {
25949
- case 1:
25950
- msg += "".concat(args[0], " argument");
25951
- break;
25952
- case 2:
25953
- msg += "".concat(args[0], " and ").concat(args[1], " arguments");
25954
- break;
25955
- default:
25956
- msg += args.slice(0, len - 1).join(', ');
25957
- msg += ", and ".concat(args[len - 1], " arguments");
25958
- break;
25959
- }
25960
- return "".concat(msg, " must be specified");
25961
- }
25962
- function oneOf(expected, thing) {
25963
- assert(expected, 'expected is required');
25964
- assert(typeof thing === 'string', 'thing is required');
25965
- if (Array.isArray(expected)) {
25966
- var len = expected.length;
25967
- assert(len > 0, 'At least one expected value needs to be specified');
25968
- // tslint:disable-next-line
25969
- expected = expected.map(function (i) { return String(i); });
25970
- if (len > 2) {
25971
- return "one of ".concat(thing, " ").concat(expected.slice(0, len - 1).join(', '), ", or ") + expected[len - 1];
25972
- }
25973
- else if (len === 2) {
25974
- return "one of ".concat(thing, " ").concat(expected[0], " or ").concat(expected[1]);
25975
- }
25976
- else {
25977
- return "of ".concat(thing, " ").concat(expected[0]);
25978
- }
25979
- }
25980
- else {
25981
- return "of ".concat(thing, " ").concat(String(expected));
25982
- }
25983
- }
25984
- function bufferOutOfBounds(name, isWriting) {
25985
- if (isWriting) {
25986
- return 'Attempt to write outside buffer bounds';
25987
- }
25988
- else {
25989
- return "\"".concat(name, "\" is outside of buffer bounds");
25990
- }
25991
- }
25992
-
25993
-
25994
- /***/ }),
25995
-
25996
- /***/ 81115:
25997
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
25998
-
25999
- "use strict";
26000
-
26001
- var __extends = (this && this.__extends) || (function () {
26002
- var extendStatics = function (d, b) {
26003
- extendStatics = Object.setPrototypeOf ||
26004
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
26005
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
26006
- return extendStatics(d, b);
26007
- };
26008
- return function (d, b) {
26009
- if (typeof b !== "function" && b !== null)
26010
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
26011
- extendStatics(d, b);
26012
- function __() { this.constructor = d; }
26013
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
26014
- };
26015
- })();
26016
- Object.defineProperty(exports, "__esModule", ({ value: true }));
26017
- exports.File = exports.Link = exports.Node = exports.SEP = void 0;
26018
- var process_1 = __webpack_require__(31597);
26019
- var buffer_1 = __webpack_require__(52975);
26020
- var constants_1 = __webpack_require__(34413);
26021
- var events_1 = __webpack_require__(82361);
26022
- var Stats_1 = __webpack_require__(21860);
26023
- var S_IFMT = constants_1.constants.S_IFMT, S_IFDIR = constants_1.constants.S_IFDIR, S_IFREG = constants_1.constants.S_IFREG, S_IFLNK = constants_1.constants.S_IFLNK, O_APPEND = constants_1.constants.O_APPEND;
26024
- var getuid = function () { var _a, _b; return (_b = (_a = process_1.default.getuid) === null || _a === void 0 ? void 0 : _a.call(process_1.default)) !== null && _b !== void 0 ? _b : 0; };
26025
- var getgid = function () { var _a, _b; return (_b = (_a = process_1.default.getgid) === null || _a === void 0 ? void 0 : _a.call(process_1.default)) !== null && _b !== void 0 ? _b : 0; };
26026
- exports.SEP = '/';
26027
- /**
26028
- * Node in a file system (like i-node, v-node).
26029
- */
26030
- var Node = /** @class */ (function (_super) {
26031
- __extends(Node, _super);
26032
- function Node(ino, perm) {
26033
- if (perm === void 0) { perm = 438; }
26034
- var _this = _super.call(this) || this;
26035
- // User ID and group ID.
26036
- _this.uid = getuid();
26037
- _this.gid = getgid();
26038
- _this.atime = new Date();
26039
- _this.mtime = new Date();
26040
- _this.ctime = new Date();
26041
- _this.perm = 438; // Permissions `chmod`, `fchmod`
26042
- _this.mode = S_IFREG; // S_IFDIR, S_IFREG, etc.. (file by default?)
26043
- // Number of hard links pointing at this Node.
26044
- _this.nlink = 1;
26045
- _this.perm = perm;
26046
- _this.mode |= perm;
26047
- _this.ino = ino;
26048
- return _this;
26049
- }
26050
- Node.prototype.getString = function (encoding) {
26051
- if (encoding === void 0) { encoding = 'utf8'; }
26052
- return this.getBuffer().toString(encoding);
26053
- };
26054
- Node.prototype.setString = function (str) {
26055
- // this.setBuffer(bufferFrom(str, 'utf8'));
26056
- this.buf = (0, buffer_1.bufferFrom)(str, 'utf8');
26057
- this.touch();
26058
- };
26059
- Node.prototype.getBuffer = function () {
26060
- if (!this.buf)
26061
- this.setBuffer((0, buffer_1.bufferAllocUnsafe)(0));
26062
- return (0, buffer_1.bufferFrom)(this.buf); // Return a copy.
26063
- };
26064
- Node.prototype.setBuffer = function (buf) {
26065
- this.buf = (0, buffer_1.bufferFrom)(buf); // Creates a copy of data.
26066
- this.touch();
26067
- };
26068
- Node.prototype.getSize = function () {
26069
- return this.buf ? this.buf.length : 0;
26070
- };
26071
- Node.prototype.setModeProperty = function (property) {
26072
- this.mode = (this.mode & ~S_IFMT) | property;
26073
- };
26074
- Node.prototype.setIsFile = function () {
26075
- this.setModeProperty(S_IFREG);
26076
- };
26077
- Node.prototype.setIsDirectory = function () {
26078
- this.setModeProperty(S_IFDIR);
26079
- };
26080
- Node.prototype.setIsSymlink = function () {
26081
- this.setModeProperty(S_IFLNK);
26082
- };
26083
- Node.prototype.isFile = function () {
26084
- return (this.mode & S_IFMT) === S_IFREG;
26085
- };
26086
- Node.prototype.isDirectory = function () {
26087
- return (this.mode & S_IFMT) === S_IFDIR;
26088
- };
26089
- Node.prototype.isSymlink = function () {
26090
- // return !!this.symlink;
26091
- return (this.mode & S_IFMT) === S_IFLNK;
26092
- };
26093
- Node.prototype.makeSymlink = function (steps) {
26094
- this.symlink = steps;
26095
- this.setIsSymlink();
26096
- };
26097
- Node.prototype.write = function (buf, off, len, pos) {
26098
- if (off === void 0) { off = 0; }
26099
- if (len === void 0) { len = buf.length; }
26100
- if (pos === void 0) { pos = 0; }
26101
- if (!this.buf)
26102
- this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
26103
- if (pos + len > this.buf.length) {
26104
- var newBuf = (0, buffer_1.bufferAllocUnsafe)(pos + len);
26105
- this.buf.copy(newBuf, 0, 0, this.buf.length);
26106
- this.buf = newBuf;
26107
- }
26108
- buf.copy(this.buf, pos, off, off + len);
26109
- this.touch();
26110
- return len;
26111
- };
26112
- // Returns the number of bytes read.
26113
- Node.prototype.read = function (buf, off, len, pos) {
26114
- if (off === void 0) { off = 0; }
26115
- if (len === void 0) { len = buf.byteLength; }
26116
- if (pos === void 0) { pos = 0; }
26117
- if (!this.buf)
26118
- this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
26119
- var actualLen = len;
26120
- if (actualLen > buf.byteLength) {
26121
- actualLen = buf.byteLength;
26122
- }
26123
- if (actualLen + pos > this.buf.length) {
26124
- actualLen = this.buf.length - pos;
26125
- }
26126
- this.buf.copy(buf, off, pos, pos + actualLen);
26127
- return actualLen;
26128
- };
26129
- Node.prototype.truncate = function (len) {
26130
- if (len === void 0) { len = 0; }
26131
- if (!len)
26132
- this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
26133
- else {
26134
- if (!this.buf)
26135
- this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
26136
- if (len <= this.buf.length) {
26137
- this.buf = this.buf.slice(0, len);
26138
- }
26139
- else {
26140
- var buf = (0, buffer_1.bufferAllocUnsafe)(0);
26141
- this.buf.copy(buf);
26142
- buf.fill(0, len);
26143
- }
26144
- }
26145
- this.touch();
26146
- };
26147
- Node.prototype.chmod = function (perm) {
26148
- this.perm = perm;
26149
- this.mode = (this.mode & ~511) | perm;
26150
- this.touch();
26151
- };
26152
- Node.prototype.chown = function (uid, gid) {
26153
- this.uid = uid;
26154
- this.gid = gid;
26155
- this.touch();
26156
- };
26157
- Node.prototype.touch = function () {
26158
- this.mtime = new Date();
26159
- this.emit('change', this);
26160
- };
26161
- Node.prototype.canRead = function (uid, gid) {
26162
- if (uid === void 0) { uid = getuid(); }
26163
- if (gid === void 0) { gid = getgid(); }
26164
- if (this.perm & 4 /* S.IROTH */) {
26165
- return true;
26166
- }
26167
- if (gid === this.gid) {
26168
- if (this.perm & 32 /* S.IRGRP */) {
26169
- return true;
26170
- }
26171
- }
26172
- if (uid === this.uid) {
26173
- if (this.perm & 256 /* S.IRUSR */) {
26174
- return true;
26175
- }
26176
- }
26177
- return false;
26178
- };
26179
- Node.prototype.canWrite = function (uid, gid) {
26180
- if (uid === void 0) { uid = getuid(); }
26181
- if (gid === void 0) { gid = getgid(); }
26182
- if (this.perm & 2 /* S.IWOTH */) {
26183
- return true;
26184
- }
26185
- if (gid === this.gid) {
26186
- if (this.perm & 16 /* S.IWGRP */) {
26187
- return true;
26188
- }
26189
- }
26190
- if (uid === this.uid) {
26191
- if (this.perm & 128 /* S.IWUSR */) {
26192
- return true;
26193
- }
26194
- }
26195
- return false;
26196
- };
26197
- Node.prototype.del = function () {
26198
- this.emit('delete', this);
26199
- };
26200
- Node.prototype.toJSON = function () {
26201
- return {
26202
- ino: this.ino,
26203
- uid: this.uid,
26204
- gid: this.gid,
26205
- atime: this.atime.getTime(),
26206
- mtime: this.mtime.getTime(),
26207
- ctime: this.ctime.getTime(),
26208
- perm: this.perm,
26209
- mode: this.mode,
26210
- nlink: this.nlink,
26211
- symlink: this.symlink,
26212
- data: this.getString(),
26213
- };
26214
- };
26215
- return Node;
26216
- }(events_1.EventEmitter));
26217
- exports.Node = Node;
26218
- /**
26219
- * Represents a hard link that points to an i-node `node`.
26220
- */
26221
- var Link = /** @class */ (function (_super) {
26222
- __extends(Link, _super);
26223
- function Link(vol, parent, name) {
26224
- var _this = _super.call(this) || this;
26225
- _this.children = {};
26226
- // Path to this node as Array: ['usr', 'bin', 'node'].
26227
- _this._steps = [];
26228
- // "i-node" number of the node.
26229
- _this.ino = 0;
26230
- // Number of children.
26231
- _this.length = 0;
26232
- _this.vol = vol;
26233
- _this.parent = parent;
26234
- _this.name = name;
26235
- _this.syncSteps();
26236
- return _this;
26237
- }
26238
- Object.defineProperty(Link.prototype, "steps", {
26239
- get: function () {
26240
- return this._steps;
26241
- },
26242
- // Recursively sync children steps, e.g. in case of dir rename
26243
- set: function (val) {
26244
- this._steps = val;
26245
- for (var _i = 0, _a = Object.values(this.children); _i < _a.length; _i++) {
26246
- var child = _a[_i];
26247
- child === null || child === void 0 ? void 0 : child.syncSteps();
26248
- }
26249
- },
26250
- enumerable: false,
26251
- configurable: true
26252
- });
26253
- Link.prototype.setNode = function (node) {
26254
- this.node = node;
26255
- this.ino = node.ino;
26256
- };
26257
- Link.prototype.getNode = function () {
26258
- return this.node;
26259
- };
26260
- Link.prototype.createChild = function (name, node) {
26261
- if (node === void 0) { node = this.vol.createNode(); }
26262
- var link = new Link(this.vol, this, name);
26263
- link.setNode(node);
26264
- if (node.isDirectory()) {
26265
- // link.setChild('.', link);
26266
- // link.getNode().nlink++;
26267
- // link.setChild('..', this);
26268
- // this.getNode().nlink++;
26269
- }
26270
- this.setChild(name, link);
26271
- return link;
26272
- };
26273
- Link.prototype.setChild = function (name, link) {
26274
- if (link === void 0) { link = new Link(this.vol, this, name); }
26275
- this.children[name] = link;
26276
- link.parent = this;
26277
- this.length++;
26278
- this.emit('child:add', link, this);
26279
- return link;
26280
- };
26281
- Link.prototype.deleteChild = function (link) {
26282
- delete this.children[link.getName()];
26283
- this.length--;
26284
- this.emit('child:delete', link, this);
26285
- };
26286
- Link.prototype.getChild = function (name) {
26287
- if (Object.hasOwnProperty.call(this.children, name)) {
26288
- return this.children[name];
26289
- }
26290
- };
26291
- Link.prototype.getPath = function () {
26292
- return this.steps.join(exports.SEP);
26293
- };
26294
- Link.prototype.getName = function () {
26295
- return this.steps[this.steps.length - 1];
26296
- };
26297
- // del() {
26298
- // const parent = this.parent;
26299
- // if(parent) {
26300
- // parent.deleteChild(link);
26301
- // }
26302
- // this.parent = null;
26303
- // this.vol = null;
26304
- // }
26305
- /**
26306
- * Walk the tree path and return the `Link` at that location, if any.
26307
- * @param steps {string[]} Desired location.
26308
- * @param stop {number} Max steps to go into.
26309
- * @param i {number} Current step in the `steps` array.
26310
- *
26311
- * @return {Link|null}
26312
- */
26313
- Link.prototype.walk = function (steps, stop, i) {
26314
- if (stop === void 0) { stop = steps.length; }
26315
- if (i === void 0) { i = 0; }
26316
- if (i >= steps.length)
26317
- return this;
26318
- if (i >= stop)
26319
- return this;
26320
- var step = steps[i];
26321
- var link = this.getChild(step);
26322
- if (!link)
26323
- return null;
26324
- return link.walk(steps, stop, i + 1);
26325
- };
26326
- Link.prototype.toJSON = function () {
26327
- return {
26328
- steps: this.steps,
26329
- ino: this.ino,
26330
- children: Object.keys(this.children),
26331
- };
26332
- };
26333
- Link.prototype.syncSteps = function () {
26334
- this.steps = this.parent ? this.parent.steps.concat([this.name]) : [this.name];
26335
- };
26336
- return Link;
26337
- }(events_1.EventEmitter));
26338
- exports.Link = Link;
26339
- /**
26340
- * Represents an open file (file descriptor) that points to a `Link` (Hard-link) and a `Node`.
26341
- */
26342
- var File = /** @class */ (function () {
26343
- /**
26344
- * Open a Link-Node pair. `node` is provided separately as that might be a different node
26345
- * rather the one `link` points to, because it might be a symlink.
26346
- * @param link
26347
- * @param node
26348
- * @param flags
26349
- * @param fd
26350
- */
26351
- function File(link, node, flags, fd) {
26352
- /**
26353
- * A cursor/offset position in a file, where data will be written on write.
26354
- * User can "seek" this position.
26355
- */
26356
- this.position = 0;
26357
- this.link = link;
26358
- this.node = node;
26359
- this.flags = flags;
26360
- this.fd = fd;
26361
- }
26362
- File.prototype.getString = function (encoding) {
26363
- if (encoding === void 0) { encoding = 'utf8'; }
26364
- return this.node.getString();
26365
- };
26366
- File.prototype.setString = function (str) {
26367
- this.node.setString(str);
26368
- };
26369
- File.prototype.getBuffer = function () {
26370
- return this.node.getBuffer();
26371
- };
26372
- File.prototype.setBuffer = function (buf) {
26373
- this.node.setBuffer(buf);
26374
- };
26375
- File.prototype.getSize = function () {
26376
- return this.node.getSize();
26377
- };
26378
- File.prototype.truncate = function (len) {
26379
- this.node.truncate(len);
26380
- };
26381
- File.prototype.seekTo = function (position) {
26382
- this.position = position;
26383
- };
26384
- File.prototype.stats = function () {
26385
- return Stats_1.default.build(this.node);
26386
- };
26387
- File.prototype.write = function (buf, offset, length, position) {
26388
- if (offset === void 0) { offset = 0; }
26389
- if (length === void 0) { length = buf.length; }
26390
- if (typeof position !== 'number')
26391
- position = this.position;
26392
- if (this.flags & O_APPEND)
26393
- position = this.getSize();
26394
- var bytes = this.node.write(buf, offset, length, position);
26395
- this.position = position + bytes;
26396
- return bytes;
26397
- };
26398
- File.prototype.read = function (buf, offset, length, position) {
26399
- if (offset === void 0) { offset = 0; }
26400
- if (length === void 0) { length = buf.byteLength; }
26401
- if (typeof position !== 'number')
26402
- position = this.position;
26403
- var bytes = this.node.read(buf, offset, length, position);
26404
- this.position = position + bytes;
26405
- return bytes;
26406
- };
26407
- File.prototype.chmod = function (perm) {
26408
- this.node.chmod(perm);
26409
- };
26410
- File.prototype.chown = function (uid, gid) {
26411
- this.node.chown(uid, gid);
26412
- };
26413
- return File;
26414
- }());
26415
- exports.File = File;
26416
-
26417
-
26418
- /***/ }),
26419
-
26420
- /***/ 31597:
26421
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
26422
-
26423
- "use strict";
26424
-
26425
- // Here we mock the global `process` variable in case we are not in Node's environment.
26426
- Object.defineProperty(exports, "__esModule", ({ value: true }));
26427
- exports.createProcess = void 0;
26428
- /**
26429
- * Looks to return a `process` object, if one is available.
26430
- *
26431
- * The global `process` is returned if defined;
26432
- * otherwise `require('process')` is attempted.
26433
- *
26434
- * If that fails, `undefined` is returned.
26435
- *
26436
- * @return {IProcess | undefined}
26437
- */
26438
- var maybeReturnProcess = function () {
26439
- if (typeof process !== 'undefined') {
26440
- return process;
26441
- }
26442
- try {
26443
- return __webpack_require__(77282);
26444
- }
26445
- catch (_a) {
26446
- return undefined;
26447
- }
26448
- };
26449
- function createProcess() {
26450
- var p = maybeReturnProcess() || {};
26451
- if (!p.cwd)
26452
- p.cwd = function () { return '/'; };
26453
- if (!p.nextTick)
26454
- p.nextTick = (__webpack_require__(58056)["default"]);
26455
- if (!p.emitWarning)
26456
- p.emitWarning = function (message, type) {
26457
- // tslint:disable-next-line:no-console
26458
- console.warn("".concat(type).concat(type ? ': ' : '').concat(message));
26459
- };
26460
- if (!p.env)
26461
- p.env = {};
26462
- return p;
26463
- }
26464
- exports.createProcess = createProcess;
26465
- exports["default"] = createProcess();
26466
-
26467
-
26468
- /***/ }),
26469
-
26470
- /***/ 17015:
26471
- /***/ (function(__unused_webpack_module, exports) {
26472
-
26473
- "use strict";
26474
-
26475
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
26476
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
26477
- if (ar || !(i in from)) {
26478
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
26479
- ar[i] = from[i];
26480
- }
26481
- }
26482
- return to.concat(ar || Array.prototype.slice.call(from));
26483
- };
26484
- Object.defineProperty(exports, "__esModule", ({ value: true }));
26485
- exports.FileHandle = void 0;
26486
- function promisify(vol, fn, getResult) {
26487
- if (getResult === void 0) { getResult = function (input) { return input; }; }
26488
- return function () {
26489
- var args = [];
26490
- for (var _i = 0; _i < arguments.length; _i++) {
26491
- args[_i] = arguments[_i];
26492
- }
26493
- return new Promise(function (resolve, reject) {
26494
- vol[fn].bind(vol).apply(void 0, __spreadArray(__spreadArray([], args, false), [function (error, result) {
26495
- if (error)
26496
- return reject(error);
26497
- return resolve(getResult(result));
26498
- }], false));
26499
- });
26500
- };
26501
- }
26502
- var FileHandle = /** @class */ (function () {
26503
- function FileHandle(vol, fd) {
26504
- this.vol = vol;
26505
- this.fd = fd;
26506
- }
26507
- FileHandle.prototype.appendFile = function (data, options) {
26508
- return promisify(this.vol, 'appendFile')(this.fd, data, options);
26509
- };
26510
- FileHandle.prototype.chmod = function (mode) {
26511
- return promisify(this.vol, 'fchmod')(this.fd, mode);
26512
- };
26513
- FileHandle.prototype.chown = function (uid, gid) {
26514
- return promisify(this.vol, 'fchown')(this.fd, uid, gid);
26515
- };
26516
- FileHandle.prototype.close = function () {
26517
- return promisify(this.vol, 'close')(this.fd);
26518
- };
26519
- FileHandle.prototype.datasync = function () {
26520
- return promisify(this.vol, 'fdatasync')(this.fd);
26521
- };
26522
- FileHandle.prototype.read = function (buffer, offset, length, position) {
26523
- return promisify(this.vol, 'read', function (bytesRead) { return ({ bytesRead: bytesRead, buffer: buffer }); })(this.fd, buffer, offset, length, position);
26524
- };
26525
- FileHandle.prototype.readFile = function (options) {
26526
- return promisify(this.vol, 'readFile')(this.fd, options);
26527
- };
26528
- FileHandle.prototype.stat = function (options) {
26529
- return promisify(this.vol, 'fstat')(this.fd, options);
26530
- };
26531
- FileHandle.prototype.sync = function () {
26532
- return promisify(this.vol, 'fsync')(this.fd);
26533
- };
26534
- FileHandle.prototype.truncate = function (len) {
26535
- return promisify(this.vol, 'ftruncate')(this.fd, len);
26536
- };
26537
- FileHandle.prototype.utimes = function (atime, mtime) {
26538
- return promisify(this.vol, 'futimes')(this.fd, atime, mtime);
26539
- };
26540
- FileHandle.prototype.write = function (buffer, offset, length, position) {
26541
- return promisify(this.vol, 'write', function (bytesWritten) { return ({ bytesWritten: bytesWritten, buffer: buffer }); })(this.fd, buffer, offset, length, position);
26542
- };
26543
- FileHandle.prototype.writeFile = function (data, options) {
26544
- return promisify(this.vol, 'writeFile')(this.fd, data, options);
26545
- };
26546
- return FileHandle;
26547
- }());
26548
- exports.FileHandle = FileHandle;
26549
- function createPromisesApi(vol) {
26550
- if (typeof Promise === 'undefined')
26551
- return null;
26552
- return {
26553
- FileHandle: FileHandle,
26554
- access: function (path, mode) {
26555
- return promisify(vol, 'access')(path, mode);
26556
- },
26557
- appendFile: function (path, data, options) {
26558
- return promisify(vol, 'appendFile')(path instanceof FileHandle ? path.fd : path, data, options);
26559
- },
26560
- chmod: function (path, mode) {
26561
- return promisify(vol, 'chmod')(path, mode);
26562
- },
26563
- chown: function (path, uid, gid) {
26564
- return promisify(vol, 'chown')(path, uid, gid);
26565
- },
26566
- copyFile: function (src, dest, flags) {
26567
- return promisify(vol, 'copyFile')(src, dest, flags);
26568
- },
26569
- lchmod: function (path, mode) {
26570
- return promisify(vol, 'lchmod')(path, mode);
26571
- },
26572
- lchown: function (path, uid, gid) {
26573
- return promisify(vol, 'lchown')(path, uid, gid);
26574
- },
26575
- link: function (existingPath, newPath) {
26576
- return promisify(vol, 'link')(existingPath, newPath);
26577
- },
26578
- lstat: function (path, options) {
26579
- return promisify(vol, 'lstat')(path, options);
26580
- },
26581
- mkdir: function (path, options) {
26582
- return promisify(vol, 'mkdir')(path, options);
26583
- },
26584
- mkdtemp: function (prefix, options) {
26585
- return promisify(vol, 'mkdtemp')(prefix, options);
26586
- },
26587
- open: function (path, flags, mode) {
26588
- return promisify(vol, 'open', function (fd) { return new FileHandle(vol, fd); })(path, flags, mode);
26589
- },
26590
- readdir: function (path, options) {
26591
- return promisify(vol, 'readdir')(path, options);
26592
- },
26593
- readFile: function (id, options) {
26594
- return promisify(vol, 'readFile')(id instanceof FileHandle ? id.fd : id, options);
26595
- },
26596
- readlink: function (path, options) {
26597
- return promisify(vol, 'readlink')(path, options);
26598
- },
26599
- realpath: function (path, options) {
26600
- return promisify(vol, 'realpath')(path, options);
26601
- },
26602
- rename: function (oldPath, newPath) {
26603
- return promisify(vol, 'rename')(oldPath, newPath);
26604
- },
26605
- rmdir: function (path) {
26606
- return promisify(vol, 'rmdir')(path);
26607
- },
26608
- rm: function (path, options) {
26609
- return promisify(vol, 'rm')(path, options);
26610
- },
26611
- stat: function (path, options) {
26612
- return promisify(vol, 'stat')(path, options);
26613
- },
26614
- symlink: function (target, path, type) {
26615
- return promisify(vol, 'symlink')(target, path, type);
26616
- },
26617
- truncate: function (path, len) {
26618
- return promisify(vol, 'truncate')(path, len);
26619
- },
26620
- unlink: function (path) {
26621
- return promisify(vol, 'unlink')(path);
26622
- },
26623
- utimes: function (path, atime, mtime) {
26624
- return promisify(vol, 'utimes')(path, atime, mtime);
26625
- },
26626
- writeFile: function (id, data, options) {
26627
- return promisify(vol, 'writeFile')(id instanceof FileHandle ? id.fd : id, data, options);
26628
- },
26629
- };
26630
- }
26631
- exports["default"] = createPromisesApi;
26632
-
26633
-
26634
- /***/ }),
26635
-
26636
- /***/ 58056:
26637
- /***/ ((__unused_webpack_module, exports) => {
26638
-
26639
- "use strict";
26640
-
26641
- Object.defineProperty(exports, "__esModule", ({ value: true }));
26642
- var _setImmediate;
26643
- if (typeof setImmediate === 'function')
26644
- _setImmediate = setImmediate.bind(typeof globalThis !== 'undefined' ? globalThis : global);
26645
- else
26646
- _setImmediate = setTimeout.bind(typeof globalThis !== 'undefined' ? globalThis : global);
26647
- exports["default"] = _setImmediate;
26648
-
26649
-
26650
- /***/ }),
26651
-
26652
- /***/ 66819:
26653
- /***/ ((__unused_webpack_module, exports) => {
26654
-
26655
- "use strict";
26656
-
26657
- Object.defineProperty(exports, "__esModule", ({ value: true }));
26658
- /**
26659
- * `setTimeoutUnref` is just like `setTimeout`,
26660
- * only in Node's environment it will "unref" its macro task.
26661
- */
26662
- function setTimeoutUnref(callback, time, args) {
26663
- var ref = setTimeout.apply(typeof globalThis !== 'undefined' ? globalThis : global, arguments);
26664
- if (ref && typeof ref === 'object' && typeof ref.unref === 'function')
26665
- ref.unref();
26666
- return ref;
26667
- }
26668
- exports["default"] = setTimeoutUnref;
26669
-
26670
-
26671
- /***/ }),
26672
-
26673
- /***/ 22682:
26674
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
26675
-
26676
- "use strict";
26677
-
26678
- var __extends = (this && this.__extends) || (function () {
26679
- var extendStatics = function (d, b) {
26680
- extendStatics = Object.setPrototypeOf ||
26681
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
26682
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
26683
- return extendStatics(d, b);
26684
- };
26685
- return function (d, b) {
26686
- if (typeof b !== "function" && b !== null)
26687
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
26688
- extendStatics(d, b);
26689
- function __() { this.constructor = d; }
26690
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
26691
- };
26692
- })();
26693
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
26694
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
26695
- if (ar || !(i in from)) {
26696
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
26697
- ar[i] = from[i];
26698
- }
26699
- }
26700
- return to.concat(ar || Array.prototype.slice.call(from));
26701
- };
26702
- Object.defineProperty(exports, "__esModule", ({ value: true }));
26703
- exports.FSWatcher = exports.StatWatcher = exports.Volume = exports.toUnixTimestamp = exports.bufferToEncoding = exports.dataToBuffer = exports.dataToStr = exports.pathToSteps = exports.filenameToSteps = exports.pathToFilename = exports.flagsToNumber = exports.FLAGS = void 0;
26704
- var pathModule = __webpack_require__(71017);
26705
- var node_1 = __webpack_require__(81115);
26706
- var Stats_1 = __webpack_require__(21860);
26707
- var Dirent_1 = __webpack_require__(90079);
26708
- var buffer_1 = __webpack_require__(52975);
26709
- var setImmediate_1 = __webpack_require__(58056);
26710
- var process_1 = __webpack_require__(31597);
26711
- var setTimeoutUnref_1 = __webpack_require__(66819);
26712
- var stream_1 = __webpack_require__(12781);
26713
- var constants_1 = __webpack_require__(34413);
26714
- var events_1 = __webpack_require__(82361);
26715
- var encoding_1 = __webpack_require__(68385);
26716
- var errors = __webpack_require__(11904);
26717
- var util = __webpack_require__(73837);
26718
- var promises_1 = __webpack_require__(17015);
26719
- var resolveCrossPlatform = pathModule.resolve;
26720
- var O_RDONLY = constants_1.constants.O_RDONLY, O_WRONLY = constants_1.constants.O_WRONLY, O_RDWR = constants_1.constants.O_RDWR, O_CREAT = constants_1.constants.O_CREAT, O_EXCL = constants_1.constants.O_EXCL, O_TRUNC = constants_1.constants.O_TRUNC, O_APPEND = constants_1.constants.O_APPEND, O_SYNC = constants_1.constants.O_SYNC, O_DIRECTORY = constants_1.constants.O_DIRECTORY, F_OK = constants_1.constants.F_OK, COPYFILE_EXCL = constants_1.constants.COPYFILE_EXCL, COPYFILE_FICLONE_FORCE = constants_1.constants.COPYFILE_FICLONE_FORCE;
26721
- var _a = pathModule.posix ? pathModule.posix : pathModule, sep = _a.sep, relative = _a.relative, join = _a.join, dirname = _a.dirname;
26722
- var isWin = process_1.default.platform === 'win32';
26723
- var kMinPoolSpace = 128;
26724
- // const kMaxLength = require('buffer').kMaxLength;
26725
- // ---------------------------------------- Error messages
26726
- // TODO: Use `internal/errors.js` in the future.
26727
- var ERRSTR = {
26728
- PATH_STR: 'path must be a string or Buffer',
26729
- // FD: 'file descriptor must be a unsigned 32-bit integer',
26730
- FD: 'fd must be a file descriptor',
26731
- MODE_INT: 'mode must be an int',
26732
- CB: 'callback must be a function',
26733
- UID: 'uid must be an unsigned int',
26734
- GID: 'gid must be an unsigned int',
26735
- LEN: 'len must be an integer',
26736
- ATIME: 'atime must be an integer',
26737
- MTIME: 'mtime must be an integer',
26738
- PREFIX: 'filename prefix is required',
26739
- BUFFER: 'buffer must be an instance of Buffer or StaticBuffer',
26740
- OFFSET: 'offset must be an integer',
26741
- LENGTH: 'length must be an integer',
26742
- POSITION: 'position must be an integer',
26743
- };
26744
- var ERRSTR_OPTS = function (tipeof) { return "Expected options to be either an object or a string, but got ".concat(tipeof, " instead"); };
26745
- // const ERRSTR_FLAG = flag => `Unknown file open flag: ${flag}`;
26746
- var ENOENT = 'ENOENT';
26747
- var EBADF = 'EBADF';
26748
- var EINVAL = 'EINVAL';
26749
- var EPERM = 'EPERM';
26750
- var EPROTO = 'EPROTO';
26751
- var EEXIST = 'EEXIST';
26752
- var ENOTDIR = 'ENOTDIR';
26753
- var EMFILE = 'EMFILE';
26754
- var EACCES = 'EACCES';
26755
- var EISDIR = 'EISDIR';
26756
- var ENOTEMPTY = 'ENOTEMPTY';
26757
- var ENOSYS = 'ENOSYS';
26758
- var ERR_FS_EISDIR = 'ERR_FS_EISDIR';
26759
- function formatError(errorCode, func, path, path2) {
26760
- if (func === void 0) { func = ''; }
26761
- if (path === void 0) { path = ''; }
26762
- if (path2 === void 0) { path2 = ''; }
26763
- var pathFormatted = '';
26764
- if (path)
26765
- pathFormatted = " '".concat(path, "'");
26766
- if (path2)
26767
- pathFormatted += " -> '".concat(path2, "'");
26768
- switch (errorCode) {
26769
- case ENOENT:
26770
- return "ENOENT: no such file or directory, ".concat(func).concat(pathFormatted);
26771
- case EBADF:
26772
- return "EBADF: bad file descriptor, ".concat(func).concat(pathFormatted);
26773
- case EINVAL:
26774
- return "EINVAL: invalid argument, ".concat(func).concat(pathFormatted);
26775
- case EPERM:
26776
- return "EPERM: operation not permitted, ".concat(func).concat(pathFormatted);
26777
- case EPROTO:
26778
- return "EPROTO: protocol error, ".concat(func).concat(pathFormatted);
26779
- case EEXIST:
26780
- return "EEXIST: file already exists, ".concat(func).concat(pathFormatted);
26781
- case ENOTDIR:
26782
- return "ENOTDIR: not a directory, ".concat(func).concat(pathFormatted);
26783
- case EISDIR:
26784
- return "EISDIR: illegal operation on a directory, ".concat(func).concat(pathFormatted);
26785
- case EACCES:
26786
- return "EACCES: permission denied, ".concat(func).concat(pathFormatted);
26787
- case ENOTEMPTY:
26788
- return "ENOTEMPTY: directory not empty, ".concat(func).concat(pathFormatted);
26789
- case EMFILE:
26790
- return "EMFILE: too many open files, ".concat(func).concat(pathFormatted);
26791
- case ENOSYS:
26792
- return "ENOSYS: function not implemented, ".concat(func).concat(pathFormatted);
26793
- case ERR_FS_EISDIR:
26794
- return "[ERR_FS_EISDIR]: Path is a directory: ".concat(func, " returned EISDIR (is a directory) ").concat(path);
26795
- default:
26796
- return "".concat(errorCode, ": error occurred, ").concat(func).concat(pathFormatted);
26797
- }
26798
- }
26799
- function createError(errorCode, func, path, path2, Constructor) {
26800
- if (func === void 0) { func = ''; }
26801
- if (path === void 0) { path = ''; }
26802
- if (path2 === void 0) { path2 = ''; }
26803
- if (Constructor === void 0) { Constructor = Error; }
26804
- var error = new Constructor(formatError(errorCode, func, path, path2));
26805
- error.code = errorCode;
26806
- return error;
26807
- }
26808
- // ---------------------------------------- Flags
26809
- // List of file `flags` as defined by Node.
26810
- var FLAGS;
26811
- (function (FLAGS) {
26812
- // Open file for reading. An exception occurs if the file does not exist.
26813
- FLAGS[FLAGS["r"] = O_RDONLY] = "r";
26814
- // Open file for reading and writing. An exception occurs if the file does not exist.
26815
- FLAGS[FLAGS["r+"] = O_RDWR] = "r+";
26816
- // Open file for reading in synchronous mode. Instructs the operating system to bypass the local file system cache.
26817
- FLAGS[FLAGS["rs"] = O_RDONLY | O_SYNC] = "rs";
26818
- FLAGS[FLAGS["sr"] = FLAGS.rs] = "sr";
26819
- // Open file for reading and writing, telling the OS to open it synchronously. See notes for 'rs' about using this with caution.
26820
- FLAGS[FLAGS["rs+"] = O_RDWR | O_SYNC] = "rs+";
26821
- FLAGS[FLAGS["sr+"] = FLAGS['rs+']] = "sr+";
26822
- // Open file for writing. The file is created (if it does not exist) or truncated (if it exists).
26823
- FLAGS[FLAGS["w"] = O_WRONLY | O_CREAT | O_TRUNC] = "w";
26824
- // Like 'w' but fails if path exists.
26825
- FLAGS[FLAGS["wx"] = O_WRONLY | O_CREAT | O_TRUNC | O_EXCL] = "wx";
26826
- FLAGS[FLAGS["xw"] = FLAGS.wx] = "xw";
26827
- // Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).
26828
- FLAGS[FLAGS["w+"] = O_RDWR | O_CREAT | O_TRUNC] = "w+";
26829
- // Like 'w+' but fails if path exists.
26830
- FLAGS[FLAGS["wx+"] = O_RDWR | O_CREAT | O_TRUNC | O_EXCL] = "wx+";
26831
- FLAGS[FLAGS["xw+"] = FLAGS['wx+']] = "xw+";
26832
- // Open file for appending. The file is created if it does not exist.
26833
- FLAGS[FLAGS["a"] = O_WRONLY | O_APPEND | O_CREAT] = "a";
26834
- // Like 'a' but fails if path exists.
26835
- FLAGS[FLAGS["ax"] = O_WRONLY | O_APPEND | O_CREAT | O_EXCL] = "ax";
26836
- FLAGS[FLAGS["xa"] = FLAGS.ax] = "xa";
26837
- // Open file for reading and appending. The file is created if it does not exist.
26838
- FLAGS[FLAGS["a+"] = O_RDWR | O_APPEND | O_CREAT] = "a+";
26839
- // Like 'a+' but fails if path exists.
26840
- FLAGS[FLAGS["ax+"] = O_RDWR | O_APPEND | O_CREAT | O_EXCL] = "ax+";
26841
- FLAGS[FLAGS["xa+"] = FLAGS['ax+']] = "xa+";
26842
- })(FLAGS = exports.FLAGS || (exports.FLAGS = {}));
26843
- function flagsToNumber(flags) {
26844
- if (typeof flags === 'number')
26845
- return flags;
26846
- if (typeof flags === 'string') {
26847
- var flagsNum = FLAGS[flags];
26848
- if (typeof flagsNum !== 'undefined')
26849
- return flagsNum;
26850
- }
26851
- // throw new TypeError(formatError(ERRSTR_FLAG(flags)));
26852
- throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'flags', flags);
26853
- }
26854
- exports.flagsToNumber = flagsToNumber;
26855
- // ---------------------------------------- Options
26856
- function getOptions(defaults, options) {
26857
- var opts;
26858
- if (!options)
26859
- return defaults;
26860
- else {
26861
- var tipeof = typeof options;
26862
- switch (tipeof) {
26863
- case 'string':
26864
- opts = Object.assign({}, defaults, { encoding: options });
26865
- break;
26866
- case 'object':
26867
- opts = Object.assign({}, defaults, options);
26868
- break;
26869
- default:
26870
- throw TypeError(ERRSTR_OPTS(tipeof));
26871
- }
26872
- }
26873
- if (opts.encoding !== 'buffer')
26874
- (0, encoding_1.assertEncoding)(opts.encoding);
26875
- return opts;
26876
- }
26877
- function optsGenerator(defaults) {
26878
- return function (options) { return getOptions(defaults, options); };
26879
- }
26880
- function validateCallback(callback) {
26881
- if (typeof callback !== 'function')
26882
- throw TypeError(ERRSTR.CB);
26883
- return callback;
26884
- }
26885
- function optsAndCbGenerator(getOpts) {
26886
- return function (options, callback) {
26887
- return typeof options === 'function' ? [getOpts(), options] : [getOpts(options), validateCallback(callback)];
26888
- };
26889
- }
26890
- var optsDefaults = {
26891
- encoding: 'utf8',
26892
- };
26893
- var getDefaultOpts = optsGenerator(optsDefaults);
26894
- var getDefaultOptsAndCb = optsAndCbGenerator(getDefaultOpts);
26895
- var readFileOptsDefaults = {
26896
- flag: 'r',
26897
- };
26898
- var getReadFileOptions = optsGenerator(readFileOptsDefaults);
26899
- var writeFileDefaults = {
26900
- encoding: 'utf8',
26901
- mode: 438 /* MODE.DEFAULT */,
26902
- flag: FLAGS[FLAGS.w],
26903
- };
26904
- var getWriteFileOptions = optsGenerator(writeFileDefaults);
26905
- var appendFileDefaults = {
26906
- encoding: 'utf8',
26907
- mode: 438 /* MODE.DEFAULT */,
26908
- flag: FLAGS[FLAGS.a],
26909
- };
26910
- var getAppendFileOpts = optsGenerator(appendFileDefaults);
26911
- var getAppendFileOptsAndCb = optsAndCbGenerator(getAppendFileOpts);
26912
- var realpathDefaults = optsDefaults;
26913
- var getRealpathOptions = optsGenerator(realpathDefaults);
26914
- var getRealpathOptsAndCb = optsAndCbGenerator(getRealpathOptions);
26915
- var mkdirDefaults = {
26916
- mode: 511 /* MODE.DIR */,
26917
- recursive: false,
26918
- };
26919
- var getMkdirOptions = function (options) {
26920
- if (typeof options === 'number')
26921
- return Object.assign({}, mkdirDefaults, { mode: options });
26922
- return Object.assign({}, mkdirDefaults, options);
26923
- };
26924
- var rmdirDefaults = {
26925
- recursive: false,
26926
- };
26927
- var getRmdirOptions = function (options) {
26928
- return Object.assign({}, rmdirDefaults, options);
26929
- };
26930
- var getRmOpts = optsGenerator(optsDefaults);
26931
- var getRmOptsAndCb = optsAndCbGenerator(getRmOpts);
26932
- var readdirDefaults = {
26933
- encoding: 'utf8',
26934
- withFileTypes: false,
26935
- };
26936
- var getReaddirOptions = optsGenerator(readdirDefaults);
26937
- var getReaddirOptsAndCb = optsAndCbGenerator(getReaddirOptions);
26938
- var statDefaults = {
26939
- bigint: false,
26940
- };
26941
- var getStatOptions = function (options) {
26942
- if (options === void 0) { options = {}; }
26943
- return Object.assign({}, statDefaults, options);
26944
- };
26945
- var getStatOptsAndCb = function (options, callback) {
26946
- return typeof options === 'function' ? [getStatOptions(), options] : [getStatOptions(options), validateCallback(callback)];
26947
- };
26948
- // ---------------------------------------- Utility functions
26949
- function getPathFromURLPosix(url) {
26950
- if (url.hostname !== '') {
26951
- throw new errors.TypeError('ERR_INVALID_FILE_URL_HOST', process_1.default.platform);
26952
- }
26953
- var pathname = url.pathname;
26954
- for (var n = 0; n < pathname.length; n++) {
26955
- if (pathname[n] === '%') {
26956
- var third = pathname.codePointAt(n + 2) | 0x20;
26957
- if (pathname[n + 1] === '2' && third === 102) {
26958
- throw new errors.TypeError('ERR_INVALID_FILE_URL_PATH', 'must not include encoded / characters');
26959
- }
26960
- }
26961
- }
26962
- return decodeURIComponent(pathname);
26963
- }
26964
- function pathToFilename(path) {
26965
- if (typeof path !== 'string' && !buffer_1.Buffer.isBuffer(path)) {
26966
- try {
26967
- if (!(path instanceof (__webpack_require__(57310).URL)))
26968
- throw new TypeError(ERRSTR.PATH_STR);
26969
- }
26970
- catch (err) {
26971
- throw new TypeError(ERRSTR.PATH_STR);
26972
- }
26973
- path = getPathFromURLPosix(path);
26974
- }
26975
- var pathString = String(path);
26976
- nullCheck(pathString);
26977
- // return slash(pathString);
26978
- return pathString;
26979
- }
26980
- exports.pathToFilename = pathToFilename;
26981
- var resolve = function (filename, base) {
26982
- if (base === void 0) { base = process_1.default.cwd(); }
26983
- return resolveCrossPlatform(base, filename);
26984
- };
26985
- if (isWin) {
26986
- var _resolve_1 = resolve;
26987
- var unixify_1 = (__webpack_require__(45867)/* .unixify */ .Z4);
26988
- resolve = function (filename, base) { return unixify_1(_resolve_1(filename, base)); };
26989
- }
26990
- function filenameToSteps(filename, base) {
26991
- var fullPath = resolve(filename, base);
26992
- var fullPathSansSlash = fullPath.substr(1);
26993
- if (!fullPathSansSlash)
26994
- return [];
26995
- return fullPathSansSlash.split(sep);
26996
- }
26997
- exports.filenameToSteps = filenameToSteps;
26998
- function pathToSteps(path) {
26999
- return filenameToSteps(pathToFilename(path));
27000
- }
27001
- exports.pathToSteps = pathToSteps;
27002
- function dataToStr(data, encoding) {
27003
- if (encoding === void 0) { encoding = encoding_1.ENCODING_UTF8; }
27004
- if (buffer_1.Buffer.isBuffer(data))
27005
- return data.toString(encoding);
27006
- else if (data instanceof Uint8Array)
27007
- return (0, buffer_1.bufferFrom)(data).toString(encoding);
27008
- else
27009
- return String(data);
27010
- }
27011
- exports.dataToStr = dataToStr;
27012
- function dataToBuffer(data, encoding) {
27013
- if (encoding === void 0) { encoding = encoding_1.ENCODING_UTF8; }
27014
- if (buffer_1.Buffer.isBuffer(data))
27015
- return data;
27016
- else if (data instanceof Uint8Array)
27017
- return (0, buffer_1.bufferFrom)(data);
27018
- else
27019
- return (0, buffer_1.bufferFrom)(String(data), encoding);
27020
- }
27021
- exports.dataToBuffer = dataToBuffer;
27022
- function bufferToEncoding(buffer, encoding) {
27023
- if (!encoding || encoding === 'buffer')
27024
- return buffer;
27025
- else
27026
- return buffer.toString(encoding);
27027
- }
27028
- exports.bufferToEncoding = bufferToEncoding;
27029
- function nullCheck(path, callback) {
27030
- if (('' + path).indexOf('\u0000') !== -1) {
27031
- var er = new Error('Path must be a string without null bytes');
27032
- er.code = ENOENT;
27033
- if (typeof callback !== 'function')
27034
- throw er;
27035
- process_1.default.nextTick(callback, er);
27036
- return false;
27037
- }
27038
- return true;
27039
- }
27040
- function _modeToNumber(mode, def) {
27041
- if (typeof mode === 'number')
27042
- return mode;
27043
- if (typeof mode === 'string')
27044
- return parseInt(mode, 8);
27045
- if (def)
27046
- return modeToNumber(def);
27047
- return undefined;
27048
- }
27049
- function modeToNumber(mode, def) {
27050
- var result = _modeToNumber(mode, def);
27051
- if (typeof result !== 'number' || isNaN(result))
27052
- throw new TypeError(ERRSTR.MODE_INT);
27053
- return result;
27054
- }
27055
- function isFd(path) {
27056
- return path >>> 0 === path;
27057
- }
27058
- function validateFd(fd) {
27059
- if (!isFd(fd))
27060
- throw TypeError(ERRSTR.FD);
27061
- }
27062
- // converts Date or number to a fractional UNIX timestamp
27063
- function toUnixTimestamp(time) {
27064
- // tslint:disable-next-line triple-equals
27065
- if (typeof time === 'string' && +time == time) {
27066
- return +time;
27067
- }
27068
- if (time instanceof Date) {
27069
- return time.getTime() / 1000;
27070
- }
27071
- if (isFinite(time)) {
27072
- if (time < 0) {
27073
- return Date.now() / 1000;
27074
- }
27075
- return time;
27076
- }
27077
- throw new Error('Cannot parse time: ' + time);
27078
- }
27079
- exports.toUnixTimestamp = toUnixTimestamp;
27080
- function validateUid(uid) {
27081
- if (typeof uid !== 'number')
27082
- throw TypeError(ERRSTR.UID);
27083
- }
27084
- function validateGid(gid) {
27085
- if (typeof gid !== 'number')
27086
- throw TypeError(ERRSTR.GID);
27087
- }
27088
- function flattenJSON(nestedJSON) {
27089
- var flatJSON = {};
27090
- function flatten(pathPrefix, node) {
27091
- for (var path in node) {
27092
- var contentOrNode = node[path];
27093
- var joinedPath = join(pathPrefix, path);
27094
- if (typeof contentOrNode === 'string') {
27095
- flatJSON[joinedPath] = contentOrNode;
27096
- }
27097
- else if (typeof contentOrNode === 'object' && contentOrNode !== null && Object.keys(contentOrNode).length > 0) {
27098
- // empty directories need an explicit entry and therefore get handled in `else`, non-empty ones are implicitly considered
27099
- flatten(joinedPath, contentOrNode);
27100
- }
27101
- else {
27102
- // without this branch null, empty-object or non-object entries would not be handled in the same way
27103
- // by both fromJSON() and fromNestedJSON()
27104
- flatJSON[joinedPath] = null;
27105
- }
27106
- }
27107
- }
27108
- flatten('', nestedJSON);
27109
- return flatJSON;
27110
- }
27111
- /**
27112
- * `Volume` represents a file system.
27113
- */
27114
- var Volume = /** @class */ (function () {
27115
- function Volume(props) {
27116
- if (props === void 0) { props = {}; }
27117
- // I-node number counter.
27118
- this.ino = 0;
27119
- // A mapping for i-node numbers to i-nodes (`Node`);
27120
- this.inodes = {};
27121
- // List of released i-node numbers, for reuse.
27122
- this.releasedInos = [];
27123
- // A mapping for file descriptors to `File`s.
27124
- this.fds = {};
27125
- // A list of reusable (opened and closed) file descriptors, that should be
27126
- // used first before creating a new file descriptor.
27127
- this.releasedFds = [];
27128
- // Max number of open files.
27129
- this.maxFiles = 10000;
27130
- // Current number of open files.
27131
- this.openFiles = 0;
27132
- this.promisesApi = (0, promises_1.default)(this);
27133
- this.statWatchers = {};
27134
- this.props = Object.assign({ Node: node_1.Node, Link: node_1.Link, File: node_1.File }, props);
27135
- var root = this.createLink();
27136
- root.setNode(this.createNode(true));
27137
- var self = this; // tslint:disable-line no-this-assignment
27138
- this.StatWatcher = /** @class */ (function (_super) {
27139
- __extends(StatWatcher, _super);
27140
- function StatWatcher() {
27141
- return _super.call(this, self) || this;
27142
- }
27143
- return StatWatcher;
27144
- }(StatWatcher));
27145
- var _ReadStream = FsReadStream;
27146
- this.ReadStream = /** @class */ (function (_super) {
27147
- __extends(class_1, _super);
27148
- function class_1() {
27149
- var args = [];
27150
- for (var _i = 0; _i < arguments.length; _i++) {
27151
- args[_i] = arguments[_i];
27152
- }
27153
- return _super.apply(this, __spreadArray([self], args, false)) || this;
27154
- }
27155
- return class_1;
27156
- }(_ReadStream));
27157
- var _WriteStream = FsWriteStream;
27158
- this.WriteStream = /** @class */ (function (_super) {
27159
- __extends(class_2, _super);
27160
- function class_2() {
27161
- var args = [];
27162
- for (var _i = 0; _i < arguments.length; _i++) {
27163
- args[_i] = arguments[_i];
27164
- }
27165
- return _super.apply(this, __spreadArray([self], args, false)) || this;
27166
- }
27167
- return class_2;
27168
- }(_WriteStream));
27169
- this.FSWatcher = /** @class */ (function (_super) {
27170
- __extends(FSWatcher, _super);
27171
- function FSWatcher() {
27172
- return _super.call(this, self) || this;
27173
- }
27174
- return FSWatcher;
27175
- }(FSWatcher));
27176
- // root.setChild('.', root);
27177
- // root.getNode().nlink++;
27178
- // root.setChild('..', root);
27179
- // root.getNode().nlink++;
27180
- this.root = root;
27181
- }
27182
- Volume.fromJSON = function (json, cwd) {
27183
- var vol = new Volume();
27184
- vol.fromJSON(json, cwd);
27185
- return vol;
27186
- };
27187
- Volume.fromNestedJSON = function (json, cwd) {
27188
- var vol = new Volume();
27189
- vol.fromNestedJSON(json, cwd);
27190
- return vol;
27191
- };
27192
- Object.defineProperty(Volume.prototype, "promises", {
27193
- get: function () {
27194
- if (this.promisesApi === null)
27195
- throw new Error('Promise is not supported in this environment.');
27196
- return this.promisesApi;
27197
- },
27198
- enumerable: false,
27199
- configurable: true
27200
- });
27201
- Volume.prototype.createLink = function (parent, name, isDirectory, perm) {
27202
- if (isDirectory === void 0) { isDirectory = false; }
27203
- if (!parent) {
27204
- return new this.props.Link(this, null, '');
27205
- }
27206
- if (!name) {
27207
- throw new Error('createLink: name cannot be empty');
27208
- }
27209
- return parent.createChild(name, this.createNode(isDirectory, perm));
27210
- };
27211
- Volume.prototype.deleteLink = function (link) {
27212
- var parent = link.parent;
27213
- if (parent) {
27214
- parent.deleteChild(link);
27215
- return true;
27216
- }
27217
- return false;
27218
- };
27219
- Volume.prototype.newInoNumber = function () {
27220
- var releasedFd = this.releasedInos.pop();
27221
- if (releasedFd)
27222
- return releasedFd;
27223
- else {
27224
- this.ino = (this.ino + 1) % 0xffffffff;
27225
- return this.ino;
27226
- }
27227
- };
27228
- Volume.prototype.newFdNumber = function () {
27229
- var releasedFd = this.releasedFds.pop();
27230
- return typeof releasedFd === 'number' ? releasedFd : Volume.fd--;
27231
- };
27232
- Volume.prototype.createNode = function (isDirectory, perm) {
27233
- if (isDirectory === void 0) { isDirectory = false; }
27234
- var node = new this.props.Node(this.newInoNumber(), perm);
27235
- if (isDirectory)
27236
- node.setIsDirectory();
27237
- this.inodes[node.ino] = node;
27238
- return node;
27239
- };
27240
- Volume.prototype.getNode = function (ino) {
27241
- return this.inodes[ino];
27242
- };
27243
- Volume.prototype.deleteNode = function (node) {
27244
- node.del();
27245
- delete this.inodes[node.ino];
27246
- this.releasedInos.push(node.ino);
27247
- };
27248
- // Generates 6 character long random string, used by `mkdtemp`.
27249
- Volume.prototype.genRndStr = function () {
27250
- var str = (Math.random() + 1).toString(36).substr(2, 6);
27251
- if (str.length === 6)
27252
- return str;
27253
- else
27254
- return this.genRndStr();
27255
- };
27256
- // Returns a `Link` (hard link) referenced by path "split" into steps.
27257
- Volume.prototype.getLink = function (steps) {
27258
- return this.root.walk(steps);
27259
- };
27260
- // Just link `getLink`, but throws a correct user error, if link to found.
27261
- Volume.prototype.getLinkOrThrow = function (filename, funcName) {
27262
- var steps = filenameToSteps(filename);
27263
- var link = this.getLink(steps);
27264
- if (!link)
27265
- throw createError(ENOENT, funcName, filename);
27266
- return link;
27267
- };
27268
- // Just like `getLink`, but also dereference/resolves symbolic links.
27269
- Volume.prototype.getResolvedLink = function (filenameOrSteps) {
27270
- var steps = typeof filenameOrSteps === 'string' ? filenameToSteps(filenameOrSteps) : filenameOrSteps;
27271
- var link = this.root;
27272
- var i = 0;
27273
- while (i < steps.length) {
27274
- var step = steps[i];
27275
- link = link.getChild(step);
27276
- if (!link)
27277
- return null;
27278
- var node = link.getNode();
27279
- if (node.isSymlink()) {
27280
- steps = node.symlink.concat(steps.slice(i + 1));
27281
- link = this.root;
27282
- i = 0;
27283
- continue;
27284
- }
27285
- i++;
27286
- }
27287
- return link;
27288
- };
27289
- // Just like `getLinkOrThrow`, but also dereference/resolves symbolic links.
27290
- Volume.prototype.getResolvedLinkOrThrow = function (filename, funcName) {
27291
- var link = this.getResolvedLink(filename);
27292
- if (!link)
27293
- throw createError(ENOENT, funcName, filename);
27294
- return link;
27295
- };
27296
- Volume.prototype.resolveSymlinks = function (link) {
27297
- // let node: Node = link.getNode();
27298
- // while(link && node.isSymlink()) {
27299
- // link = this.getLink(node.symlink);
27300
- // if(!link) return null;
27301
- // node = link.getNode();
27302
- // }
27303
- // return link;
27304
- return this.getResolvedLink(link.steps.slice(1));
27305
- };
27306
- // Just like `getLinkOrThrow`, but also verifies that the link is a directory.
27307
- Volume.prototype.getLinkAsDirOrThrow = function (filename, funcName) {
27308
- var link = this.getLinkOrThrow(filename, funcName);
27309
- if (!link.getNode().isDirectory())
27310
- throw createError(ENOTDIR, funcName, filename);
27311
- return link;
27312
- };
27313
- // Get the immediate parent directory of the link.
27314
- Volume.prototype.getLinkParent = function (steps) {
27315
- return this.root.walk(steps, steps.length - 1);
27316
- };
27317
- Volume.prototype.getLinkParentAsDirOrThrow = function (filenameOrSteps, funcName) {
27318
- var steps = filenameOrSteps instanceof Array ? filenameOrSteps : filenameToSteps(filenameOrSteps);
27319
- var link = this.getLinkParent(steps);
27320
- if (!link)
27321
- throw createError(ENOENT, funcName, sep + steps.join(sep));
27322
- if (!link.getNode().isDirectory())
27323
- throw createError(ENOTDIR, funcName, sep + steps.join(sep));
27324
- return link;
27325
- };
27326
- Volume.prototype.getFileByFd = function (fd) {
27327
- return this.fds[String(fd)];
27328
- };
27329
- Volume.prototype.getFileByFdOrThrow = function (fd, funcName) {
27330
- if (!isFd(fd))
27331
- throw TypeError(ERRSTR.FD);
27332
- var file = this.getFileByFd(fd);
27333
- if (!file)
27334
- throw createError(EBADF, funcName);
27335
- return file;
27336
- };
27337
- /**
27338
- * @todo This is not used anymore. Remove.
27339
- */
27340
- /*
27341
- private getNodeByIdOrCreate(id: TFileId, flags: number, perm: number): Node {
27342
- if (typeof id === 'number') {
27343
- const file = this.getFileByFd(id);
27344
- if (!file) throw Error('File nto found');
27345
- return file.node;
27346
- } else {
27347
- const steps = pathToSteps(id as PathLike);
27348
- let link = this.getLink(steps);
27349
- if (link) return link.getNode();
27350
-
27351
- // Try creating a node if not found.
27352
- if (flags & O_CREAT) {
27353
- const dirLink = this.getLinkParent(steps);
27354
- if (dirLink) {
27355
- const name = steps[steps.length - 1];
27356
- link = this.createLink(dirLink, name, false, perm);
27357
- return link.getNode();
27358
- }
27359
- }
27360
-
27361
- throw createError(ENOENT, 'getNodeByIdOrCreate', pathToFilename(id));
27362
- }
27363
- }
27364
- */
27365
- Volume.prototype.wrapAsync = function (method, args, callback) {
27366
- var _this = this;
27367
- validateCallback(callback);
27368
- (0, setImmediate_1.default)(function () {
27369
- var result;
27370
- try {
27371
- result = method.apply(_this, args);
27372
- }
27373
- catch (err) {
27374
- callback(err);
27375
- return;
27376
- }
27377
- callback(null, result);
27378
- });
27379
- };
27380
- Volume.prototype._toJSON = function (link, json, path) {
27381
- var _a;
27382
- if (link === void 0) { link = this.root; }
27383
- if (json === void 0) { json = {}; }
27384
- var isEmpty = true;
27385
- var children = link.children;
27386
- if (link.getNode().isFile()) {
27387
- children = (_a = {}, _a[link.getName()] = link.parent.getChild(link.getName()), _a);
27388
- link = link.parent;
27389
- }
27390
- for (var name_1 in children) {
27391
- isEmpty = false;
27392
- var child = link.getChild(name_1);
27393
- if (!child) {
27394
- throw new Error('_toJSON: unexpected undefined');
27395
- }
27396
- var node = child.getNode();
27397
- if (node.isFile()) {
27398
- var filename = child.getPath();
27399
- if (path)
27400
- filename = relative(path, filename);
27401
- json[filename] = node.getString();
27402
- }
27403
- else if (node.isDirectory()) {
27404
- this._toJSON(child, json, path);
27405
- }
27406
- }
27407
- var dirPath = link.getPath();
27408
- if (path)
27409
- dirPath = relative(path, dirPath);
27410
- if (dirPath && isEmpty) {
27411
- json[dirPath] = null;
27412
- }
27413
- return json;
27414
- };
27415
- Volume.prototype.toJSON = function (paths, json, isRelative) {
27416
- if (json === void 0) { json = {}; }
27417
- if (isRelative === void 0) { isRelative = false; }
27418
- var links = [];
27419
- if (paths) {
27420
- if (!(paths instanceof Array))
27421
- paths = [paths];
27422
- for (var _i = 0, paths_1 = paths; _i < paths_1.length; _i++) {
27423
- var path = paths_1[_i];
27424
- var filename = pathToFilename(path);
27425
- var link = this.getResolvedLink(filename);
27426
- if (!link)
27427
- continue;
27428
- links.push(link);
27429
- }
27430
- }
27431
- else {
27432
- links.push(this.root);
27433
- }
27434
- if (!links.length)
27435
- return json;
27436
- for (var _a = 0, links_1 = links; _a < links_1.length; _a++) {
27437
- var link = links_1[_a];
27438
- this._toJSON(link, json, isRelative ? link.getPath() : '');
27439
- }
27440
- return json;
27441
- };
27442
- Volume.prototype.fromJSON = function (json, cwd) {
27443
- if (cwd === void 0) { cwd = process_1.default.cwd(); }
27444
- for (var filename in json) {
27445
- var data = json[filename];
27446
- filename = resolve(filename, cwd);
27447
- if (typeof data === 'string') {
27448
- var dir = dirname(filename);
27449
- this.mkdirpBase(dir, 511 /* MODE.DIR */);
27450
- this.writeFileSync(filename, data);
27451
- }
27452
- else {
27453
- this.mkdirpBase(filename, 511 /* MODE.DIR */);
27454
- }
27455
- }
27456
- };
27457
- Volume.prototype.fromNestedJSON = function (json, cwd) {
27458
- this.fromJSON(flattenJSON(json), cwd);
27459
- };
27460
- Volume.prototype.reset = function () {
27461
- this.ino = 0;
27462
- this.inodes = {};
27463
- this.releasedInos = [];
27464
- this.fds = {};
27465
- this.releasedFds = [];
27466
- this.openFiles = 0;
27467
- this.root = this.createLink();
27468
- this.root.setNode(this.createNode(true));
27469
- };
27470
- // Legacy interface
27471
- Volume.prototype.mountSync = function (mountpoint, json) {
27472
- this.fromJSON(json, mountpoint);
27473
- };
27474
- Volume.prototype.openLink = function (link, flagsNum, resolveSymlinks) {
27475
- if (resolveSymlinks === void 0) { resolveSymlinks = true; }
27476
- if (this.openFiles >= this.maxFiles) {
27477
- // Too many open files.
27478
- throw createError(EMFILE, 'open', link.getPath());
27479
- }
27480
- // Resolve symlinks.
27481
- var realLink = link;
27482
- if (resolveSymlinks)
27483
- realLink = this.resolveSymlinks(link);
27484
- if (!realLink)
27485
- throw createError(ENOENT, 'open', link.getPath());
27486
- var node = realLink.getNode();
27487
- // Check whether node is a directory
27488
- if (node.isDirectory()) {
27489
- if ((flagsNum & (O_RDONLY | O_RDWR | O_WRONLY)) !== O_RDONLY)
27490
- throw createError(EISDIR, 'open', link.getPath());
27491
- }
27492
- else {
27493
- if (flagsNum & O_DIRECTORY)
27494
- throw createError(ENOTDIR, 'open', link.getPath());
27495
- }
27496
- // Check node permissions
27497
- if (!(flagsNum & O_WRONLY)) {
27498
- if (!node.canRead()) {
27499
- throw createError(EACCES, 'open', link.getPath());
27500
- }
27501
- }
27502
- if (flagsNum & O_RDWR) {
27503
- }
27504
- var file = new this.props.File(link, node, flagsNum, this.newFdNumber());
27505
- this.fds[file.fd] = file;
27506
- this.openFiles++;
27507
- if (flagsNum & O_TRUNC)
27508
- file.truncate();
27509
- return file;
27510
- };
27511
- Volume.prototype.openFile = function (filename, flagsNum, modeNum, resolveSymlinks) {
27512
- if (resolveSymlinks === void 0) { resolveSymlinks = true; }
27513
- var steps = filenameToSteps(filename);
27514
- var link = resolveSymlinks ? this.getResolvedLink(steps) : this.getLink(steps);
27515
- if (link && flagsNum & O_EXCL)
27516
- throw createError(EEXIST, 'open', filename);
27517
- // Try creating a new file, if it does not exist.
27518
- if (!link && flagsNum & O_CREAT) {
27519
- // const dirLink: Link = this.getLinkParent(steps);
27520
- var dirLink = this.getResolvedLink(steps.slice(0, steps.length - 1));
27521
- // if(!dirLink) throw createError(ENOENT, 'open', filename);
27522
- if (!dirLink)
27523
- throw createError(ENOENT, 'open', sep + steps.join(sep));
27524
- if (flagsNum & O_CREAT && typeof modeNum === 'number') {
27525
- link = this.createLink(dirLink, steps[steps.length - 1], false, modeNum);
27526
- }
27527
- }
27528
- if (link)
27529
- return this.openLink(link, flagsNum, resolveSymlinks);
27530
- throw createError(ENOENT, 'open', filename);
27531
- };
27532
- Volume.prototype.openBase = function (filename, flagsNum, modeNum, resolveSymlinks) {
27533
- if (resolveSymlinks === void 0) { resolveSymlinks = true; }
27534
- var file = this.openFile(filename, flagsNum, modeNum, resolveSymlinks);
27535
- if (!file)
27536
- throw createError(ENOENT, 'open', filename);
27537
- return file.fd;
27538
- };
27539
- Volume.prototype.openSync = function (path, flags, mode) {
27540
- if (mode === void 0) { mode = 438 /* MODE.DEFAULT */; }
27541
- // Validate (1) mode; (2) path; (3) flags - in that order.
27542
- var modeNum = modeToNumber(mode);
27543
- var fileName = pathToFilename(path);
27544
- var flagsNum = flagsToNumber(flags);
27545
- return this.openBase(fileName, flagsNum, modeNum);
27546
- };
27547
- Volume.prototype.open = function (path, flags, a, b) {
27548
- var mode = a;
27549
- var callback = b;
27550
- if (typeof a === 'function') {
27551
- mode = 438 /* MODE.DEFAULT */;
27552
- callback = a;
27553
- }
27554
- mode = mode || 438 /* MODE.DEFAULT */;
27555
- var modeNum = modeToNumber(mode);
27556
- var fileName = pathToFilename(path);
27557
- var flagsNum = flagsToNumber(flags);
27558
- this.wrapAsync(this.openBase, [fileName, flagsNum, modeNum], callback);
27559
- };
27560
- Volume.prototype.closeFile = function (file) {
27561
- if (!this.fds[file.fd])
27562
- return;
27563
- this.openFiles--;
27564
- delete this.fds[file.fd];
27565
- this.releasedFds.push(file.fd);
27566
- };
27567
- Volume.prototype.closeSync = function (fd) {
27568
- validateFd(fd);
27569
- var file = this.getFileByFdOrThrow(fd, 'close');
27570
- this.closeFile(file);
27571
- };
27572
- Volume.prototype.close = function (fd, callback) {
27573
- validateFd(fd);
27574
- this.wrapAsync(this.closeSync, [fd], callback);
27575
- };
27576
- Volume.prototype.openFileOrGetById = function (id, flagsNum, modeNum) {
27577
- if (typeof id === 'number') {
27578
- var file = this.fds[id];
27579
- if (!file)
27580
- throw createError(ENOENT);
27581
- return file;
27582
- }
27583
- else {
27584
- return this.openFile(pathToFilename(id), flagsNum, modeNum);
27585
- }
27586
- };
27587
- Volume.prototype.readBase = function (fd, buffer, offset, length, position) {
27588
- var file = this.getFileByFdOrThrow(fd);
27589
- return file.read(buffer, Number(offset), Number(length), position);
27590
- };
27591
- Volume.prototype.readSync = function (fd, buffer, offset, length, position) {
27592
- validateFd(fd);
27593
- return this.readBase(fd, buffer, offset, length, position);
27594
- };
27595
- Volume.prototype.read = function (fd, buffer, offset, length, position, callback) {
27596
- var _this = this;
27597
- validateCallback(callback);
27598
- // This `if` branch is from Node.js
27599
- if (length === 0) {
27600
- return process_1.default.nextTick(function () {
27601
- if (callback)
27602
- callback(null, 0, buffer);
27603
- });
27604
- }
27605
- (0, setImmediate_1.default)(function () {
27606
- try {
27607
- var bytes = _this.readBase(fd, buffer, offset, length, position);
27608
- callback(null, bytes, buffer);
27609
- }
27610
- catch (err) {
27611
- callback(err);
27612
- }
27613
- });
27614
- };
27615
- Volume.prototype.readFileBase = function (id, flagsNum, encoding) {
27616
- var result;
27617
- var isUserFd = typeof id === 'number';
27618
- var userOwnsFd = isUserFd && isFd(id);
27619
- var fd;
27620
- if (userOwnsFd)
27621
- fd = id;
27622
- else {
27623
- var filename = pathToFilename(id);
27624
- var steps = filenameToSteps(filename);
27625
- var link = this.getResolvedLink(steps);
27626
- if (link) {
27627
- var node = link.getNode();
27628
- if (node.isDirectory())
27629
- throw createError(EISDIR, 'open', link.getPath());
27630
- }
27631
- fd = this.openSync(id, flagsNum);
27632
- }
27633
- try {
27634
- result = bufferToEncoding(this.getFileByFdOrThrow(fd).getBuffer(), encoding);
27635
- }
27636
- finally {
27637
- if (!userOwnsFd) {
27638
- this.closeSync(fd);
27639
- }
27640
- }
27641
- return result;
27642
- };
27643
- Volume.prototype.readFileSync = function (file, options) {
27644
- var opts = getReadFileOptions(options);
27645
- var flagsNum = flagsToNumber(opts.flag);
27646
- return this.readFileBase(file, flagsNum, opts.encoding);
27647
- };
27648
- Volume.prototype.readFile = function (id, a, b) {
27649
- var _a = optsAndCbGenerator(getReadFileOptions)(a, b), opts = _a[0], callback = _a[1];
27650
- var flagsNum = flagsToNumber(opts.flag);
27651
- this.wrapAsync(this.readFileBase, [id, flagsNum, opts.encoding], callback);
27652
- };
27653
- Volume.prototype.writeBase = function (fd, buf, offset, length, position) {
27654
- var file = this.getFileByFdOrThrow(fd, 'write');
27655
- return file.write(buf, offset, length, position);
27656
- };
27657
- Volume.prototype.writeSync = function (fd, a, b, c, d) {
27658
- validateFd(fd);
27659
- var encoding;
27660
- var offset;
27661
- var length;
27662
- var position;
27663
- var isBuffer = typeof a !== 'string';
27664
- if (isBuffer) {
27665
- offset = (b || 0) | 0;
27666
- length = c;
27667
- position = d;
27668
- }
27669
- else {
27670
- position = b;
27671
- encoding = c;
27672
- }
27673
- var buf = dataToBuffer(a, encoding);
27674
- if (isBuffer) {
27675
- if (typeof length === 'undefined') {
27676
- length = buf.length;
27677
- }
27678
- }
27679
- else {
27680
- offset = 0;
27681
- length = buf.length;
27682
- }
27683
- return this.writeBase(fd, buf, offset, length, position);
27684
- };
27685
- Volume.prototype.write = function (fd, a, b, c, d, e) {
27686
- var _this = this;
27687
- validateFd(fd);
27688
- var offset;
27689
- var length;
27690
- var position;
27691
- var encoding;
27692
- var callback;
27693
- var tipa = typeof a;
27694
- var tipb = typeof b;
27695
- var tipc = typeof c;
27696
- var tipd = typeof d;
27697
- if (tipa !== 'string') {
27698
- if (tipb === 'function') {
27699
- callback = b;
27700
- }
27701
- else if (tipc === 'function') {
27702
- offset = b | 0;
27703
- callback = c;
27704
- }
27705
- else if (tipd === 'function') {
27706
- offset = b | 0;
27707
- length = c;
27708
- callback = d;
27709
- }
27710
- else {
27711
- offset = b | 0;
27712
- length = c;
27713
- position = d;
27714
- callback = e;
27715
- }
27716
- }
27717
- else {
27718
- if (tipb === 'function') {
27719
- callback = b;
27720
- }
27721
- else if (tipc === 'function') {
27722
- position = b;
27723
- callback = c;
27724
- }
27725
- else if (tipd === 'function') {
27726
- position = b;
27727
- encoding = c;
27728
- callback = d;
27729
- }
27730
- }
27731
- var buf = dataToBuffer(a, encoding);
27732
- if (tipa !== 'string') {
27733
- if (typeof length === 'undefined')
27734
- length = buf.length;
27735
- }
27736
- else {
27737
- offset = 0;
27738
- length = buf.length;
27739
- }
27740
- var cb = validateCallback(callback);
27741
- (0, setImmediate_1.default)(function () {
27742
- try {
27743
- var bytes = _this.writeBase(fd, buf, offset, length, position);
27744
- if (tipa !== 'string') {
27745
- cb(null, bytes, buf);
27746
- }
27747
- else {
27748
- cb(null, bytes, a);
27749
- }
27750
- }
27751
- catch (err) {
27752
- cb(err);
27753
- }
27754
- });
27755
- };
27756
- Volume.prototype.writeFileBase = function (id, buf, flagsNum, modeNum) {
27757
- // console.log('writeFileBase', id, buf, flagsNum, modeNum);
27758
- // const node = this.getNodeByIdOrCreate(id, flagsNum, modeNum);
27759
- // node.setBuffer(buf);
27760
- var isUserFd = typeof id === 'number';
27761
- var fd;
27762
- if (isUserFd)
27763
- fd = id;
27764
- else {
27765
- fd = this.openBase(pathToFilename(id), flagsNum, modeNum);
27766
- // fd = this.openSync(id as PathLike, flagsNum, modeNum);
27767
- }
27768
- var offset = 0;
27769
- var length = buf.length;
27770
- var position = flagsNum & O_APPEND ? undefined : 0;
27771
- try {
27772
- while (length > 0) {
27773
- var written = this.writeSync(fd, buf, offset, length, position);
27774
- offset += written;
27775
- length -= written;
27776
- if (position !== undefined)
27777
- position += written;
27778
- }
27779
- }
27780
- finally {
27781
- if (!isUserFd)
27782
- this.closeSync(fd);
27783
- }
27784
- };
27785
- Volume.prototype.writeFileSync = function (id, data, options) {
27786
- var opts = getWriteFileOptions(options);
27787
- var flagsNum = flagsToNumber(opts.flag);
27788
- var modeNum = modeToNumber(opts.mode);
27789
- var buf = dataToBuffer(data, opts.encoding);
27790
- this.writeFileBase(id, buf, flagsNum, modeNum);
27791
- };
27792
- Volume.prototype.writeFile = function (id, data, a, b) {
27793
- var options = a;
27794
- var callback = b;
27795
- if (typeof a === 'function') {
27796
- options = writeFileDefaults;
27797
- callback = a;
27798
- }
27799
- var cb = validateCallback(callback);
27800
- var opts = getWriteFileOptions(options);
27801
- var flagsNum = flagsToNumber(opts.flag);
27802
- var modeNum = modeToNumber(opts.mode);
27803
- var buf = dataToBuffer(data, opts.encoding);
27804
- this.wrapAsync(this.writeFileBase, [id, buf, flagsNum, modeNum], cb);
27805
- };
27806
- Volume.prototype.linkBase = function (filename1, filename2) {
27807
- var steps1 = filenameToSteps(filename1);
27808
- var link1 = this.getLink(steps1);
27809
- if (!link1)
27810
- throw createError(ENOENT, 'link', filename1, filename2);
27811
- var steps2 = filenameToSteps(filename2);
27812
- // Check new link directory exists.
27813
- var dir2 = this.getLinkParent(steps2);
27814
- if (!dir2)
27815
- throw createError(ENOENT, 'link', filename1, filename2);
27816
- var name = steps2[steps2.length - 1];
27817
- // Check if new file already exists.
27818
- if (dir2.getChild(name))
27819
- throw createError(EEXIST, 'link', filename1, filename2);
27820
- var node = link1.getNode();
27821
- node.nlink++;
27822
- dir2.createChild(name, node);
27823
- };
27824
- Volume.prototype.copyFileBase = function (src, dest, flags) {
27825
- var buf = this.readFileSync(src);
27826
- if (flags & COPYFILE_EXCL) {
27827
- if (this.existsSync(dest)) {
27828
- throw createError(EEXIST, 'copyFile', src, dest);
27829
- }
27830
- }
27831
- if (flags & COPYFILE_FICLONE_FORCE) {
27832
- throw createError(ENOSYS, 'copyFile', src, dest);
27833
- }
27834
- this.writeFileBase(dest, buf, FLAGS.w, 438 /* MODE.DEFAULT */);
27835
- };
27836
- Volume.prototype.copyFileSync = function (src, dest, flags) {
27837
- var srcFilename = pathToFilename(src);
27838
- var destFilename = pathToFilename(dest);
27839
- return this.copyFileBase(srcFilename, destFilename, (flags || 0) | 0);
27840
- };
27841
- Volume.prototype.copyFile = function (src, dest, a, b) {
27842
- var srcFilename = pathToFilename(src);
27843
- var destFilename = pathToFilename(dest);
27844
- var flags;
27845
- var callback;
27846
- if (typeof a === 'function') {
27847
- flags = 0;
27848
- callback = a;
27849
- }
27850
- else {
27851
- flags = a;
27852
- callback = b;
27853
- }
27854
- validateCallback(callback);
27855
- this.wrapAsync(this.copyFileBase, [srcFilename, destFilename, flags], callback);
27856
- };
27857
- Volume.prototype.linkSync = function (existingPath, newPath) {
27858
- var existingPathFilename = pathToFilename(existingPath);
27859
- var newPathFilename = pathToFilename(newPath);
27860
- this.linkBase(existingPathFilename, newPathFilename);
27861
- };
27862
- Volume.prototype.link = function (existingPath, newPath, callback) {
27863
- var existingPathFilename = pathToFilename(existingPath);
27864
- var newPathFilename = pathToFilename(newPath);
27865
- this.wrapAsync(this.linkBase, [existingPathFilename, newPathFilename], callback);
27866
- };
27867
- Volume.prototype.unlinkBase = function (filename) {
27868
- var steps = filenameToSteps(filename);
27869
- var link = this.getLink(steps);
27870
- if (!link)
27871
- throw createError(ENOENT, 'unlink', filename);
27872
- // TODO: Check if it is file, dir, other...
27873
- if (link.length)
27874
- throw Error('Dir not empty...');
27875
- this.deleteLink(link);
27876
- var node = link.getNode();
27877
- node.nlink--;
27878
- // When all hard links to i-node are deleted, remove the i-node, too.
27879
- if (node.nlink <= 0) {
27880
- this.deleteNode(node);
27881
- }
27882
- };
27883
- Volume.prototype.unlinkSync = function (path) {
27884
- var filename = pathToFilename(path);
27885
- this.unlinkBase(filename);
27886
- };
27887
- Volume.prototype.unlink = function (path, callback) {
27888
- var filename = pathToFilename(path);
27889
- this.wrapAsync(this.unlinkBase, [filename], callback);
27890
- };
27891
- Volume.prototype.symlinkBase = function (targetFilename, pathFilename) {
27892
- var pathSteps = filenameToSteps(pathFilename);
27893
- // Check if directory exists, where we about to create a symlink.
27894
- var dirLink = this.getLinkParent(pathSteps);
27895
- if (!dirLink)
27896
- throw createError(ENOENT, 'symlink', targetFilename, pathFilename);
27897
- var name = pathSteps[pathSteps.length - 1];
27898
- // Check if new file already exists.
27899
- if (dirLink.getChild(name))
27900
- throw createError(EEXIST, 'symlink', targetFilename, pathFilename);
27901
- // Create symlink.
27902
- var symlink = dirLink.createChild(name);
27903
- symlink.getNode().makeSymlink(filenameToSteps(targetFilename));
27904
- return symlink;
27905
- };
27906
- // `type` argument works only on Windows.
27907
- Volume.prototype.symlinkSync = function (target, path, type) {
27908
- var targetFilename = pathToFilename(target);
27909
- var pathFilename = pathToFilename(path);
27910
- this.symlinkBase(targetFilename, pathFilename);
27911
- };
27912
- Volume.prototype.symlink = function (target, path, a, b) {
27913
- var callback = validateCallback(typeof a === 'function' ? a : b);
27914
- var targetFilename = pathToFilename(target);
27915
- var pathFilename = pathToFilename(path);
27916
- this.wrapAsync(this.symlinkBase, [targetFilename, pathFilename], callback);
27917
- };
27918
- Volume.prototype.realpathBase = function (filename, encoding) {
27919
- var steps = filenameToSteps(filename);
27920
- var realLink = this.getResolvedLink(steps);
27921
- if (!realLink)
27922
- throw createError(ENOENT, 'realpath', filename);
27923
- return (0, encoding_1.strToEncoding)(realLink.getPath(), encoding);
27924
- };
27925
- Volume.prototype.realpathSync = function (path, options) {
27926
- return this.realpathBase(pathToFilename(path), getRealpathOptions(options).encoding);
27927
- };
27928
- Volume.prototype.realpath = function (path, a, b) {
27929
- var _a = getRealpathOptsAndCb(a, b), opts = _a[0], callback = _a[1];
27930
- var pathFilename = pathToFilename(path);
27931
- this.wrapAsync(this.realpathBase, [pathFilename, opts.encoding], callback);
27932
- };
27933
- Volume.prototype.lstatBase = function (filename, bigint, throwIfNoEntry) {
27934
- if (bigint === void 0) { bigint = false; }
27935
- if (throwIfNoEntry === void 0) { throwIfNoEntry = false; }
27936
- var link = this.getLink(filenameToSteps(filename));
27937
- if (link) {
27938
- return Stats_1.default.build(link.getNode(), bigint);
27939
- }
27940
- else if (!throwIfNoEntry) {
27941
- return undefined;
27942
- }
27943
- else {
27944
- throw createError(ENOENT, 'lstat', filename);
27945
- }
27946
- };
27947
- Volume.prototype.lstatSync = function (path, options) {
27948
- var _a = getStatOptions(options), _b = _a.throwIfNoEntry, throwIfNoEntry = _b === void 0 ? true : _b, _c = _a.bigint, bigint = _c === void 0 ? false : _c;
27949
- return this.lstatBase(pathToFilename(path), bigint, throwIfNoEntry);
27950
- };
27951
- Volume.prototype.lstat = function (path, a, b) {
27952
- var _a = getStatOptsAndCb(a, b), _b = _a[0], _c = _b.throwIfNoEntry, throwIfNoEntry = _c === void 0 ? true : _c, _d = _b.bigint, bigint = _d === void 0 ? false : _d, callback = _a[1];
27953
- this.wrapAsync(this.lstatBase, [pathToFilename(path), bigint, throwIfNoEntry], callback);
27954
- };
27955
- Volume.prototype.statBase = function (filename, bigint, throwIfNoEntry) {
27956
- if (bigint === void 0) { bigint = false; }
27957
- if (throwIfNoEntry === void 0) { throwIfNoEntry = true; }
27958
- var link = this.getResolvedLink(filenameToSteps(filename));
27959
- if (link) {
27960
- return Stats_1.default.build(link.getNode(), bigint);
27961
- }
27962
- else if (!throwIfNoEntry) {
27963
- return undefined;
27964
- }
27965
- else {
27966
- throw createError(ENOENT, 'stat', filename);
27967
- }
27968
- };
27969
- Volume.prototype.statSync = function (path, options) {
27970
- var _a = getStatOptions(options), _b = _a.bigint, bigint = _b === void 0 ? true : _b, _c = _a.throwIfNoEntry, throwIfNoEntry = _c === void 0 ? true : _c;
27971
- return this.statBase(pathToFilename(path), bigint, throwIfNoEntry);
27972
- };
27973
- Volume.prototype.stat = function (path, a, b) {
27974
- var _a = getStatOptsAndCb(a, b), _b = _a[0], _c = _b.bigint, bigint = _c === void 0 ? false : _c, _d = _b.throwIfNoEntry, throwIfNoEntry = _d === void 0 ? true : _d, callback = _a[1];
27975
- this.wrapAsync(this.statBase, [pathToFilename(path), bigint, throwIfNoEntry], callback);
27976
- };
27977
- Volume.prototype.fstatBase = function (fd, bigint) {
27978
- if (bigint === void 0) { bigint = false; }
27979
- var file = this.getFileByFd(fd);
27980
- if (!file)
27981
- throw createError(EBADF, 'fstat');
27982
- return Stats_1.default.build(file.node, bigint);
27983
- };
27984
- Volume.prototype.fstatSync = function (fd, options) {
27985
- return this.fstatBase(fd, getStatOptions(options).bigint);
27986
- };
27987
- Volume.prototype.fstat = function (fd, a, b) {
27988
- var _a = getStatOptsAndCb(a, b), opts = _a[0], callback = _a[1];
27989
- this.wrapAsync(this.fstatBase, [fd, opts.bigint], callback);
27990
- };
27991
- Volume.prototype.renameBase = function (oldPathFilename, newPathFilename) {
27992
- var link = this.getLink(filenameToSteps(oldPathFilename));
27993
- if (!link)
27994
- throw createError(ENOENT, 'rename', oldPathFilename, newPathFilename);
27995
- // TODO: Check if it is directory, if non-empty, we cannot move it, right?
27996
- var newPathSteps = filenameToSteps(newPathFilename);
27997
- // Check directory exists for the new location.
27998
- var newPathDirLink = this.getLinkParent(newPathSteps);
27999
- if (!newPathDirLink)
28000
- throw createError(ENOENT, 'rename', oldPathFilename, newPathFilename);
28001
- // TODO: Also treat cases with directories and symbolic links.
28002
- // TODO: See: http://man7.org/linux/man-pages/man2/rename.2.html
28003
- // Remove hard link from old folder.
28004
- var oldLinkParent = link.parent;
28005
- if (oldLinkParent) {
28006
- oldLinkParent.deleteChild(link);
28007
- }
28008
- // Rename should overwrite the new path, if that exists.
28009
- var name = newPathSteps[newPathSteps.length - 1];
28010
- link.name = name;
28011
- link.steps = __spreadArray(__spreadArray([], newPathDirLink.steps, true), [name], false);
28012
- newPathDirLink.setChild(link.getName(), link);
28013
- };
28014
- Volume.prototype.renameSync = function (oldPath, newPath) {
28015
- var oldPathFilename = pathToFilename(oldPath);
28016
- var newPathFilename = pathToFilename(newPath);
28017
- this.renameBase(oldPathFilename, newPathFilename);
28018
- };
28019
- Volume.prototype.rename = function (oldPath, newPath, callback) {
28020
- var oldPathFilename = pathToFilename(oldPath);
28021
- var newPathFilename = pathToFilename(newPath);
28022
- this.wrapAsync(this.renameBase, [oldPathFilename, newPathFilename], callback);
28023
- };
28024
- Volume.prototype.existsBase = function (filename) {
28025
- return !!this.statBase(filename);
28026
- };
28027
- Volume.prototype.existsSync = function (path) {
28028
- try {
28029
- return this.existsBase(pathToFilename(path));
28030
- }
28031
- catch (err) {
28032
- return false;
28033
- }
28034
- };
28035
- Volume.prototype.exists = function (path, callback) {
28036
- var _this = this;
28037
- var filename = pathToFilename(path);
28038
- if (typeof callback !== 'function')
28039
- throw Error(ERRSTR.CB);
28040
- (0, setImmediate_1.default)(function () {
28041
- try {
28042
- callback(_this.existsBase(filename));
28043
- }
28044
- catch (err) {
28045
- callback(false);
28046
- }
28047
- });
28048
- };
28049
- Volume.prototype.accessBase = function (filename, mode) {
28050
- var link = this.getLinkOrThrow(filename, 'access');
28051
- // TODO: Verify permissions
28052
- };
28053
- Volume.prototype.accessSync = function (path, mode) {
28054
- if (mode === void 0) { mode = F_OK; }
28055
- var filename = pathToFilename(path);
28056
- mode = mode | 0;
28057
- this.accessBase(filename, mode);
28058
- };
28059
- Volume.prototype.access = function (path, a, b) {
28060
- var mode = F_OK;
28061
- var callback;
28062
- if (typeof a !== 'function') {
28063
- mode = a | 0; // cast to number
28064
- callback = validateCallback(b);
28065
- }
28066
- else {
28067
- callback = a;
28068
- }
28069
- var filename = pathToFilename(path);
28070
- this.wrapAsync(this.accessBase, [filename, mode], callback);
28071
- };
28072
- Volume.prototype.appendFileSync = function (id, data, options) {
28073
- if (options === void 0) { options = appendFileDefaults; }
28074
- var opts = getAppendFileOpts(options);
28075
- // force append behavior when using a supplied file descriptor
28076
- if (!opts.flag || isFd(id))
28077
- opts.flag = 'a';
28078
- this.writeFileSync(id, data, opts);
28079
- };
28080
- Volume.prototype.appendFile = function (id, data, a, b) {
28081
- var _a = getAppendFileOptsAndCb(a, b), opts = _a[0], callback = _a[1];
28082
- // force append behavior when using a supplied file descriptor
28083
- if (!opts.flag || isFd(id))
28084
- opts.flag = 'a';
28085
- this.writeFile(id, data, opts, callback);
28086
- };
28087
- Volume.prototype.readdirBase = function (filename, options) {
28088
- var steps = filenameToSteps(filename);
28089
- var link = this.getResolvedLink(steps);
28090
- if (!link)
28091
- throw createError(ENOENT, 'readdir', filename);
28092
- var node = link.getNode();
28093
- if (!node.isDirectory())
28094
- throw createError(ENOTDIR, 'scandir', filename);
28095
- if (options.withFileTypes) {
28096
- var list_1 = [];
28097
- for (var name_2 in link.children) {
28098
- var child = link.getChild(name_2);
28099
- if (!child) {
28100
- continue;
28101
- }
28102
- list_1.push(Dirent_1.default.build(child, options.encoding));
28103
- }
28104
- if (!isWin && options.encoding !== 'buffer')
28105
- list_1.sort(function (a, b) {
28106
- if (a.name < b.name)
28107
- return -1;
28108
- if (a.name > b.name)
28109
- return 1;
28110
- return 0;
28111
- });
28112
- return list_1;
28113
- }
28114
- var list = [];
28115
- for (var name_3 in link.children) {
28116
- list.push((0, encoding_1.strToEncoding)(name_3, options.encoding));
28117
- }
28118
- if (!isWin && options.encoding !== 'buffer')
28119
- list.sort();
28120
- return list;
28121
- };
28122
- Volume.prototype.readdirSync = function (path, options) {
28123
- var opts = getReaddirOptions(options);
28124
- var filename = pathToFilename(path);
28125
- return this.readdirBase(filename, opts);
28126
- };
28127
- Volume.prototype.readdir = function (path, a, b) {
28128
- var _a = getReaddirOptsAndCb(a, b), options = _a[0], callback = _a[1];
28129
- var filename = pathToFilename(path);
28130
- this.wrapAsync(this.readdirBase, [filename, options], callback);
28131
- };
28132
- Volume.prototype.readlinkBase = function (filename, encoding) {
28133
- var link = this.getLinkOrThrow(filename, 'readlink');
28134
- var node = link.getNode();
28135
- if (!node.isSymlink())
28136
- throw createError(EINVAL, 'readlink', filename);
28137
- var str = sep + node.symlink.join(sep);
28138
- return (0, encoding_1.strToEncoding)(str, encoding);
28139
- };
28140
- Volume.prototype.readlinkSync = function (path, options) {
28141
- var opts = getDefaultOpts(options);
28142
- var filename = pathToFilename(path);
28143
- return this.readlinkBase(filename, opts.encoding);
28144
- };
28145
- Volume.prototype.readlink = function (path, a, b) {
28146
- var _a = getDefaultOptsAndCb(a, b), opts = _a[0], callback = _a[1];
28147
- var filename = pathToFilename(path);
28148
- this.wrapAsync(this.readlinkBase, [filename, opts.encoding], callback);
28149
- };
28150
- Volume.prototype.fsyncBase = function (fd) {
28151
- this.getFileByFdOrThrow(fd, 'fsync');
28152
- };
28153
- Volume.prototype.fsyncSync = function (fd) {
28154
- this.fsyncBase(fd);
28155
- };
28156
- Volume.prototype.fsync = function (fd, callback) {
28157
- this.wrapAsync(this.fsyncBase, [fd], callback);
28158
- };
28159
- Volume.prototype.fdatasyncBase = function (fd) {
28160
- this.getFileByFdOrThrow(fd, 'fdatasync');
28161
- };
28162
- Volume.prototype.fdatasyncSync = function (fd) {
28163
- this.fdatasyncBase(fd);
28164
- };
28165
- Volume.prototype.fdatasync = function (fd, callback) {
28166
- this.wrapAsync(this.fdatasyncBase, [fd], callback);
28167
- };
28168
- Volume.prototype.ftruncateBase = function (fd, len) {
28169
- var file = this.getFileByFdOrThrow(fd, 'ftruncate');
28170
- file.truncate(len);
28171
- };
28172
- Volume.prototype.ftruncateSync = function (fd, len) {
28173
- this.ftruncateBase(fd, len);
28174
- };
28175
- Volume.prototype.ftruncate = function (fd, a, b) {
28176
- var len = typeof a === 'number' ? a : 0;
28177
- var callback = validateCallback(typeof a === 'number' ? b : a);
28178
- this.wrapAsync(this.ftruncateBase, [fd, len], callback);
28179
- };
28180
- Volume.prototype.truncateBase = function (path, len) {
28181
- var fd = this.openSync(path, 'r+');
28182
- try {
28183
- this.ftruncateSync(fd, len);
28184
- }
28185
- finally {
28186
- this.closeSync(fd);
28187
- }
28188
- };
28189
- Volume.prototype.truncateSync = function (id, len) {
28190
- if (isFd(id))
28191
- return this.ftruncateSync(id, len);
28192
- this.truncateBase(id, len);
28193
- };
28194
- Volume.prototype.truncate = function (id, a, b) {
28195
- var len = typeof a === 'number' ? a : 0;
28196
- var callback = validateCallback(typeof a === 'number' ? b : a);
28197
- if (isFd(id))
28198
- return this.ftruncate(id, len, callback);
28199
- this.wrapAsync(this.truncateBase, [id, len], callback);
28200
- };
28201
- Volume.prototype.futimesBase = function (fd, atime, mtime) {
28202
- var file = this.getFileByFdOrThrow(fd, 'futimes');
28203
- var node = file.node;
28204
- node.atime = new Date(atime * 1000);
28205
- node.mtime = new Date(mtime * 1000);
28206
- };
28207
- Volume.prototype.futimesSync = function (fd, atime, mtime) {
28208
- this.futimesBase(fd, toUnixTimestamp(atime), toUnixTimestamp(mtime));
28209
- };
28210
- Volume.prototype.futimes = function (fd, atime, mtime, callback) {
28211
- this.wrapAsync(this.futimesBase, [fd, toUnixTimestamp(atime), toUnixTimestamp(mtime)], callback);
28212
- };
28213
- Volume.prototype.utimesBase = function (filename, atime, mtime) {
28214
- var fd = this.openSync(filename, 'r+');
28215
- try {
28216
- this.futimesBase(fd, atime, mtime);
28217
- }
28218
- finally {
28219
- this.closeSync(fd);
28220
- }
28221
- };
28222
- Volume.prototype.utimesSync = function (path, atime, mtime) {
28223
- this.utimesBase(pathToFilename(path), toUnixTimestamp(atime), toUnixTimestamp(mtime));
28224
- };
28225
- Volume.prototype.utimes = function (path, atime, mtime, callback) {
28226
- this.wrapAsync(this.utimesBase, [pathToFilename(path), toUnixTimestamp(atime), toUnixTimestamp(mtime)], callback);
28227
- };
28228
- Volume.prototype.mkdirBase = function (filename, modeNum) {
28229
- var steps = filenameToSteps(filename);
28230
- // This will throw if user tries to create root dir `fs.mkdirSync('/')`.
28231
- if (!steps.length) {
28232
- throw createError(EEXIST, 'mkdir', filename);
28233
- }
28234
- var dir = this.getLinkParentAsDirOrThrow(filename, 'mkdir');
28235
- // Check path already exists.
28236
- var name = steps[steps.length - 1];
28237
- if (dir.getChild(name))
28238
- throw createError(EEXIST, 'mkdir', filename);
28239
- dir.createChild(name, this.createNode(true, modeNum));
28240
- };
28241
- /**
28242
- * Creates directory tree recursively.
28243
- * @param filename
28244
- * @param modeNum
28245
- */
28246
- Volume.prototype.mkdirpBase = function (filename, modeNum) {
28247
- var steps = filenameToSteps(filename);
28248
- var link = this.root;
28249
- for (var i = 0; i < steps.length; i++) {
28250
- var step = steps[i];
28251
- if (!link.getNode().isDirectory())
28252
- throw createError(ENOTDIR, 'mkdir', link.getPath());
28253
- var child = link.getChild(step);
28254
- if (child) {
28255
- if (child.getNode().isDirectory())
28256
- link = child;
28257
- else
28258
- throw createError(ENOTDIR, 'mkdir', child.getPath());
28259
- }
28260
- else {
28261
- link = link.createChild(step, this.createNode(true, modeNum));
28262
- }
28263
- }
28264
- };
28265
- Volume.prototype.mkdirSync = function (path, options) {
28266
- var opts = getMkdirOptions(options);
28267
- var modeNum = modeToNumber(opts.mode, 511);
28268
- var filename = pathToFilename(path);
28269
- if (opts.recursive)
28270
- this.mkdirpBase(filename, modeNum);
28271
- else
28272
- this.mkdirBase(filename, modeNum);
28273
- };
28274
- Volume.prototype.mkdir = function (path, a, b) {
28275
- var opts = getMkdirOptions(a);
28276
- var callback = validateCallback(typeof a === 'function' ? a : b);
28277
- var modeNum = modeToNumber(opts.mode, 511);
28278
- var filename = pathToFilename(path);
28279
- if (opts.recursive)
28280
- this.wrapAsync(this.mkdirpBase, [filename, modeNum], callback);
28281
- else
28282
- this.wrapAsync(this.mkdirBase, [filename, modeNum], callback);
28283
- };
28284
- // legacy interface
28285
- Volume.prototype.mkdirpSync = function (path, mode) {
28286
- this.mkdirSync(path, { mode: mode, recursive: true });
28287
- };
28288
- Volume.prototype.mkdirp = function (path, a, b) {
28289
- var mode = typeof a === 'function' ? undefined : a;
28290
- var callback = validateCallback(typeof a === 'function' ? a : b);
28291
- this.mkdir(path, { mode: mode, recursive: true }, callback);
28292
- };
28293
- Volume.prototype.mkdtempBase = function (prefix, encoding, retry) {
28294
- if (retry === void 0) { retry = 5; }
28295
- var filename = prefix + this.genRndStr();
28296
- try {
28297
- this.mkdirBase(filename, 511 /* MODE.DIR */);
28298
- return (0, encoding_1.strToEncoding)(filename, encoding);
28299
- }
28300
- catch (err) {
28301
- if (err.code === EEXIST) {
28302
- if (retry > 1)
28303
- return this.mkdtempBase(prefix, encoding, retry - 1);
28304
- else
28305
- throw Error('Could not create temp dir.');
28306
- }
28307
- else
28308
- throw err;
28309
- }
28310
- };
28311
- Volume.prototype.mkdtempSync = function (prefix, options) {
28312
- var encoding = getDefaultOpts(options).encoding;
28313
- if (!prefix || typeof prefix !== 'string')
28314
- throw new TypeError('filename prefix is required');
28315
- nullCheck(prefix);
28316
- return this.mkdtempBase(prefix, encoding);
28317
- };
28318
- Volume.prototype.mkdtemp = function (prefix, a, b) {
28319
- var _a = getDefaultOptsAndCb(a, b), encoding = _a[0].encoding, callback = _a[1];
28320
- if (!prefix || typeof prefix !== 'string')
28321
- throw new TypeError('filename prefix is required');
28322
- if (!nullCheck(prefix))
28323
- return;
28324
- this.wrapAsync(this.mkdtempBase, [prefix, encoding], callback);
28325
- };
28326
- Volume.prototype.rmdirBase = function (filename, options) {
28327
- var opts = getRmdirOptions(options);
28328
- var link = this.getLinkAsDirOrThrow(filename, 'rmdir');
28329
- // Check directory is empty.
28330
- if (link.length && !opts.recursive)
28331
- throw createError(ENOTEMPTY, 'rmdir', filename);
28332
- this.deleteLink(link);
28333
- };
28334
- Volume.prototype.rmdirSync = function (path, options) {
28335
- this.rmdirBase(pathToFilename(path), options);
28336
- };
28337
- Volume.prototype.rmdir = function (path, a, b) {
28338
- var opts = getRmdirOptions(a);
28339
- var callback = validateCallback(typeof a === 'function' ? a : b);
28340
- this.wrapAsync(this.rmdirBase, [pathToFilename(path), opts], callback);
28341
- };
28342
- Volume.prototype.rmBase = function (filename, options) {
28343
- if (options === void 0) { options = {}; }
28344
- var link = this.getResolvedLink(filename);
28345
- if (!link) {
28346
- // "stat" is used to match Node's native error message.
28347
- if (!options.force)
28348
- throw createError(ENOENT, 'stat', filename);
28349
- return;
28350
- }
28351
- if (link.getNode().isDirectory()) {
28352
- if (!options.recursive) {
28353
- throw createError(ERR_FS_EISDIR, 'rm', filename);
28354
- }
28355
- }
28356
- this.deleteLink(link);
28357
- };
28358
- Volume.prototype.rmSync = function (path, options) {
28359
- this.rmBase(pathToFilename(path), options);
28360
- };
28361
- Volume.prototype.rm = function (path, a, b) {
28362
- var _a = getRmOptsAndCb(a, b), opts = _a[0], callback = _a[1];
28363
- this.wrapAsync(this.rmBase, [pathToFilename(path), opts], callback);
28364
- };
28365
- Volume.prototype.fchmodBase = function (fd, modeNum) {
28366
- var file = this.getFileByFdOrThrow(fd, 'fchmod');
28367
- file.chmod(modeNum);
28368
- };
28369
- Volume.prototype.fchmodSync = function (fd, mode) {
28370
- this.fchmodBase(fd, modeToNumber(mode));
28371
- };
28372
- Volume.prototype.fchmod = function (fd, mode, callback) {
28373
- this.wrapAsync(this.fchmodBase, [fd, modeToNumber(mode)], callback);
28374
- };
28375
- Volume.prototype.chmodBase = function (filename, modeNum) {
28376
- var fd = this.openSync(filename, 'r+');
28377
- try {
28378
- this.fchmodBase(fd, modeNum);
28379
- }
28380
- finally {
28381
- this.closeSync(fd);
28382
- }
28383
- };
28384
- Volume.prototype.chmodSync = function (path, mode) {
28385
- var modeNum = modeToNumber(mode);
28386
- var filename = pathToFilename(path);
28387
- this.chmodBase(filename, modeNum);
28388
- };
28389
- Volume.prototype.chmod = function (path, mode, callback) {
28390
- var modeNum = modeToNumber(mode);
28391
- var filename = pathToFilename(path);
28392
- this.wrapAsync(this.chmodBase, [filename, modeNum], callback);
28393
- };
28394
- Volume.prototype.lchmodBase = function (filename, modeNum) {
28395
- var fd = this.openBase(filename, O_RDWR, 0, false);
28396
- try {
28397
- this.fchmodBase(fd, modeNum);
28398
- }
28399
- finally {
28400
- this.closeSync(fd);
28401
- }
28402
- };
28403
- Volume.prototype.lchmodSync = function (path, mode) {
28404
- var modeNum = modeToNumber(mode);
28405
- var filename = pathToFilename(path);
28406
- this.lchmodBase(filename, modeNum);
28407
- };
28408
- Volume.prototype.lchmod = function (path, mode, callback) {
28409
- var modeNum = modeToNumber(mode);
28410
- var filename = pathToFilename(path);
28411
- this.wrapAsync(this.lchmodBase, [filename, modeNum], callback);
28412
- };
28413
- Volume.prototype.fchownBase = function (fd, uid, gid) {
28414
- this.getFileByFdOrThrow(fd, 'fchown').chown(uid, gid);
28415
- };
28416
- Volume.prototype.fchownSync = function (fd, uid, gid) {
28417
- validateUid(uid);
28418
- validateGid(gid);
28419
- this.fchownBase(fd, uid, gid);
28420
- };
28421
- Volume.prototype.fchown = function (fd, uid, gid, callback) {
28422
- validateUid(uid);
28423
- validateGid(gid);
28424
- this.wrapAsync(this.fchownBase, [fd, uid, gid], callback);
28425
- };
28426
- Volume.prototype.chownBase = function (filename, uid, gid) {
28427
- var link = this.getResolvedLinkOrThrow(filename, 'chown');
28428
- var node = link.getNode();
28429
- node.chown(uid, gid);
28430
- // if(node.isFile() || node.isSymlink()) {
28431
- //
28432
- // } else if(node.isDirectory()) {
28433
- //
28434
- // } else {
28435
- // TODO: What do we do here?
28436
- // }
28437
- };
28438
- Volume.prototype.chownSync = function (path, uid, gid) {
28439
- validateUid(uid);
28440
- validateGid(gid);
28441
- this.chownBase(pathToFilename(path), uid, gid);
28442
- };
28443
- Volume.prototype.chown = function (path, uid, gid, callback) {
28444
- validateUid(uid);
28445
- validateGid(gid);
28446
- this.wrapAsync(this.chownBase, [pathToFilename(path), uid, gid], callback);
28447
- };
28448
- Volume.prototype.lchownBase = function (filename, uid, gid) {
28449
- this.getLinkOrThrow(filename, 'lchown').getNode().chown(uid, gid);
28450
- };
28451
- Volume.prototype.lchownSync = function (path, uid, gid) {
28452
- validateUid(uid);
28453
- validateGid(gid);
28454
- this.lchownBase(pathToFilename(path), uid, gid);
28455
- };
28456
- Volume.prototype.lchown = function (path, uid, gid, callback) {
28457
- validateUid(uid);
28458
- validateGid(gid);
28459
- this.wrapAsync(this.lchownBase, [pathToFilename(path), uid, gid], callback);
28460
- };
28461
- Volume.prototype.watchFile = function (path, a, b) {
28462
- var filename = pathToFilename(path);
28463
- var options = a;
28464
- var listener = b;
28465
- if (typeof options === 'function') {
28466
- listener = a;
28467
- options = null;
28468
- }
28469
- if (typeof listener !== 'function') {
28470
- throw Error('"watchFile()" requires a listener function');
28471
- }
28472
- var interval = 5007;
28473
- var persistent = true;
28474
- if (options && typeof options === 'object') {
28475
- if (typeof options.interval === 'number')
28476
- interval = options.interval;
28477
- if (typeof options.persistent === 'boolean')
28478
- persistent = options.persistent;
28479
- }
28480
- var watcher = this.statWatchers[filename];
28481
- if (!watcher) {
28482
- watcher = new this.StatWatcher();
28483
- watcher.start(filename, persistent, interval);
28484
- this.statWatchers[filename] = watcher;
28485
- }
28486
- watcher.addListener('change', listener);
28487
- return watcher;
28488
- };
28489
- Volume.prototype.unwatchFile = function (path, listener) {
28490
- var filename = pathToFilename(path);
28491
- var watcher = this.statWatchers[filename];
28492
- if (!watcher)
28493
- return;
28494
- if (typeof listener === 'function') {
28495
- watcher.removeListener('change', listener);
28496
- }
28497
- else {
28498
- watcher.removeAllListeners('change');
28499
- }
28500
- if (watcher.listenerCount('change') === 0) {
28501
- watcher.stop();
28502
- delete this.statWatchers[filename];
28503
- }
28504
- };
28505
- Volume.prototype.createReadStream = function (path, options) {
28506
- return new this.ReadStream(path, options);
28507
- };
28508
- Volume.prototype.createWriteStream = function (path, options) {
28509
- return new this.WriteStream(path, options);
28510
- };
28511
- // watch(path: PathLike): FSWatcher;
28512
- // watch(path: PathLike, options?: IWatchOptions | string): FSWatcher;
28513
- Volume.prototype.watch = function (path, options, listener) {
28514
- var filename = pathToFilename(path);
28515
- var givenOptions = options;
28516
- if (typeof options === 'function') {
28517
- listener = options;
28518
- givenOptions = null;
28519
- }
28520
- // tslint:disable-next-line prefer-const
28521
- var _a = getDefaultOpts(givenOptions), persistent = _a.persistent, recursive = _a.recursive, encoding = _a.encoding;
28522
- if (persistent === undefined)
28523
- persistent = true;
28524
- if (recursive === undefined)
28525
- recursive = false;
28526
- var watcher = new this.FSWatcher();
28527
- watcher.start(filename, persistent, recursive, encoding);
28528
- if (listener) {
28529
- watcher.addListener('change', listener);
28530
- }
28531
- return watcher;
28532
- };
28533
- /**
28534
- * Global file descriptor counter. UNIX file descriptors start from 0 and go sequentially
28535
- * up, so here, in order not to conflict with them, we choose some big number and descrease
28536
- * the file descriptor of every new opened file.
28537
- * @type {number}
28538
- * @todo This should not be static, right?
28539
- */
28540
- Volume.fd = 0x7fffffff;
28541
- return Volume;
28542
- }());
28543
- exports.Volume = Volume;
28544
- function emitStop(self) {
28545
- self.emit('stop');
28546
- }
28547
- var StatWatcher = /** @class */ (function (_super) {
28548
- __extends(StatWatcher, _super);
28549
- function StatWatcher(vol) {
28550
- var _this = _super.call(this) || this;
28551
- _this.onInterval = function () {
28552
- try {
28553
- var stats = _this.vol.statSync(_this.filename);
28554
- if (_this.hasChanged(stats)) {
28555
- _this.emit('change', stats, _this.prev);
28556
- _this.prev = stats;
28557
- }
28558
- }
28559
- finally {
28560
- _this.loop();
28561
- }
28562
- };
28563
- _this.vol = vol;
28564
- return _this;
28565
- }
28566
- StatWatcher.prototype.loop = function () {
28567
- this.timeoutRef = this.setTimeout(this.onInterval, this.interval);
28568
- };
28569
- StatWatcher.prototype.hasChanged = function (stats) {
28570
- // if(!this.prev) return false;
28571
- if (stats.mtimeMs > this.prev.mtimeMs)
28572
- return true;
28573
- if (stats.nlink !== this.prev.nlink)
28574
- return true;
28575
- return false;
28576
- };
28577
- StatWatcher.prototype.start = function (path, persistent, interval) {
28578
- if (persistent === void 0) { persistent = true; }
28579
- if (interval === void 0) { interval = 5007; }
28580
- this.filename = pathToFilename(path);
28581
- this.setTimeout = persistent
28582
- ? setTimeout.bind(typeof globalThis !== 'undefined' ? globalThis : global)
28583
- : setTimeoutUnref_1.default;
28584
- this.interval = interval;
28585
- this.prev = this.vol.statSync(this.filename);
28586
- this.loop();
28587
- };
28588
- StatWatcher.prototype.stop = function () {
28589
- clearTimeout(this.timeoutRef);
28590
- process_1.default.nextTick(emitStop, this);
28591
- };
28592
- return StatWatcher;
28593
- }(events_1.EventEmitter));
28594
- exports.StatWatcher = StatWatcher;
28595
- var pool;
28596
- function allocNewPool(poolSize) {
28597
- pool = (0, buffer_1.bufferAllocUnsafe)(poolSize);
28598
- pool.used = 0;
28599
- }
28600
- util.inherits(FsReadStream, stream_1.Readable);
28601
- exports.ReadStream = FsReadStream;
28602
- function FsReadStream(vol, path, options) {
28603
- if (!(this instanceof FsReadStream))
28604
- return new FsReadStream(vol, path, options);
28605
- this._vol = vol;
28606
- // a little bit bigger buffer and water marks by default
28607
- options = Object.assign({}, getOptions(options, {}));
28608
- if (options.highWaterMark === undefined)
28609
- options.highWaterMark = 64 * 1024;
28610
- stream_1.Readable.call(this, options);
28611
- this.path = pathToFilename(path);
28612
- this.fd = options.fd === undefined ? null : options.fd;
28613
- this.flags = options.flags === undefined ? 'r' : options.flags;
28614
- this.mode = options.mode === undefined ? 438 : options.mode;
28615
- this.start = options.start;
28616
- this.end = options.end;
28617
- this.autoClose = options.autoClose === undefined ? true : options.autoClose;
28618
- this.pos = undefined;
28619
- this.bytesRead = 0;
28620
- if (this.start !== undefined) {
28621
- if (typeof this.start !== 'number') {
28622
- throw new TypeError('"start" option must be a Number');
28623
- }
28624
- if (this.end === undefined) {
28625
- this.end = Infinity;
28626
- }
28627
- else if (typeof this.end !== 'number') {
28628
- throw new TypeError('"end" option must be a Number');
28629
- }
28630
- if (this.start > this.end) {
28631
- throw new Error('"start" option must be <= "end" option');
28632
- }
28633
- this.pos = this.start;
28634
- }
28635
- if (typeof this.fd !== 'number')
28636
- this.open();
28637
- this.on('end', function () {
28638
- if (this.autoClose) {
28639
- if (this.destroy)
28640
- this.destroy();
28641
- }
28642
- });
28643
- }
28644
- FsReadStream.prototype.open = function () {
28645
- var self = this; // tslint:disable-line no-this-assignment
28646
- this._vol.open(this.path, this.flags, this.mode, function (er, fd) {
28647
- if (er) {
28648
- if (self.autoClose) {
28649
- if (self.destroy)
28650
- self.destroy();
28651
- }
28652
- self.emit('error', er);
28653
- return;
28654
- }
28655
- self.fd = fd;
28656
- self.emit('open', fd);
28657
- // start the flow of data.
28658
- self.read();
28659
- });
28660
- };
28661
- FsReadStream.prototype._read = function (n) {
28662
- if (typeof this.fd !== 'number') {
28663
- return this.once('open', function () {
28664
- this._read(n);
28665
- });
28666
- }
28667
- if (this.destroyed)
28668
- return;
28669
- if (!pool || pool.length - pool.used < kMinPoolSpace) {
28670
- // discard the old pool.
28671
- allocNewPool(this._readableState.highWaterMark);
28672
- }
28673
- // Grab another reference to the pool in the case that while we're
28674
- // in the thread pool another read() finishes up the pool, and
28675
- // allocates a new one.
28676
- var thisPool = pool;
28677
- var toRead = Math.min(pool.length - pool.used, n);
28678
- var start = pool.used;
28679
- if (this.pos !== undefined)
28680
- toRead = Math.min(this.end - this.pos + 1, toRead);
28681
- // already read everything we were supposed to read!
28682
- // treat as EOF.
28683
- if (toRead <= 0)
28684
- return this.push(null);
28685
- // the actual read.
28686
- var self = this; // tslint:disable-line no-this-assignment
28687
- this._vol.read(this.fd, pool, pool.used, toRead, this.pos, onread);
28688
- // move the pool positions, and internal position for reading.
28689
- if (this.pos !== undefined)
28690
- this.pos += toRead;
28691
- pool.used += toRead;
28692
- function onread(er, bytesRead) {
28693
- if (er) {
28694
- if (self.autoClose && self.destroy) {
28695
- self.destroy();
28696
- }
28697
- self.emit('error', er);
28698
- }
28699
- else {
28700
- var b = null;
28701
- if (bytesRead > 0) {
28702
- self.bytesRead += bytesRead;
28703
- b = thisPool.slice(start, start + bytesRead);
28704
- }
28705
- self.push(b);
28706
- }
28707
- }
28708
- };
28709
- FsReadStream.prototype._destroy = function (err, cb) {
28710
- this.close(function (err2) {
28711
- cb(err || err2);
28712
- });
28713
- };
28714
- FsReadStream.prototype.close = function (cb) {
28715
- var _this = this;
28716
- var _a;
28717
- if (cb)
28718
- this.once('close', cb);
28719
- if (this.closed || typeof this.fd !== 'number') {
28720
- if (typeof this.fd !== 'number') {
28721
- this.once('open', closeOnOpen);
28722
- return;
28723
- }
28724
- return process_1.default.nextTick(function () { return _this.emit('close'); });
28725
- }
28726
- // Since Node 18, there is only a getter for '.closed'.
28727
- // The first branch mimics other setters from Readable.
28728
- // See https://github.com/nodejs/node/blob/v18.0.0/lib/internal/streams/readable.js#L1243
28729
- if (typeof ((_a = this._readableState) === null || _a === void 0 ? void 0 : _a.closed) === 'boolean') {
28730
- this._readableState.closed = true;
28731
- }
28732
- else {
28733
- this.closed = true;
28734
- }
28735
- this._vol.close(this.fd, function (er) {
28736
- if (er)
28737
- _this.emit('error', er);
28738
- else
28739
- _this.emit('close');
28740
- });
28741
- this.fd = null;
28742
- };
28743
- // needed because as it will be called with arguments
28744
- // that does not match this.close() signature
28745
- function closeOnOpen(fd) {
28746
- this.close();
28747
- }
28748
- util.inherits(FsWriteStream, stream_1.Writable);
28749
- exports.WriteStream = FsWriteStream;
28750
- function FsWriteStream(vol, path, options) {
28751
- if (!(this instanceof FsWriteStream))
28752
- return new FsWriteStream(vol, path, options);
28753
- this._vol = vol;
28754
- options = Object.assign({}, getOptions(options, {}));
28755
- stream_1.Writable.call(this, options);
28756
- this.path = pathToFilename(path);
28757
- this.fd = options.fd === undefined ? null : options.fd;
28758
- this.flags = options.flags === undefined ? 'w' : options.flags;
28759
- this.mode = options.mode === undefined ? 438 : options.mode;
28760
- this.start = options.start;
28761
- this.autoClose = options.autoClose === undefined ? true : !!options.autoClose;
28762
- this.pos = undefined;
28763
- this.bytesWritten = 0;
28764
- if (this.start !== undefined) {
28765
- if (typeof this.start !== 'number') {
28766
- throw new TypeError('"start" option must be a Number');
28767
- }
28768
- if (this.start < 0) {
28769
- throw new Error('"start" must be >= zero');
28770
- }
28771
- this.pos = this.start;
28772
- }
28773
- if (options.encoding)
28774
- this.setDefaultEncoding(options.encoding);
28775
- if (typeof this.fd !== 'number')
28776
- this.open();
28777
- // dispose on finish.
28778
- this.once('finish', function () {
28779
- if (this.autoClose) {
28780
- this.close();
28781
- }
28782
- });
28783
- }
28784
- FsWriteStream.prototype.open = function () {
28785
- this._vol.open(this.path, this.flags, this.mode, function (er, fd) {
28786
- if (er) {
28787
- if (this.autoClose && this.destroy) {
28788
- this.destroy();
28789
- }
28790
- this.emit('error', er);
28791
- return;
28792
- }
28793
- this.fd = fd;
28794
- this.emit('open', fd);
28795
- }.bind(this));
28796
- };
28797
- FsWriteStream.prototype._write = function (data, encoding, cb) {
28798
- if (!(data instanceof buffer_1.Buffer || data instanceof Uint8Array))
28799
- return this.emit('error', new Error('Invalid data'));
28800
- if (typeof this.fd !== 'number') {
28801
- return this.once('open', function () {
28802
- this._write(data, encoding, cb);
28803
- });
28804
- }
28805
- var self = this; // tslint:disable-line no-this-assignment
28806
- this._vol.write(this.fd, data, 0, data.length, this.pos, function (er, bytes) {
28807
- if (er) {
28808
- if (self.autoClose && self.destroy) {
28809
- self.destroy();
28810
- }
28811
- return cb(er);
28812
- }
28813
- self.bytesWritten += bytes;
28814
- cb();
28815
- });
28816
- if (this.pos !== undefined)
28817
- this.pos += data.length;
28818
- };
28819
- FsWriteStream.prototype._writev = function (data, cb) {
28820
- if (typeof this.fd !== 'number') {
28821
- return this.once('open', function () {
28822
- this._writev(data, cb);
28823
- });
28824
- }
28825
- var self = this; // tslint:disable-line no-this-assignment
28826
- var len = data.length;
28827
- var chunks = new Array(len);
28828
- var size = 0;
28829
- for (var i = 0; i < len; i++) {
28830
- var chunk = data[i].chunk;
28831
- chunks[i] = chunk;
28832
- size += chunk.length;
28833
- }
28834
- var buf = buffer_1.Buffer.concat(chunks);
28835
- this._vol.write(this.fd, buf, 0, buf.length, this.pos, function (er, bytes) {
28836
- if (er) {
28837
- if (self.destroy)
28838
- self.destroy();
28839
- return cb(er);
28840
- }
28841
- self.bytesWritten += bytes;
28842
- cb();
28843
- });
28844
- if (this.pos !== undefined)
28845
- this.pos += size;
28846
- };
28847
- FsWriteStream.prototype.close = function (cb) {
28848
- var _this = this;
28849
- var _a;
28850
- if (cb)
28851
- this.once('close', cb);
28852
- if (this.closed || typeof this.fd !== 'number') {
28853
- if (typeof this.fd !== 'number') {
28854
- this.once('open', closeOnOpen);
28855
- return;
28856
- }
28857
- return process_1.default.nextTick(function () { return _this.emit('close'); });
28858
- }
28859
- // Since Node 18, there is only a getter for '.closed'.
28860
- // The first branch mimics other setters from Writable.
28861
- // See https://github.com/nodejs/node/blob/v18.0.0/lib/internal/streams/writable.js#L766
28862
- if (typeof ((_a = this._writableState) === null || _a === void 0 ? void 0 : _a.closed) === 'boolean') {
28863
- this._writableState.closed = true;
28864
- }
28865
- else {
28866
- this.closed = true;
28867
- }
28868
- this._vol.close(this.fd, function (er) {
28869
- if (er)
28870
- _this.emit('error', er);
28871
- else
28872
- _this.emit('close');
28873
- });
28874
- this.fd = null;
28875
- };
28876
- FsWriteStream.prototype._destroy = FsReadStream.prototype._destroy;
28877
- // There is no shutdown() for files.
28878
- FsWriteStream.prototype.destroySoon = FsWriteStream.prototype.end;
28879
- // ---------------------------------------- FSWatcher
28880
- var FSWatcher = /** @class */ (function (_super) {
28881
- __extends(FSWatcher, _super);
28882
- function FSWatcher(vol) {
28883
- var _this = _super.call(this) || this;
28884
- _this._filename = '';
28885
- _this._filenameEncoded = '';
28886
- // _persistent: boolean = true;
28887
- _this._recursive = false;
28888
- _this._encoding = encoding_1.ENCODING_UTF8;
28889
- _this._onNodeChange = function () {
28890
- _this._emit('change');
28891
- };
28892
- _this._onParentChild = function (link) {
28893
- if (link.getName() === _this._getName()) {
28894
- _this._emit('rename');
28895
- }
28896
- };
28897
- _this._emit = function (type) {
28898
- _this.emit('change', type, _this._filenameEncoded);
28899
- };
28900
- _this._persist = function () {
28901
- _this._timer = setTimeout(_this._persist, 1e6);
28902
- };
28903
- _this._vol = vol;
28904
- return _this;
28905
- // TODO: Emit "error" messages when watching.
28906
- // this._handle.onchange = function(status, eventType, filename) {
28907
- // if (status < 0) {
28908
- // self._handle.close();
28909
- // const error = !filename ?
28910
- // errnoException(status, 'Error watching file for changes:') :
28911
- // errnoException(status, `Error watching file ${filename} for changes:`);
28912
- // error.filename = filename;
28913
- // self.emit('error', error);
28914
- // } else {
28915
- // self.emit('change', eventType, filename);
28916
- // }
28917
- // };
28918
- }
28919
- FSWatcher.prototype._getName = function () {
28920
- return this._steps[this._steps.length - 1];
28921
- };
28922
- FSWatcher.prototype.start = function (path, persistent, recursive, encoding) {
28923
- if (persistent === void 0) { persistent = true; }
28924
- if (recursive === void 0) { recursive = false; }
28925
- if (encoding === void 0) { encoding = encoding_1.ENCODING_UTF8; }
28926
- this._filename = pathToFilename(path);
28927
- this._steps = filenameToSteps(this._filename);
28928
- this._filenameEncoded = (0, encoding_1.strToEncoding)(this._filename);
28929
- // this._persistent = persistent;
28930
- this._recursive = recursive;
28931
- this._encoding = encoding;
28932
- try {
28933
- this._link = this._vol.getLinkOrThrow(this._filename, 'FSWatcher');
28934
- }
28935
- catch (err) {
28936
- var error = new Error("watch ".concat(this._filename, " ").concat(err.code));
28937
- error.code = err.code;
28938
- error.errno = err.code;
28939
- throw error;
28940
- }
28941
- this._link.getNode().on('change', this._onNodeChange);
28942
- this._link.on('child:add', this._onNodeChange);
28943
- this._link.on('child:delete', this._onNodeChange);
28944
- var parent = this._link.parent;
28945
- if (parent) {
28946
- // parent.on('child:add', this._onParentChild);
28947
- parent.setMaxListeners(parent.getMaxListeners() + 1);
28948
- parent.on('child:delete', this._onParentChild);
28949
- }
28950
- if (persistent)
28951
- this._persist();
28952
- };
28953
- FSWatcher.prototype.close = function () {
28954
- clearTimeout(this._timer);
28955
- this._link.getNode().removeListener('change', this._onNodeChange);
28956
- var parent = this._link.parent;
28957
- if (parent) {
28958
- // parent.removeListener('child:add', this._onParentChild);
28959
- parent.removeListener('child:delete', this._onParentChild);
28960
- }
28961
- };
28962
- return FSWatcher;
28963
- }(events_1.EventEmitter));
28964
- exports.FSWatcher = FSWatcher;
28965
-
28966
-
28967
25317
  /***/ }),
28968
25318
 
28969
25319
  /***/ 83349: