All files / src/fsa-to-node FsaNodeFs.ts

72.38% Statements 456/630
66.87% Branches 105/157
63.19% Functions 91/144
73.46% Lines 432/588

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 11092x 2x 2x 2x 2x 2x 2x   2x   2x 2x 2x   2x 2x 2x 2x               2x       2x       2x           2x     299x       299x           293x 293x 293x 6x 6x   293x 293x 293x 293x 293x 253x 40x       299x 254x 254x 254x         299x               2x   2x         2x 2x 2x 2x 2x 2x 2x 2x   2x         299x         75x     75x 75x 75x 75x 75x 75x 72x 72x   71x 70x 70x 70x   75x 75x 75x       70x 5x     299x               241x 241x 241x 241x 241x 241x   241x         299x           1x 1x   1x 1x         1x 1x 1x 1x 1x 1x 2x 2x 2x 2x   1x   1x         299x           280x 280x 280x 1x 1x   280x 280x 280x 280x 280x 280x 280x 280x 280x 280x 280x 280x   274x 274x 274x 274x   280x 280x 280x       274x 6x       299x 41x 41x     41x 1x 1x   40x 40x   41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x   41x                 299x 53x 53x 53x 53x   47x   6x 6x   5x 5x     1x 1x                 299x         1x 1x 1x 1x     299x         1515x 1515x 1515x 1515x 1515x 972x   972x 543x       299x   299x         7x 7x 7x 5x   5x 2x         977x 977x 232x 232x 232x   977x 977x             299x         239x 239x 239x 239x 239x 239x 239x 239x 239x 239x 239x 239x 239x 239x   239x         299x       8x 8x 8x     299x         18x   18x 18x 18x       18x 18x 18x 18x 15x 15x 13x 13x   6x 2x 2x 2x 1x   1x     5x     7x 2x 2x 2x   6x             11x 7x       299x 5x 5x 5x   5x 5x 5x 5x         5x       5x         299x 20x 20x 20x 20x 20x   20x 20x 13x 91x 39x 39x   13x 13x 26x 26x     13x   7x   49x   7x   7x         20x         299x                       299x       299x       299x         2x 2x 2x 2x 2x   2x         299x         1x 1x 1x 1x   1x 1x 1x           299x                 299x                 299x         221x 221x   221x 221x   221x 219x   219x   2x 2x               2x         299x         1x 1x 1x 1x 1x 1x 1x         2x 2x 10x 4x     2x         299x         28x 28x 28x 28x 27x 27x 27x   26x   1x 1x             1x 1x 1x                 299x         7x 7x 7x 6x 4x   3x   3x 1x 1x   2x 2x             1x 1x 1x       1x         299x               299x               299x               299x                 299x                 299x                 299x       14x           14x 14x 14x 14x 14x 14x 12x 11x 10x   11x       12x     299x       6x                       6x 6x 6x 6x 6x 6x 6x     299x 299x 299x 299x 299x 299x             299x 299x 299x   299x 299x       299x                         299x   299x         299x                   299x                         299x                           299x                         299x               299x                 299x                     299x                   299x           299x           299x                   299x                     299x                   299x           299x         299x         299x                                           299x       1x 1x 1x 1x     299x                               299x                         299x                           299x                       299x 299x 299x 299x 299x 299x 299x 299x 299x 299x 299x   299x 299x 299x 299x   299x 299x       299x 299x 299x 299x 299x 299x 299x 299x 299x   299x 299x 299x 299x    
import * as optHelpers from '../node/options';
import * as util from '../node/util';
import { Buffer } from '../internal/buffer';
import { FsPromises } from '../node/FsPromises';
import { pathToLocation, testDirectoryIsWritable } from './util';
import { ERRSTR, MODE } from '../node/constants';
import { strToEncoding } from '../encoding';
import { FsaToNodeConstants } from './constants';
import { FsaNodeDirent } from './FsaNodeDirent';
import { AMODE } from '../consts/AMODE';
import { constants } from '../constants';
import { FsaNodeStats } from './FsaNodeStats';
import queueMicrotask from '../queueMicrotask';
import { FsSynchronousApi } from '../node/types/FsSynchronousApi';
import { FsaNodeWriteStream } from './FsaNodeWriteStream';
import { FsaNodeReadStream } from './FsaNodeReadStream';
import { FsaNodeCore } from './FsaNodeCore';
import { FileHandle } from '../node/FileHandle';
import type { FsCallbackApi, FsPromisesApi } from '../node/types';
import type * as misc from '../node/types/misc';
import type * as opts from '../node/types/options';
import type * as fsa from '../fsa/types';
import type { FsCommonObjects } from '../node/types/FsCommonObjects';
import type { WritevCallback } from '../node/types/FsCallbackApi';
 
const notSupported: (...args: any[]) => any = () => {
  throw new Error('Method not supported by the File System Access API.');
};
 
const notImplemented: (...args: any[]) => any = () => {
  throw new Error('Not implemented');
};
 
const noop: (...args: any[]) => any = () => {};
 
/**
 * Constructs a Node.js `fs` API from a File System Access API
 * [`FileSystemDirectoryHandle` object](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle).
 */
export class FsaNodeFs extends FsaNodeCore implements FsCallbackApi, FsSynchronousApi, FsCommonObjects {
  // ------------------------------------------------------------ FsPromisesApi
 
  public readonly promises: FsPromisesApi = new FsPromises(this, FileHandle);
 
  // ------------------------------------------------------------ FsCallbackApi
 
  public readonly open: FsCallbackApi['open'] = (
    path: misc.PathLike,
    flags: misc.TFlags,
    a?: misc.TMode | misc.TCallback<number>,
    b?: misc.TCallback<number> | string,
  ) => {
    let mode: misc.TMode = a as misc.TMode;
    let callback: misc.TCallback<number> = b as misc.TCallback<number>;
    if (typeof a === 'function') {
      mode = MODE.DEFAULT;
      callback = a;
    }
    mode = mode || MODE.DEFAULT;
    const modeNum = util.modeToNumber(mode);
    const filename = util.pathToFilename(path);
    const flagsNum = util.flagsToNumber(flags);
    this.__open(filename, flagsNum, modeNum).then(
      openFile => callback(null, openFile.fd),
      error => callback(error),
    );
  };
 
  public readonly close: FsCallbackApi['close'] = (fd: number, callback: misc.TCallback<void>): void => {
    util.validateFd(fd);
    this.__close(fd).then(
      () => callback(null),
      error => callback(error),
    );
  };
 
  public readonly read: FsCallbackApi['read'] = (
    fd: number,
    buffer: Buffer | ArrayBufferView | DataView,
    offset: number,
    length: number,
    position: number,
    callback: (err?: Error | null, bytesRead?: number, buffer?: Buffer | ArrayBufferView | DataView) => void,
  ): void => {
    util.validateCallback(callback);
    // This `if` branch is from Node.js
    Iif (length === 0) {
      return queueMicrotask(() => {
        Iif (callback) callback(null, 0, buffer);
      });
    }
    (async () => {
      const openFile = await this.getFileByFd(fd, 'read');
      const file = await openFile.file.getFile();
      const src = await file.arrayBuffer();
      const slice = new Uint8Array(src, Number(position), Number(length));
      const dest = new Uint8Array(buffer.buffer, buffer.byteOffset + offset, slice.length);
      dest.set(slice, 0);
      return slice.length;
    })().then(
      bytesWritten => callback(null, bytesWritten, buffer),
      error => callback(error),
    );
  };
 
  public readonly readFile: FsCallbackApi['readFile'] = (
    id: misc.TFileId,
    a?: opts.IReadFileOptions | string | misc.TCallback<misc.TDataOut>,
    b?: misc.TCallback<misc.TDataOut>,
  ) => {
    const [opts, callback] = optHelpers.optsAndCbGenerator<opts.IReadFileOptions, misc.TDataOut>(
      optHelpers.getReadFileOptions,
    )(a, b);
    const flagsNum = util.flagsToNumber(opts.flag);
    (async () => {
      let fd: number = typeof id === 'number' ? id : -1;
      const originalFd = fd;
      try {
        if (fd === -1) {
          const filename = util.pathToFilename(id as misc.PathLike);
          fd = (await this.__open(filename, flagsNum, 0)).fd;
        }
        const handle = await this.__getFileById(fd, 'readFile');
        const file = await handle.getFile();
        const buffer = Buffer.from(await file.arrayBuffer());
        return util.bufferToEncoding(buffer, opts.encoding);
      } finally {
        try {
          const idWasFd = typeof originalFd === 'number' && originalFd >= 0;
          if (idWasFd) await this.__close(originalFd);
        } catch {}
      }
    })()
      .then(data => callback(null, data))
      .catch(error => callback(error));
  };
 
  public readonly write: FsCallbackApi['write'] = (
    fd: number,
    a?: unknown,
    b?: unknown,
    c?: unknown,
    d?: unknown,
    e?: unknown,
  ) => {
    const [, asStr, buf, offset, length, position, cb] = util.getWriteArgs(fd, a, b, c, d, e);
    (async () => {
      const openFile = await this.getFileByFd(fd, 'write');
      const data = buf.subarray(offset, offset + length);
      await openFile.write(data, position);
      return length;
    })().then(
      bytesWritten => cb(null, bytesWritten, asStr ? a : buf),
      error => cb(error),
    );
  };
 
  public readonly writev: FsCallbackApi['writev'] = (
    fd: number,
    buffers: ArrayBufferView[],
    a: number | null | WritevCallback,
    b?: WritevCallback,
  ): void => {
    util.validateFd(fd);
    let position: number | null = null;
    let callback: WritevCallback;
    if (typeof a === 'function') {
      callback = a;
    } else E{
      position = Number(a);
      callback = <WritevCallback>b;
    }
    util.validateCallback(callback);
    (async () => {
      const openFile = await this.getFileByFd(fd, 'writev');
      const length = buffers.length;
      let bytesWritten = 0;
      for (let i = 0; i < length; i++) {
        const data = buffers[i];
        await openFile.write(data, position);
        bytesWritten += data.byteLength;
        position = null;
      }
      return bytesWritten;
    })().then(
      bytesWritten => callback(null, bytesWritten, buffers),
      error => callback(error),
    );
  };
 
  public readonly writeFile: FsCallbackApi['writeFile'] = (
    id: misc.TFileId,
    data: misc.TData,
    a: misc.TCallback<void> | opts.IWriteFileOptions | string,
    b?: misc.TCallback<void>,
  ): void => {
    let options: opts.IWriteFileOptions | string = a as opts.IWriteFileOptions;
    let callback: misc.TCallback<void> | undefined = b;
    if (typeof a === 'function') {
      options = optHelpers.writeFileDefaults;
      callback = a;
    }
    const cb = util.validateCallback(callback);
    const opts = optHelpers.getWriteFileOptions(options);
    const flagsNum = util.flagsToNumber(opts.flag);
    const modeNum = util.modeToNumber(opts.mode);
    const buf = util.dataToBuffer(data, opts.encoding);
    (async () => {
      let fd: number = typeof id === 'number' ? id : -1;
      const originalFd = fd;
      try {
        if (fd === -1) {
          const filename = util.pathToFilename(id as misc.PathLike);
          fd = (await this.__open(filename, flagsNum, modeNum)).fd;
        }
        const file = await this.__getFileById(fd, 'writeFile');
        const writable = await file.createWritable({ keepExistingData: false });
        await writable.write(buf);
        await writable.close();
      } finally {
        try {
          const idWasFd = typeof originalFd === 'number' && originalFd >= 0;
          Iif (idWasFd) await this.__close(originalFd);
        } catch {}
      }
    })().then(
      () => cb(null),
      error => cb(error),
    );
  };
 
  public readonly copyFile: FsCallbackApi['copyFile'] = (src: misc.PathLike, dest: misc.PathLike, a, b?): void => {
    const srcFilename = util.pathToFilename(src);
    const destFilename = util.pathToFilename(dest);
    let flags: misc.TFlagsCopy;
    let callback: misc.TCallback<void>;
    if (typeof a === 'function') {
      flags = 0;
      callback = a;
    } else {
      flags = a;
      callback = b;
    }
    util.validateCallback(callback);
    const [oldFolder, oldName] = pathToLocation(srcFilename);
    const [newFolder, newName] = pathToLocation(destFilename);
    (async () => {
      const oldFile = await this.getFile(oldFolder, oldName, 'copyFile');
      const newDir = await this.getDir(newFolder, false, 'copyFile');
      const newFile = await newDir.getFileHandle(newName, { create: true });
      const writable = await newFile.createWritable({ keepExistingData: false });
      const oldData = await oldFile.getFile();
      await writable.write(await oldData.arrayBuffer());
      await writable.close();
    })().then(
      () => callback(null),
      error => callback(error),
    );
  };
 
  /**
   * @todo There is a proposal for native "self remove" operation.
   * @see https://github.com/whatwg/fs/blob/main/proposals/Remove.md
   */
  public readonly unlink: FsCallbackApi['unlink'] = (path: misc.PathLike, callback: misc.TCallback<void>): void => {
    const filename = util.pathToFilename(path);
    const [folder, name] = pathToLocation(filename);
    this.getDir(folder, false, 'unlink')
      .then(dir => dir.removeEntry(name))
      .then(
        () => callback(null),
        error => {
          if (error && typeof error === 'object') {
            switch (error.name) {
              case 'NotFoundError': {
                callback(util.createError('ENOENT', 'unlink', filename));
                return;
              }
              case 'InvalidModificationError': {
                callback(util.createError('EISDIR', 'unlink', filename));
                return;
              }
            }
          }
          callback(error);
        },
      );
  };
 
  public readonly realpath: FsCallbackApi['realpath'] = (
    path: misc.PathLike,
    a: misc.TCallback<misc.TDataOut> | opts.IRealpathOptions | string,
    b?: misc.TCallback<misc.TDataOut>,
  ): void => {
    const [opts, callback] = optHelpers.getRealpathOptsAndCb(a, b);
    let pathFilename = util.pathToFilename(path);
    if (pathFilename[0] !== FsaToNodeConstants.Separator) pathFilename = FsaToNodeConstants.Separator + pathFilename;
    callback(null, strToEncoding(pathFilename, opts.encoding));
  };
 
  public readonly stat: FsCallbackApi['stat'] = (
    path: misc.PathLike,
    a: misc.TCallback<misc.IStats> | opts.IStatOptions,
    b?: misc.TCallback<misc.IStats>,
  ): void => {
    const [{ bigint = false, throwIfNoEntry = true }, callback] = optHelpers.getStatOptsAndCb(a, b);
    const filename = util.pathToFilename(path);
    const [folder, name] = pathToLocation(filename);
    (async () => {
      const handle = await this.getFileOrDir(folder, name, 'stat');
      return await this.getHandleStats(bigint, handle);
    })().then(
      stats => callback(null, stats),
      error => callback(error),
    );
  };
 
  public readonly lstat: FsCallbackApi['lstat'] = this.stat;
 
  public readonly fstat: FsCallbackApi['fstat'] = (
    fd: number,
    a: misc.TCallback<misc.IStats> | opts.IStatOptions,
    b?: misc.TCallback<misc.IStats>,
  ): void => {
    const [{ bigint = false, throwIfNoEntry = true }, callback] = optHelpers.getStatOptsAndCb(a, b);
    (async () => {
      const openFile = await this.getFileByFd(fd, 'fstat');
      return await this.getHandleStats(bigint, openFile.file);
    })().then(
      stats => callback(null, stats),
      error => callback(error),
    );
  };
 
  private async getHandleStats(bigint: boolean, handle: fsa.IFileSystemHandle): Promise<misc.IStats> {
    let size: number = 0;
    if (handle.kind === 'file') {
      const file = <fsa.IFileSystemFileHandle>handle;
      const fileData = await file.getFile();
      size = fileData.size;
    }
    const stats = new FsaNodeStats(bigint, bigint ? BigInt(size) : size, handle.kind);
    return stats;
  }
 
  /**
   * @todo There is a proposal for native move support.
   * @see https://github.com/whatwg/fs/blob/main/proposals/MovingNonOpfsFiles.md
   */
  public readonly rename: FsCallbackApi['rename'] = (
    oldPath: misc.PathLike,
    newPath: misc.PathLike,
    callback: misc.TCallback<void>,
  ): void => {
    const oldPathFilename = util.pathToFilename(oldPath);
    const newPathFilename = util.pathToFilename(newPath);
    const [oldFolder, oldName] = pathToLocation(oldPathFilename);
    const [newFolder, newName] = pathToLocation(newPathFilename);
    (async () => {
      const oldFile = await this.getFile(oldFolder, oldName, 'rename');
      const newDir = await this.getDir(newFolder, false, 'rename');
      const newFile = await newDir.getFileHandle(newName, { create: true });
      const writable = await newFile.createWritable({ keepExistingData: false });
      const oldData = await oldFile.getFile();
      await writable.write(await oldData.arrayBuffer());
      await writable.close();
      const oldDir = await this.getDir(oldFolder, false, 'rename');
      await oldDir.removeEntry(oldName);
    })().then(
      () => callback(null),
      error => callback(error),
    );
  };
 
  public readonly exists: FsCallbackApi['exists'] = (
    path: misc.PathLike,
    callback: (exists: boolean) => void,
  ): void => {
    const filename = util.pathToFilename(path);
    Iif (typeof callback !== 'function') throw Error(ERRSTR.CB);
    this.access(path, AMODE.F_OK, error => callback(!error));
  };
 
  public readonly access: FsCallbackApi['access'] = (
    path: misc.PathLike,
    a: misc.TCallback<void> | number,
    b?: misc.TCallback<void>,
  ) => {
    let mode: number = AMODE.F_OK;
    let callback: misc.TCallback<void>;
    if (typeof a !== 'function') {
      mode = a | 0; // cast to number
      callback = util.validateCallback(b);
    } else E{
      callback = a;
    }
    const filename = util.pathToFilename(path);
    const [folder, name] = pathToLocation(filename);
    (async () => {
      const node = folder.length || name ? await this.getFileOrDir(folder, name, 'access') : await this.root;
      const checkIfCanExecute = mode & AMODE.X_OK;
      if (checkIfCanExecute) throw util.createError('EACCESS', 'access', filename);
      const checkIfCanWrite = mode & AMODE.W_OK;
      switch (node.kind) {
        case 'file': {
          if (checkIfCanWrite) {
            try {
              const file = node as fsa.IFileSystemFileHandle;
              const writable = await file.createWritable();
              await writable.close();
            } catch {
              throw util.createError('EACCESS', 'access', filename);
            }
          }
          break;
        }
        case 'directory': {
          if (checkIfCanWrite) {
            const dir = node as fsa.IFileSystemDirectoryHandle;
            const canWrite = await testDirectoryIsWritable(dir);
            if (!canWrite) throw util.createError('EACCESS', 'access', filename);
          }
          break;
        }
        default: {
          throw util.createError('EACCESS', 'access', filename);
        }
      }
    })().then(
      () => callback(null),
      error => callback(error),
    );
  };
 
  public readonly appendFile: FsCallbackApi['appendFile'] = (id: misc.TFileId, data: misc.TData, a, b?) => {
    const [opts, callback] = optHelpers.getAppendFileOptsAndCb(a, b);
    const buffer = util.dataToBuffer(data, opts.encoding);
    this.getFileByIdOrCreate(id, 'appendFile')
      .then(file =>
        (async () => {
          const blob = await file.getFile();
          const writable = await file.createWritable({ keepExistingData: true });
          await writable.write({
            type: 'write',
            data: buffer,
            position: blob.size,
          });
          await writable.close();
        })(),
      )
      .then(
        () => callback(null),
        error => callback(error),
      );
  };
 
  public readonly readdir: FsCallbackApi['readdir'] = (path: misc.PathLike, a?, b?) => {
    const [options, callback] = optHelpers.getReaddirOptsAndCb(a, b);
    const filename = util.pathToFilename(path);
    const [folder, name] = pathToLocation(filename);
    Iif (name) folder.push(name);
    this.getDir(folder, false, 'readdir')
      .then(dir =>
        (async () => {
          if (options.withFileTypes) {
            const list: misc.IDirent[] = [];
            for await (const [name, handle] of dir.entries()) {
              const dirent = new FsaNodeDirent(name, handle.kind);
              list.push(dirent);
            }
            if (!util.isWin && options.encoding !== 'buffer')
              list.sort((a, b) => {
                Iif (a.name < b.name) return -1;
                if (a.name > b.name) return 1;
                return 0;
              });
            return list;
          } else {
            const list: string[] = [];
 
            for await (const key of dir.keys()) list.push(key);
 
            if (!util.isWin && options.encoding !== 'buffer') list.sort();
 
            return list;
          }
        })(),
      )
      .then(
        res => callback(null, res),
        err => callback(err),
      );
  };
 
  public readonly readlink: FsCallbackApi['readlink'] = (
    path: misc.PathLike,
    a: misc.TCallback<misc.TDataOut> | opts.IOptions,
    b?: misc.TCallback<misc.TDataOut>,
  ) => {
    const [opts, callback] = optHelpers.getDefaultOptsAndCb(a, b);
    const filename = util.pathToFilename(path);
    const buffer = Buffer.from(filename);
    callback(null, util.bufferToEncoding(buffer, opts.encoding));
  };
 
  /** @todo Could this use `FileSystemSyncAccessHandle.flush` through a Worker thread? */
  public readonly fsync: FsCallbackApi['fsync'] = (fd: number, callback: misc.TCallback<void>): void => {
    callback(null);
  };
 
  public readonly fdatasync: FsCallbackApi['fdatasync'] = (fd: number, callback: misc.TCallback<void>): void => {
    callback(null);
  };
 
  public readonly ftruncate: FsCallbackApi['ftruncate'] = (
    fd: number,
    a: misc.TCallback<void> | number,
    b?: misc.TCallback<void>,
  ): void => {
    const len: number = typeof a === 'number' ? a : 0;
    const callback: misc.TCallback<void> = util.validateCallback(typeof a === 'number' ? b : a);
    this.getFileByFdAsync(fd)
      .then(file => file.file.createWritable({ keepExistingData: true }))
      .then(writable => writable.truncate(len).then(() => writable.close()))
      .then(
        () => callback(null),
        error => callback(error),
      );
  };
 
  public readonly truncate: FsCallbackApi['truncate'] = (
    path: misc.PathLike,
    a: misc.TCallback<void> | number,
    b?: misc.TCallback<void>,
  ) => {
    const len: number = typeof a === 'number' ? a : 0;
    const callback: misc.TCallback<void> = util.validateCallback(typeof a === 'number' ? b : a);
    this.open(path, 'r+', (error, fd) => {
      Iif (error) callback(error);
      else {
        this.ftruncate(fd!, len, error => {
          Iif (error) this.close(fd!, () => callback(error));
          else this.close(fd!, callback);
        });
      }
    });
  };
 
  public readonly futimes: FsCallbackApi['futimes'] = (
    fd: number,
    atime: misc.TTime,
    mtime: misc.TTime,
    callback: misc.TCallback<void>,
  ): void => {
    callback(null);
  };
 
  public readonly utimes: FsCallbackApi['utimes'] = (
    path: misc.PathLike,
    atime: misc.TTime,
    mtime: misc.TTime,
    callback: misc.TCallback<void>,
  ): void => {
    callback(null);
  };
 
  public readonly mkdir: FsCallbackApi['mkdir'] = (
    path: misc.PathLike,
    a: misc.TCallback<void> | misc.TMode | opts.IMkdirOptions,
    b?: misc.TCallback<string> | misc.TCallback<void>,
  ) => {
    const opts: misc.TMode | opts.IMkdirOptions = optHelpers.getMkdirOptions(a);
    const callback = util.validateCallback(typeof a === 'function' ? a : b!);
    // const modeNum = modeToNumber(opts.mode, 0o777);
    const filename = util.pathToFilename(path);
    const [folder, name] = pathToLocation(filename);
    // TODO: need to throw if directory already exists
    this.getDir(folder, opts.recursive ?? false)
      .then(dir => dir.getDirectoryHandle(name, { create: true }))
      .then(
        () => callback(null),
        error => {
          if (error && typeof error === 'object') {
            switch (error.name) {
              case 'NotFoundError': {
                const err = util.createError('ENOENT', 'mkdir', folder.join('/'));
                callback(err);
                return;
              }
            }
          }
          callback(error);
        },
      );
  };
 
  public readonly mkdtemp: FsCallbackApi['mkdtemp'] = (
    prefix: string,
    a: misc.TCallback<string> | opts.IOptions,
    b?: misc.TCallback<string>,
  ) => {
    const [{ encoding }, callback] = optHelpers.getDefaultOptsAndCb(a, b);
    Iif (!prefix || typeof prefix !== 'string') throw new TypeError('filename prefix is required');
    Iif (!util.nullCheck(prefix)) return;
    const filename = prefix + util.genRndStr6();
    this.mkdir(filename, MODE.DIR, err => {
      Iif (err) callback(err);
      else callback(null, strToEncoding(filename, encoding));
    });
  };
 
  private rmAll(callback: (err: Error | null) => void): void {
    (async () => {
      const root = await this.root;
      for await (const name of root.keys()) {
        await root.removeEntry(name, { recursive: true });
      }
    })().then(
      () => callback(null),
      error => callback(error),
    );
  }
 
  public readonly rmdir: FsCallbackApi['rmdir'] = (
    path: misc.PathLike,
    a: misc.TCallback<void> | opts.IRmdirOptions,
    b?: misc.TCallback<void>,
  ) => {
    const options: opts.IRmdirOptions = optHelpers.getRmdirOptions(a);
    const callback: misc.TCallback<void> = util.validateCallback(typeof a === 'function' ? a : b);
    const [folder, name] = pathToLocation(util.pathToFilename(path));
    if (!name && options.recursive) return this.rmAll(callback);
    this.getDir(folder, false, 'rmdir')
      .then(dir => dir.getDirectoryHandle(name).then(() => dir))
      .then(dir => dir.removeEntry(name, { recursive: options.recursive ?? false }))
      .then(
        () => callback(null),
        error => {
          if (error && typeof error === 'object') {
            switch (error.name) {
              case 'NotFoundError': {
                const err = util.createError('ENOENT', 'rmdir', folder.join('/'));
                callback(err);
                return;
              }
              case 'InvalidModificationError': {
                const err = util.createError('ENOTEMPTY', 'rmdir', folder.join('/'));
                callback(err);
                return;
              }
            }
          }
          callback(error);
        },
      );
  };
 
  public readonly rm: FsCallbackApi['rm'] = (
    path: misc.PathLike,
    a: misc.TCallback<void> | opts.IRmOptions,
    b?: misc.TCallback<void>,
  ): void => {
    const [options, callback] = optHelpers.getRmOptsAndCb(a, b);
    const [folder, name] = pathToLocation(util.pathToFilename(path));
    if (!name && options.recursive) return this.rmAll(callback);
    this.getDir(folder, false, 'rmdir')
      .then(dir => dir.removeEntry(name, { recursive: options.recursive ?? false }))
      .then(
        () => callback(null),
        error => {
          if (options.force) {
            callback(null);
            return;
          }
          if (error && typeof error === 'object') {
            switch (error.name) {
              case 'NotFoundError': {
                const err = util.createError('ENOENT', 'rmdir', folder.join('/'));
                callback(err);
                return;
              }
              case 'InvalidModificationError': {
                const err = util.createError('ENOTEMPTY', 'rmdir', folder.join('/'));
                callback(err);
                return;
              }
            }
          }
          callback(error);
        },
      );
  };
 
  public readonly fchmod: FsCallbackApi['fchmod'] = (
    fd: number,
    mode: misc.TMode,
    callback: misc.TCallback<void>,
  ): void => {
    callback(null);
  };
 
  public readonly chmod: FsCallbackApi['chmod'] = (
    path: misc.PathLike,
    mode: misc.TMode,
    callback: misc.TCallback<void>,
  ): void => {
    callback(null);
  };
 
  public readonly lchmod: FsCallbackApi['lchmod'] = (
    path: misc.PathLike,
    mode: misc.TMode,
    callback: misc.TCallback<void>,
  ): void => {
    callback(null);
  };
 
  public readonly fchown: FsCallbackApi['fchown'] = (
    fd: number,
    uid: number,
    gid: number,
    callback: misc.TCallback<void>,
  ): void => {
    callback(null);
  };
 
  public readonly chown: FsCallbackApi['chown'] = (
    path: misc.PathLike,
    uid: number,
    gid: number,
    callback: misc.TCallback<void>,
  ): void => {
    callback(null);
  };
 
  public readonly lchown: FsCallbackApi['lchown'] = (
    path: misc.PathLike,
    uid: number,
    gid: number,
    callback: misc.TCallback<void>,
  ): void => {
    callback(null);
  };
 
  public readonly createWriteStream: FsCallbackApi['createWriteStream'] = (
    path: misc.PathLike,
    options?: opts.IWriteStreamOptions | string,
  ): FsaNodeWriteStream => {
    const defaults: opts.IWriteStreamOptions = {
      encoding: 'utf8',
      flags: 'w',
      autoClose: true,
      emitClose: true,
    };
    const optionsObj: opts.IWriteStreamOptions = optHelpers.getOptions(defaults, options);
    const filename = util.pathToFilename(path);
    const flags = util.flagsToNumber(optionsObj.flags ?? 'w');
    const fd: number = optionsObj.fd ? (typeof optionsObj.fd === 'number' ? optionsObj.fd : optionsObj.fd.fd) : 0;
    const handle = fd ? this.getFileByFdAsync(fd) : this.__open(filename, flags, 0);
    const stream = new FsaNodeWriteStream(handle, filename, optionsObj);
    if (optionsObj.autoClose) {
      stream.once('finish', () => {
        handle.then(file => this.close(file.fd, () => {}));
      });
      stream.once('error', () => {
        handle.then(file => this.close(file.fd, () => {}));
      });
    }
    return stream;
  };
 
  public readonly createReadStream: FsCallbackApi['createReadStream'] = (
    path: misc.PathLike,
    options?: opts.IReadStreamOptions | string,
  ): misc.IReadStream => {
    const defaults: opts.IReadStreamOptions = {
      flags: 'r',
      fd: null,
      mode: 0o666,
      autoClose: true,
      emitClose: true,
      start: 0,
      end: Infinity,
      highWaterMark: 64 * 1024,
      fs: null,
      signal: null,
    };
    const optionsObj: opts.IReadStreamOptions = optHelpers.getOptions<opts.IReadStreamOptions>(defaults, options);
    const filename = util.pathToFilename(path);
    const flags = util.flagsToNumber(optionsObj.flags);
    const fd: number = optionsObj.fd ? (typeof optionsObj.fd === 'number' ? optionsObj.fd : optionsObj.fd.fd) : 0;
    const handle = fd ? this.getFileByFdAsync(fd) : this.__open(filename, flags, 0);
    const stream = new FsaNodeReadStream(this, handle, filename, optionsObj);
    return stream;
  };
 
  public readonly cp: FsCallbackApi['cp'] = notImplemented;
  public readonly lutimes: FsCallbackApi['lutimes'] = notImplemented;
  public readonly openAsBlob: FsCallbackApi['openAsBlob'] = notImplemented;
  public readonly opendir: FsCallbackApi['opendir'] = notImplemented;
  public readonly readv: FsCallbackApi['readv'] = notImplemented;
  public readonly statfs: FsCallbackApi['statfs'] = notImplemented;
 
  /**
   * @todo Watchers could be implemented in the future on top of `FileSystemObserver`,
   * which is currently a proposal.
   * @see https://github.com/whatwg/fs/blob/main/proposals/FileSystemObserver.md
   */
  public readonly watchFile: FsCallbackApi['watchFile'] = notSupported;
  public readonly unwatchFile: FsCallbackApi['unwatchFile'] = notSupported;
  public readonly watch: FsCallbackApi['watch'] = notSupported;
 
  public readonly symlink: FsCallbackApi['symlink'] = notSupported;
  public readonly link: FsCallbackApi['link'] = notSupported;
 
  // --------------------------------------------------------- FsSynchronousApi
 
  public readonly statSync: FsSynchronousApi['statSync'] = (
    path: misc.PathLike,
    options?: opts.IStatOptions,
  ): misc.IStats<any> => {
    const { bigint = true, throwIfNoEntry = true } = optHelpers.getStatOptions(options);
    const filename = util.pathToFilename(path);
    const location = pathToLocation(filename);
    const adapter = this.getSyncAdapter();
    const res = adapter.call('stat', location);
    const stats = new FsaNodeStats(bigint, res.size ?? 0, res.kind);
    return stats;
  };
 
  public readonly lstatSync: FsSynchronousApi['lstatSync'] = this.statSync;
 
  public readonly fstatSync: FsSynchronousApi['fstatSync'] = (fd: number, options?: opts.IFStatOptions) => {
    const filename = this.getFileName(fd);
    return this.statSync(filename, options as any) as any;
  };
 
  public readonly accessSync: FsSynchronousApi['accessSync'] = (
    path: misc.PathLike,
    mode: number = AMODE.F_OK,
  ): void => {
    const filename = util.pathToFilename(path);
    mode = mode | 0;
    const adapter = this.getSyncAdapter();
    adapter.call('access', [filename, mode]);
  };
 
  public readonly readFileSync: FsSynchronousApi['readFileSync'] = (
    id: misc.TFileId,
    options?: opts.IReadFileOptions | string,
  ): misc.TDataOut => {
    const opts = optHelpers.getReadFileOptions(options);
    const flagsNum = util.flagsToNumber(opts.flag);
    const filename = this.getFileName(id);
    const adapter = this.getSyncAdapter();
    const uint8 = adapter.call('readFile', [filename, opts]);
    const buffer = Buffer.from(uint8.buffer, uint8.byteOffset, uint8.byteLength);
    return util.bufferToEncoding(buffer, opts.encoding);
  };
 
  public readonly writeFileSync: FsSynchronousApi['writeFileSync'] = (
    id: misc.TFileId,
    data: misc.TData,
    options?: opts.IWriteFileOptions,
  ): void => {
    const opts = optHelpers.getWriteFileOptions(options);
    const flagsNum = util.flagsToNumber(opts.flag);
    const modeNum = util.modeToNumber(opts.mode);
    const buf = util.dataToBuffer(data, opts.encoding);
    const filename = this.getFileName(id);
    const adapter = this.getSyncAdapter();
    adapter.call('writeFile', [filename, util.bufToUint8(buf), opts]);
  };
 
  public readonly appendFileSync: FsSynchronousApi['appendFileSync'] = (
    id: misc.TFileId,
    data: misc.TData,
    options?: opts.IAppendFileOptions | string,
  ) => {
    const opts = optHelpers.getAppendFileOpts(options);
    Iif (!opts.flag || util.isFd(id)) opts.flag = 'a';
    const filename = this.getFileName(id);
    const buf = util.dataToBuffer(data, opts.encoding);
    const adapter = this.getSyncAdapter();
    adapter.call('appendFile', [filename, util.bufToUint8(buf), opts]);
  };
 
  public readonly closeSync: FsSynchronousApi['closeSync'] = (fd: number) => {
    util.validateFd(fd);
    const file = this.getFileByFd(fd, 'close');
    file.close().catch(() => {});
    this.fds.delete(fd);
    this.releasedFds.push(fd);
  };
 
  public readonly existsSync: FsSynchronousApi['existsSync'] = (path: misc.PathLike): boolean => {
    try {
      this.statSync(path);
      return true;
    } catch {
      return false;
    }
  };
 
  public readonly copyFileSync: FsSynchronousApi['copyFileSync'] = (
    src: misc.PathLike,
    dest: misc.PathLike,
    flags?: misc.TFlagsCopy,
  ): void => {
    const srcFilename = util.pathToFilename(src);
    const destFilename = util.pathToFilename(dest);
    const adapter = this.getSyncAdapter();
    adapter.call('copy', [srcFilename, destFilename, flags]);
  };
 
  public readonly renameSync: FsSynchronousApi['renameSync'] = (
    oldPath: misc.PathLike,
    newPath: misc.PathLike,
  ): void => {
    const srcFilename = util.pathToFilename(oldPath);
    const destFilename = util.pathToFilename(newPath);
    const adapter = this.getSyncAdapter();
    adapter.call('move', [srcFilename, destFilename]);
  };
 
  public readonly rmdirSync: FsSynchronousApi['rmdirSync'] = (path: misc.PathLike, opts?: opts.IRmdirOptions): void => {
    const filename = util.pathToFilename(path);
    const adapter = this.getSyncAdapter();
    adapter.call('rmdir', [filename, opts]);
  };
 
  public readonly rmSync: FsSynchronousApi['rmSync'] = (path: misc.PathLike, options?: opts.IRmOptions): void => {
    const filename = util.pathToFilename(path);
    const adapter = this.getSyncAdapter();
    adapter.call('rm', [filename, options]);
  };
 
  public readonly mkdirSync: FsSynchronousApi['mkdirSync'] = (
    path: misc.PathLike,
    options?: misc.TMode | opts.IMkdirOptions,
  ): string | undefined => {
    const opts = optHelpers.getMkdirOptions(options);
    const modeNum = util.modeToNumber(opts.mode, 0o777);
    const filename = util.pathToFilename(path);
    return this.getSyncAdapter().call('mkdir', [filename, options]);
  };
 
  public readonly mkdtempSync: FsSynchronousApi['mkdtempSync'] = (
    prefix: string,
    options?: opts.IOptions,
  ): misc.TDataOut => {
    const { encoding } = optHelpers.getDefaultOpts(options);
    Iif (!prefix || typeof prefix !== 'string') throw new TypeError('filename prefix is required');
    util.nullCheck(prefix);
    const result = this.getSyncAdapter().call('mkdtemp', [prefix, options]);
    return strToEncoding(result, encoding);
  };
 
  public readonly readlinkSync: FsSynchronousApi['readlinkSync'] = (
    path: misc.PathLike,
    options?: opts.IOptions,
  ): misc.TDataOut => {
    const opts = optHelpers.getDefaultOpts(options);
    const filename = util.pathToFilename(path);
    const buffer = Buffer.from(filename);
    return util.bufferToEncoding(buffer, opts.encoding);
  };
 
  public readonly truncateSync: FsSynchronousApi['truncateSync'] = (id: misc.TFileId, len?: number): void => {
    Iif (util.isFd(id)) return this.ftruncateSync(id as number, len);
    const filename = util.pathToFilename(id as misc.PathLike);
    this.getSyncAdapter().call('trunc', [filename, Number(len) || 0]);
  };
 
  public readonly ftruncateSync: FsSynchronousApi['ftruncateSync'] = (fd: number, len?: number): void => {
    const filename = this.getFileName(fd);
    this.truncateSync(filename, len);
  };
 
  public readonly unlinkSync: FsSynchronousApi['unlinkSync'] = (path: misc.PathLike): void => {
    const filename = util.pathToFilename(path);
    this.getSyncAdapter().call('unlink', [filename]);
  };
 
  public readonly readdirSync: FsSynchronousApi['readdirSync'] = (
    path: misc.PathLike,
    options?: opts.IReaddirOptions | string,
  ): misc.TDataOut[] | misc.IDirent[] => {
    const opts = optHelpers.getReaddirOptions(options);
    const filename = util.pathToFilename(path);
    const adapter = this.getSyncAdapter();
    const list = adapter.call('readdir', [filename]);
    if (opts.withFileTypes) {
      const res: misc.IDirent[] = [];
      for (const entry of list) res.push(new FsaNodeDirent(entry.name, entry.kind));
      return res;
    } else {
      const res: misc.TDataOut[] = [];
      for (const entry of list) {
        const buffer = Buffer.from(entry.name);
        res.push(util.bufferToEncoding(buffer, opts.encoding));
      }
      return res;
    }
  };
 
  public readonly realpathSync: FsSynchronousApi['realpathSync'] = (
    path: misc.PathLike,
    options?: opts.IRealpathOptions | string,
  ): misc.TDataOut => {
    let filename = util.pathToFilename(path);
    const { encoding } = optHelpers.getRealpathOptions(options);
    if (filename[0] !== FsaToNodeConstants.Separator) filename = FsaToNodeConstants.Separator + filename;
    return strToEncoding(filename, encoding);
  };
 
  public readonly readSync: FsSynchronousApi['readSync'] = (
    fd: number,
    buffer: Buffer | ArrayBufferView | DataView,
    offset: number,
    length: number,
    position: number,
  ): number => {
    util.validateFd(fd);
    const filename = this.getFileName(fd);
    const adapter = this.getSyncAdapter();
    const uint8 = adapter.call('read', [filename, position, length]);
    const dest = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
    dest.set(uint8, offset);
    return uint8.length;
  };
 
  public readonly writeSync: FsSynchronousApi['writeSync'] = (
    fd: number,
    a: string | Buffer | ArrayBufferView | DataView,
    b?: number,
    c?: number | BufferEncoding,
    d?: number | null,
  ): number => {
    const [, buf, offset, length, position] = util.getWriteSyncArgs(fd, a, b, c, d);
    const filename = this.getFileName(fd);
    const data = new Uint8Array(buf.buffer, buf.byteOffset + offset, length);
    return this.getSyncAdapter().call('write', [filename, data, position || null]);
  };
 
  public readonly openSync: FsSynchronousApi['openSync'] = (
    path: misc.PathLike,
    flags: misc.TFlags,
    mode: misc.TMode = MODE.DEFAULT,
  ): number => {
    const modeNum = util.modeToNumber(mode);
    const filename = util.pathToFilename(path);
    const flagsNum = util.flagsToNumber(flags);
    const adapter = this.getSyncAdapter();
    const handle = adapter.call('open', [filename, flagsNum, modeNum]);
    const openFile = this.__open2(handle, filename, flagsNum, modeNum);
    return openFile.fd;
  };
 
  public readonly writevSync: FsSynchronousApi['writevSync'] = (
    fd: number,
    buffers: ArrayBufferView[],
    position?: number | null,
  ): void => {
    Iif (buffers.length === 0) return;
    this.writeSync(fd, buffers[0], 0, buffers[0].byteLength, position);
    for (let i = 1; i < buffers.length; i++) {
      this.writeSync(fd, buffers[i], 0, buffers[i].byteLength, null);
    }
  };
 
  public readonly fdatasyncSync: FsSynchronousApi['fdatasyncSync'] = noop;
  public readonly fsyncSync: FsSynchronousApi['fsyncSync'] = noop;
  public readonly chmodSync: FsSynchronousApi['chmodSync'] = noop;
  public readonly chownSync: FsSynchronousApi['chownSync'] = noop;
  public readonly fchmodSync: FsSynchronousApi['fchmodSync'] = noop;
  public readonly fchownSync: FsSynchronousApi['fchownSync'] = noop;
  public readonly futimesSync: FsSynchronousApi['futimesSync'] = noop;
  public readonly lchmodSync: FsSynchronousApi['lchmodSync'] = noop;
  public readonly lchownSync: FsSynchronousApi['lchownSync'] = noop;
  public readonly utimesSync: FsSynchronousApi['utimesSync'] = noop;
  public readonly lutimesSync: FsSynchronousApi['lutimesSync'] = noop;
 
  public readonly cpSync: FsSynchronousApi['cpSync'] = notImplemented;
  public readonly opendirSync: FsSynchronousApi['opendirSync'] = notImplemented;
  public readonly statfsSync: FsSynchronousApi['statfsSync'] = notImplemented;
  public readonly readvSync: FsSynchronousApi['readvSync'] = notImplemented;
 
  public readonly symlinkSync: FsSynchronousApi['symlinkSync'] = notSupported;
  public readonly linkSync: FsSynchronousApi['linkSync'] = notSupported;
 
  // ---------------------------------------------------------- FsCommonObjects
 
  public readonly F_OK = constants.F_OK;
  public readonly R_OK = constants.R_OK;
  public readonly W_OK = constants.W_OK;
  public readonly X_OK = constants.X_OK;
  public readonly constants = constants;
  public readonly Dirent = FsaNodeDirent;
  public readonly Stats = FsaNodeStats<any>;
  public readonly WriteStream = FsaNodeWriteStream;
  public readonly ReadStream = FsaNodeReadStream;
 
  public readonly StatFs = 0 as any;
  public readonly Dir = 0 as any;
  public readonly StatsWatcher = 0 as any;
  public readonly FSWatcher = 0 as any;
}