@zenfs/core 0.0.2 → 0.0.4

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 (45) hide show
  1. package/dist/ApiError.d.ts +1 -1
  2. package/dist/backends/AsyncMirror.d.ts +5 -5
  3. package/dist/backends/AsyncMirror.js +5 -5
  4. package/dist/backends/AsyncStore.d.ts +5 -5
  5. package/dist/backends/AsyncStore.js +7 -7
  6. package/dist/backends/FolderAdapter.d.ts +2 -2
  7. package/dist/backends/FolderAdapter.js +4 -4
  8. package/dist/backends/InMemory.d.ts +3 -3
  9. package/dist/backends/InMemory.js +2 -2
  10. package/dist/backends/Locked.d.ts +6 -6
  11. package/dist/backends/Locked.js +1 -1
  12. package/dist/backends/OverlayFS.d.ts +6 -6
  13. package/dist/backends/OverlayFS.js +7 -7
  14. package/dist/backends/SyncStore.d.ts +5 -5
  15. package/dist/backends/SyncStore.js +7 -7
  16. package/dist/backends/backend.d.ts +1 -1
  17. package/dist/backends/backend.js +1 -1
  18. package/dist/backends/index.d.ts +5 -5
  19. package/dist/backends/index.js +4 -4
  20. package/dist/browser.min.js.map +1 -1
  21. package/dist/emulation/callbacks.d.ts +4 -4
  22. package/dist/emulation/callbacks.js +4 -4
  23. package/dist/emulation/fs.d.ts +3 -3
  24. package/dist/emulation/fs.js +2 -2
  25. package/dist/emulation/index.d.ts +5 -5
  26. package/dist/emulation/index.js +5 -5
  27. package/dist/emulation/promises.d.ts +5 -5
  28. package/dist/emulation/promises.js +4 -4
  29. package/dist/emulation/shared.d.ts +5 -5
  30. package/dist/emulation/shared.js +3 -3
  31. package/dist/emulation/sync.d.ts +4 -4
  32. package/dist/emulation/sync.js +3 -3
  33. package/dist/file.d.ts +3 -3
  34. package/dist/file.js +3 -3
  35. package/dist/filesystem.d.ts +5 -5
  36. package/dist/filesystem.js +2 -2
  37. package/dist/index.d.ts +14 -14
  38. package/dist/index.js +17 -17
  39. package/dist/inode.d.ts +2 -2
  40. package/dist/inode.js +1 -1
  41. package/dist/stats.d.ts +3 -3
  42. package/dist/stats.js +2 -2
  43. package/dist/utils.d.ts +4 -4
  44. package/dist/utils.js +1 -1
  45. package/package.json +8 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts", "../node_modules/@jspm/core/nodelibs/browser/process.js", "../node_modules/@jspm/core/nodelibs/browser/buffer.js", "../src/emulation/index.ts", "../src/ApiError.ts", "../node_modules/@jspm/core/nodelibs/browser/chunk-2eac56ff.js", "../node_modules/@jspm/core/nodelibs/browser/chunk-23dbec7b.js", "../node_modules/@jspm/core/nodelibs/browser/path.js", "../src/emulation/constants.ts", "../src/cred.ts", "../src/stats.ts", "../src/file.ts", "../src/filesystem.ts", "../src/inode.ts", "../src/utils.ts", "../src/backends/SyncStore.ts", "../src/backends/backend.ts", "../src/backends/InMemory.ts", "../src/emulation/shared.ts", "../src/emulation/promises.ts", "../src/emulation/callbacks.ts", "../src/emulation/sync.ts", "../src/emulation/fs.ts", "../src/backends/AsyncMirror.ts", "../src/backends/FolderAdapter.ts", "../src/mutex.ts", "../src/backends/Locked.ts", "../src/backends/OverlayFS.ts", "../src/backends/index.ts", "../src/backends/AsyncStore.ts"],
4
- "sourcesContent": ["/**\n * ZenFS's main module. This is exposed in the browser via the ZenFS global.\n */\n\nimport fs from './emulation/fs';\nimport { FileSystem, type BFSOneArgCallback, type BFSCallback } from './filesystem';\nimport { backends } from './backends';\nimport { ErrorCode, ApiError } from './ApiError';\nimport { Cred } from './cred';\nimport * as process from 'process';\nimport type { BackendConstructor } from './backends/backend';\nimport { type MountMapping, setCred } from './emulation/shared';\n\nif (process && (<any>process)['initializeTTYs']) {\n\t(<any>process)['initializeTTYs']();\n}\n\n/**\n * Initializes ZenFS with the given file systems.\n */\nexport function initialize(mounts: { [point: string]: FileSystem }, uid: number = 0, gid: number = 0) {\n\tsetCred(new Cred(uid, gid, uid, gid, uid, gid));\n\treturn fs.initialize(mounts);\n}\n\n/**\n * Defines a mapping of mount points to their configurations\n */\nexport interface ConfigMapping {\n\t[mountPoint: string]: FileSystem | FileSystemConfiguration | keyof typeof backends;\n}\n\n/**\n * A configuration for ZenFS\n */\nexport type Configuration = FileSystem | FileSystemConfiguration | ConfigMapping;\n\nasync function _configure(config: Configuration): Promise<void> {\n\tif ('fs' in config || config instanceof FileSystem) {\n\t\t// single FS\n\t\tconfig = { '/': config } as ConfigMapping;\n\t}\n\tfor (let [point, value] of Object.entries(config)) {\n\t\tif (typeof value == 'number') {\n\t\t\t//should never happen\n\t\t\tcontinue;\n\t\t}\n\t\tpoint = point.toString(); // so linting stops complaining that point should be declared with const, which can't be done since value is assigned to\n\n\t\tif (value instanceof FileSystem) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (typeof value == 'string') {\n\t\t\tvalue = { fs: value };\n\t\t}\n\n\t\tconfig[point] = await getFileSystem(value);\n\t}\n\treturn initialize(config as MountMapping);\n}\n\n/**\n * Creates a file system with the given configuration, and initializes ZenFS with it.\n * See the FileSystemConfiguration type for more info on the configuration object.\n */\nexport function configure(config: Configuration): Promise<void>;\nexport function configure(config: Configuration, cb: BFSOneArgCallback): void;\nexport function configure(config: Configuration, cb?: BFSOneArgCallback): Promise<void> | void {\n\t// Promise version\n\tif (typeof cb != 'function') {\n\t\treturn _configure(config);\n\t}\n\n\t// Callback version\n\t_configure(config)\n\t\t.then(() => cb())\n\t\t.catch(err => cb(err));\n\treturn;\n}\n\n/**\n * Asynchronously creates a file system with the given configuration, and initializes ZenFS with it.\n * See the FileSystemConfiguration type for more info on the configuration object.\n * Note: unlike configure, the .then is provided with the file system\n */\n\n/**\n * Specifies a file system backend type and its options.\n *\n * Individual options can recursively contain FileSystemConfiguration objects for\n * option values that require file systems.\n *\n * For example, to mirror Dropbox to Storage with AsyncMirror, use the following\n * object:\n *\n * ```javascript\n * var config = {\n * fs: \"AsyncMirror\",\n * options: {\n * sync: {fs: \"Storage\"},\n * async: {fs: \"Dropbox\", options: {client: anAuthenticatedDropboxSDKClient }}\n * }\n * };\n * ```\n *\n * The option object for each file system corresponds to that file system's option object passed to its `Create()` method.\n */\nexport interface FileSystemConfiguration {\n\tfs: string;\n\toptions?: object;\n}\n\nasync function _getFileSystem({ fs: fsName, options = {} }: FileSystemConfiguration): Promise<FileSystem> {\n\tif (!fsName) {\n\t\tthrow new ApiError(ErrorCode.EPERM, 'Missing \"fs\" property on configuration object.');\n\t}\n\n\tif (typeof options !== 'object' || options === null) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Invalid \"options\" property on configuration object.');\n\t}\n\n\tconst props = Object.keys(options).filter(k => k != 'fs');\n\n\tfor (const prop of props) {\n\t\tconst opt = options[prop];\n\t\tif (opt === null || typeof opt !== 'object' || !('fs' in opt)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst fs = await _getFileSystem(opt);\n\t\toptions[prop] = fs;\n\t}\n\n\tconst fsc = <BackendConstructor | undefined>(<any>backends)[fsName];\n\tif (!fsc) {\n\t\tthrow new ApiError(ErrorCode.EPERM, `File system ${fsName} is not available in ZenFS.`);\n\t} else {\n\t\treturn fsc.Create(options);\n\t}\n}\n\n/**\n * Retrieve a file system with the given configuration. Will return a promise if invoked without a callback\n * @param config A FileSystemConfiguration object. See FileSystemConfiguration for details.\n * @param cb Called when the file system is constructed, or when an error occurs.\n */\nexport function getFileSystem(config: FileSystemConfiguration): Promise<FileSystem>;\nexport function getFileSystem(config: FileSystemConfiguration, cb: BFSCallback<FileSystem>): void;\nexport function getFileSystem(config: FileSystemConfiguration, cb?: BFSCallback<FileSystem>): Promise<FileSystem> | void {\n\t// Promise version\n\tif (typeof cb != 'function') {\n\t\treturn _getFileSystem(config);\n\t}\n\n\t// Callback version\n\t_getFileSystem(config)\n\t\t.then(fs => cb(null, fs))\n\t\t.catch(err => cb(err));\n\treturn;\n}\n\nexport * from './backends';\nexport * from './backends/AsyncStore';\nexport * from './backends/SyncStore';\nexport * from './ApiError';\nexport * from './cred';\nexport * from './file';\nexport * from './filesystem';\nexport * from './inode';\nexport * from './mutex';\nexport * from './stats';\nexport * from './utils';\nexport { fs };\nexport default fs;\n", "function unimplemented(name) {\r\n throw new Error('Node.js process ' + name + ' is not supported by JSPM core outside of Node.js');\r\n}\r\n\r\nvar queue = [];\r\nvar draining = false;\r\nvar currentQueue;\r\nvar queueIndex = -1;\r\n\r\nfunction cleanUpNextTick() {\r\n if (!draining || !currentQueue)\r\n return;\r\n draining = false;\r\n if (currentQueue.length) {\r\n queue = currentQueue.concat(queue);\r\n }\r\n else {\r\n queueIndex = -1;\r\n }\r\n if (queue.length)\r\n drainQueue();\r\n}\r\n\r\nfunction drainQueue() {\r\n if (draining)\r\n return;\r\n var timeout = setTimeout(cleanUpNextTick, 0);\r\n draining = true;\r\n\r\n var len = queue.length;\r\n while(len) {\r\n currentQueue = queue;\r\n queue = [];\r\n while (++queueIndex < len) {\r\n if (currentQueue)\r\n currentQueue[queueIndex].run();\r\n }\r\n queueIndex = -1;\r\n len = queue.length;\r\n }\r\n currentQueue = null;\r\n draining = false;\r\n clearTimeout(timeout);\r\n}\r\n\r\nfunction nextTick (fun) {\r\n var args = new Array(arguments.length - 1);\r\n if (arguments.length > 1) {\r\n for (var i = 1; i < arguments.length; i++)\r\n args[i - 1] = arguments[i];\r\n }\r\n queue.push(new Item(fun, args));\r\n if (queue.length === 1 && !draining)\r\n setTimeout(drainQueue, 0);\r\n}\r\n// v8 likes predictible objects\r\nfunction Item(fun, array) {\r\n this.fun = fun;\r\n this.array = array;\r\n}\r\nItem.prototype.run = function () {\r\n this.fun.apply(null, this.array);\r\n};\r\n\r\nvar title = 'browser';\r\nvar arch = 'x64';\r\nvar platform = 'browser';\r\nvar env = {\r\n PATH: '/usr/bin',\r\n LANG: navigator.language + '.UTF-8',\r\n PWD: '/',\r\n HOME: '/home',\r\n TMP: '/tmp',\r\n};\r\nvar argv = ['/usr/bin/node'];\r\nvar execArgv = [];\r\nvar version = 'v16.8.0';\r\nvar versions = {};\r\n\r\nvar emitWarning = function(message, type) {\r\n console.warn((type ? (type + ': ') : '') + message);\r\n};\r\n\r\nvar binding = function(name) { unimplemented('binding'); };\r\n\r\nvar umask = function(mask) { return 0; };\r\n\r\nvar cwd = function() { return '/'; };\r\nvar chdir = function(dir) {};\r\n\r\nvar release = {\r\n name: 'node',\r\n sourceUrl: '',\r\n headersUrl: '',\r\n libUrl: '',\r\n};\r\n\r\nfunction noop() {}\r\n\r\nvar _rawDebug = noop;\r\nvar moduleLoadList = [];\r\nfunction _linkedBinding(name) { unimplemented('_linkedBinding'); }\r\nvar domain = {};\r\nvar _exiting = false;\r\nvar config = {};\r\nfunction dlopen(name) { unimplemented('dlopen'); }\r\nfunction _getActiveRequests() { return []; }\r\nfunction _getActiveHandles() { return []; }\r\nvar reallyExit = noop;\r\nvar _kill = noop;\r\nvar cpuUsage = function() { return {}; };\r\nvar resourceUsage = cpuUsage;\r\nvar memoryUsage = cpuUsage;\r\nvar kill = noop;\r\nvar exit = noop;\r\nvar openStdin = noop;\r\nvar allowedNodeEnvironmentFlags = {};\r\nfunction assert(condition, message) {\r\n if (!condition) throw new Error(message || 'assertion error');\r\n}\r\nvar features = {\r\n inspector: false,\r\n debug: false,\r\n uv: false,\r\n ipv6: false,\r\n tls_alpn: false,\r\n tls_sni: false,\r\n tls_ocsp: false,\r\n tls: false,\r\n cached_builtins: true,\r\n};\r\nvar _fatalExceptions = noop;\r\nvar setUncaughtExceptionCaptureCallback = noop;\r\nfunction hasUncaughtExceptionCaptureCallback() { return false; }var _tickCallback = noop;\r\nvar _debugProcess = noop;\r\nvar _debugEnd = noop;\r\nvar _startProfilerIdleNotifier = noop;\r\nvar _stopProfilerIdleNotifier = noop;\r\nvar stdout = undefined;\r\nvar stderr = undefined;\r\nvar stdin = undefined;\r\nvar abort = noop;\r\nvar pid = 2;\r\nvar ppid = 1;\r\nvar execPath = '/bin/usr/node';\r\nvar debugPort = 9229;\r\nvar argv0 = 'node';\r\nvar _preload_modules = [];\r\nvar setSourceMapsEnabled = noop;\r\n\r\nvar _performance = {\r\n now: typeof performance !== 'undefined' ? performance.now.bind(performance) : undefined,\r\n timing: typeof performance !== 'undefined' ? performance.timing : undefined,\r\n};\r\nif (_performance.now === undefined) {\r\n var nowOffset = Date.now();\r\n\r\n if (_performance.timing && _performance.timing.navigationStart) {\r\n nowOffset = _performance.timing.navigationStart;\r\n }\r\n _performance.now = () => Date.now() - nowOffset;\r\n}\r\n\r\nfunction uptime() {\r\n return _performance.now() / 1000;\r\n}\r\n\r\nvar nanoPerSec = 1000000000;\r\nfunction hrtime(previousTimestamp) {\r\n var baseNow = Math.floor((Date.now() - _performance.now()) * 1e-3);\r\n var clocktime = _performance.now() * 1e-3;\r\n var seconds = Math.floor(clocktime) + baseNow;\r\n var nanoseconds = Math.floor((clocktime % 1) * 1e9);\r\n if (previousTimestamp) {\r\n seconds = seconds - previousTimestamp[0];\r\n nanoseconds = nanoseconds - previousTimestamp[1];\r\n if (nanoseconds < 0) {\r\n seconds--;\r\n nanoseconds += nanoPerSec;\r\n }\r\n }\r\n return [seconds, nanoseconds];\r\n}hrtime.bigint = function(time) {\r\n var diff = hrtime(time);\r\n if (typeof BigInt === 'undefined') {\r\n return diff[0] * nanoPerSec + diff[1];\r\n }\r\n return BigInt(diff[0] * nanoPerSec) + BigInt(diff[1]);\r\n};\r\n\r\nvar _maxListeners = 10;\r\nvar _events = {};\r\nvar _eventsCount = 0;\r\nfunction on () { return process }var addListener = on;\r\nvar once = on;\r\nvar off = on;\r\nvar removeListener = on;\r\nvar removeAllListeners = on;\r\nvar emit = noop;\r\nvar prependListener = on;\r\nvar prependOnceListener = on;\r\nfunction listeners (name) { return []; }\r\nvar process = {\r\n version,\r\n versions,\r\n arch,\r\n platform,\r\n release,\r\n _rawDebug,\r\n moduleLoadList,\r\n binding,\r\n _linkedBinding,\r\n _events,\r\n _eventsCount,\r\n _maxListeners,\r\n on,\r\n addListener,\r\n once,\r\n off,\r\n removeListener,\r\n removeAllListeners,\r\n emit,\r\n prependListener,\r\n prependOnceListener,\r\n listeners,\r\n domain,\r\n _exiting,\r\n config,\r\n dlopen,\r\n uptime,\r\n _getActiveRequests,\r\n _getActiveHandles,\r\n reallyExit,\r\n _kill,\r\n cpuUsage,\r\n resourceUsage,\r\n memoryUsage,\r\n kill,\r\n exit,\r\n openStdin,\r\n allowedNodeEnvironmentFlags,\r\n assert,\r\n features,\r\n _fatalExceptions,\r\n setUncaughtExceptionCaptureCallback,\r\n hasUncaughtExceptionCaptureCallback,\r\n emitWarning,\r\n nextTick,\r\n _tickCallback,\r\n _debugProcess,\r\n _debugEnd,\r\n _startProfilerIdleNotifier,\r\n _stopProfilerIdleNotifier,\r\n stdout,\r\n stdin,\r\n stderr,\r\n abort,\r\n umask,\r\n chdir,\r\n cwd,\r\n env,\r\n title,\r\n argv,\r\n execArgv,\r\n pid,\r\n ppid,\r\n execPath,\r\n debugPort,\r\n hrtime,\r\n argv0,\r\n _preload_modules,\r\n setSourceMapsEnabled,\r\n};\n\nexport { _debugEnd, _debugProcess, _events, _eventsCount, _exiting, _fatalExceptions, _getActiveHandles, _getActiveRequests, _kill, _linkedBinding, _maxListeners, _preload_modules, _rawDebug, _startProfilerIdleNotifier, _stopProfilerIdleNotifier, _tickCallback, abort, addListener, allowedNodeEnvironmentFlags, arch, argv, argv0, assert, binding, chdir, config, cpuUsage, cwd, debugPort, process as default, dlopen, domain, emit, emitWarning, env, execArgv, execPath, exit, features, hasUncaughtExceptionCaptureCallback, hrtime, kill, listeners, memoryUsage, moduleLoadList, nextTick, off, on, once, openStdin, pid, platform, ppid, prependListener, prependOnceListener, reallyExit, release, removeAllListeners, removeListener, resourceUsage, setSourceMapsEnabled, setUncaughtExceptionCaptureCallback, stderr, stdin, stdout, title, umask, uptime, version, versions };\n", "var exports$3 = {},\n _dewExec$2 = false;\nfunction dew$2() {\n if (_dewExec$2) return exports$3;\n _dewExec$2 = true;\n exports$3.byteLength = byteLength;\n exports$3.toByteArray = toByteArray;\n exports$3.fromByteArray = fromByteArray;\n var lookup = [];\n var revLookup = [];\n var Arr = typeof Uint8Array !== \"undefined\" ? Uint8Array : Array;\n var code = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n\n for (var i = 0, len = code.length; i < len; ++i) {\n lookup[i] = code[i];\n revLookup[code.charCodeAt(i)] = i;\n } // Support decoding URL-safe base64 strings, as Node.js does.\n // See: https://en.wikipedia.org/wiki/Base64#URL_applications\n\n\n revLookup[\"-\".charCodeAt(0)] = 62;\n revLookup[\"_\".charCodeAt(0)] = 63;\n\n function getLens(b64) {\n var len = b64.length;\n\n if (len % 4 > 0) {\n throw new Error(\"Invalid string. Length must be a multiple of 4\");\n } // Trim off extra bytes after placeholder bytes are found\n // See: https://github.com/beatgammit/base64-js/issues/42\n\n\n var validLen = b64.indexOf(\"=\");\n if (validLen === -1) validLen = len;\n var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;\n return [validLen, placeHoldersLen];\n } // base64 is 4/3 + up to two characters of the original data\n\n\n function byteLength(b64) {\n var lens = getLens(b64);\n var validLen = lens[0];\n var placeHoldersLen = lens[1];\n return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;\n }\n\n function _byteLength(b64, validLen, placeHoldersLen) {\n return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;\n }\n\n function toByteArray(b64) {\n var tmp;\n var lens = getLens(b64);\n var validLen = lens[0];\n var placeHoldersLen = lens[1];\n var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));\n var curByte = 0; // if there are placeholders, only get up to the last complete 4 chars\n\n var len = placeHoldersLen > 0 ? validLen - 4 : validLen;\n var i;\n\n for (i = 0; i < len; i += 4) {\n tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];\n arr[curByte++] = tmp >> 16 & 255;\n arr[curByte++] = tmp >> 8 & 255;\n arr[curByte++] = tmp & 255;\n }\n\n if (placeHoldersLen === 2) {\n tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;\n arr[curByte++] = tmp & 255;\n }\n\n if (placeHoldersLen === 1) {\n tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;\n arr[curByte++] = tmp >> 8 & 255;\n arr[curByte++] = tmp & 255;\n }\n\n return arr;\n }\n\n function tripletToBase64(num) {\n return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];\n }\n\n function encodeChunk(uint8, start, end) {\n var tmp;\n var output = [];\n\n for (var i = start; i < end; i += 3) {\n tmp = (uint8[i] << 16 & 16711680) + (uint8[i + 1] << 8 & 65280) + (uint8[i + 2] & 255);\n output.push(tripletToBase64(tmp));\n }\n\n return output.join(\"\");\n }\n\n function fromByteArray(uint8) {\n var tmp;\n var len = uint8.length;\n var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes\n\n var parts = [];\n var maxChunkLength = 16383; // must be multiple of 3\n // go through the array every three bytes, we'll deal with trailing stuff later\n\n for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {\n parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength));\n } // pad the end with zeros, but make sure to not forget the extra bytes\n\n\n if (extraBytes === 1) {\n tmp = uint8[len - 1];\n parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + \"==\");\n } else if (extraBytes === 2) {\n tmp = (uint8[len - 2] << 8) + uint8[len - 1];\n parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + \"=\");\n }\n\n return parts.join(\"\");\n }\n\n return exports$3;\n}\n\nvar exports$2 = {},\n _dewExec$1 = false;\nfunction dew$1() {\n if (_dewExec$1) return exports$2;\n _dewExec$1 = true;\n\n /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */\n exports$2.read = function (buffer, offset, isLE, mLen, nBytes) {\n var e, m;\n var eLen = nBytes * 8 - mLen - 1;\n var eMax = (1 << eLen) - 1;\n var eBias = eMax >> 1;\n var nBits = -7;\n var i = isLE ? nBytes - 1 : 0;\n var d = isLE ? -1 : 1;\n var s = buffer[offset + i];\n i += d;\n e = s & (1 << -nBits) - 1;\n s >>= -nBits;\n nBits += eLen;\n\n for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}\n\n m = e & (1 << -nBits) - 1;\n e >>= -nBits;\n nBits += mLen;\n\n for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}\n\n if (e === 0) {\n e = 1 - eBias;\n } else if (e === eMax) {\n return m ? NaN : (s ? -1 : 1) * Infinity;\n } else {\n m = m + Math.pow(2, mLen);\n e = e - eBias;\n }\n\n return (s ? -1 : 1) * m * Math.pow(2, e - mLen);\n };\n\n exports$2.write = function (buffer, value, offset, isLE, mLen, nBytes) {\n var e, m, c;\n var eLen = nBytes * 8 - mLen - 1;\n var eMax = (1 << eLen) - 1;\n var eBias = eMax >> 1;\n var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;\n var i = isLE ? 0 : nBytes - 1;\n var d = isLE ? 1 : -1;\n var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;\n value = Math.abs(value);\n\n if (isNaN(value) || value === Infinity) {\n m = isNaN(value) ? 1 : 0;\n e = eMax;\n } else {\n e = Math.floor(Math.log(value) / Math.LN2);\n\n if (value * (c = Math.pow(2, -e)) < 1) {\n e--;\n c *= 2;\n }\n\n if (e + eBias >= 1) {\n value += rt / c;\n } else {\n value += rt * Math.pow(2, 1 - eBias);\n }\n\n if (value * c >= 2) {\n e++;\n c /= 2;\n }\n\n if (e + eBias >= eMax) {\n m = 0;\n e = eMax;\n } else if (e + eBias >= 1) {\n m = (value * c - 1) * Math.pow(2, mLen);\n e = e + eBias;\n } else {\n m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);\n e = 0;\n }\n }\n\n for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {}\n\n e = e << mLen | m;\n eLen += mLen;\n\n for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {}\n\n buffer[offset + i - d] |= s * 128;\n };\n\n return exports$2;\n}\n\nvar exports$1 = {},\n _dewExec = false;\nfunction dew() {\n if (_dewExec) return exports$1;\n _dewExec = true;\n\n const base64 = dew$2();\n\n const ieee754 = dew$1();\n\n const customInspectSymbol = typeof Symbol === \"function\" && typeof Symbol[\"for\"] === \"function\" ? Symbol[\"for\"](\"nodejs.util.inspect.custom\") // eslint-disable-line dot-notation\n : null;\n exports$1.Buffer = Buffer;\n exports$1.SlowBuffer = SlowBuffer;\n exports$1.INSPECT_MAX_BYTES = 50;\n const K_MAX_LENGTH = 2147483647;\n exports$1.kMaxLength = K_MAX_LENGTH;\n /**\n * If `Buffer.TYPED_ARRAY_SUPPORT`:\n * === true Use Uint8Array implementation (fastest)\n * === false Print warning and recommend using `buffer` v4.x which has an Object\n * implementation (most compatible, even IE6)\n *\n * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,\n * Opera 11.6+, iOS 4.2+.\n *\n * We report that the browser does not support typed arrays if the are not subclassable\n * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`\n * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support\n * for __proto__ and has a buggy typed array implementation.\n */\n\n Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();\n\n if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== \"undefined\" && typeof console.error === \"function\") {\n console.error(\"This browser lacks typed array (Uint8Array) support which is required by \" + \"`buffer` v5.x. Use `buffer` v4.x if you require old browser support.\");\n }\n\n function typedArraySupport() {\n // Can typed array instances can be augmented?\n try {\n const arr = new Uint8Array(1);\n const proto = {\n foo: function () {\n return 42;\n }\n };\n Object.setPrototypeOf(proto, Uint8Array.prototype);\n Object.setPrototypeOf(arr, proto);\n return arr.foo() === 42;\n } catch (e) {\n return false;\n }\n }\n\n Object.defineProperty(Buffer.prototype, \"parent\", {\n enumerable: true,\n get: function () {\n if (!Buffer.isBuffer(this)) return undefined;\n return this.buffer;\n }\n });\n Object.defineProperty(Buffer.prototype, \"offset\", {\n enumerable: true,\n get: function () {\n if (!Buffer.isBuffer(this)) return undefined;\n return this.byteOffset;\n }\n });\n\n function createBuffer(length) {\n if (length > K_MAX_LENGTH) {\n throw new RangeError(\"The value \\\"\" + length + \"\\\" is invalid for option \\\"size\\\"\");\n } // Return an augmented `Uint8Array` instance\n\n\n const buf = new Uint8Array(length);\n Object.setPrototypeOf(buf, Buffer.prototype);\n return buf;\n }\n /**\n * The Buffer constructor returns instances of `Uint8Array` that have their\n * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of\n * `Uint8Array`, so the returned instances will have all the node `Buffer` methods\n * and the `Uint8Array` methods. Square bracket notation works as expected -- it\n * returns a single octet.\n *\n * The `Uint8Array` prototype remains unmodified.\n */\n\n\n function Buffer(arg, encodingOrOffset, length) {\n // Common case.\n if (typeof arg === \"number\") {\n if (typeof encodingOrOffset === \"string\") {\n throw new TypeError(\"The \\\"string\\\" argument must be of type string. Received type number\");\n }\n\n return allocUnsafe(arg);\n }\n\n return from(arg, encodingOrOffset, length);\n }\n\n Buffer.poolSize = 8192; // not used by this implementation\n\n function from(value, encodingOrOffset, length) {\n if (typeof value === \"string\") {\n return fromString(value, encodingOrOffset);\n }\n\n if (ArrayBuffer.isView(value)) {\n return fromArrayView(value);\n }\n\n if (value == null) {\n throw new TypeError(\"The first argument must be one of type string, Buffer, ArrayBuffer, Array, \" + \"or Array-like Object. Received type \" + typeof value);\n }\n\n if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) {\n return fromArrayBuffer(value, encodingOrOffset, length);\n }\n\n if (typeof SharedArrayBuffer !== \"undefined\" && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) {\n return fromArrayBuffer(value, encodingOrOffset, length);\n }\n\n if (typeof value === \"number\") {\n throw new TypeError(\"The \\\"value\\\" argument must not be of type number. Received type number\");\n }\n\n const valueOf = value.valueOf && value.valueOf();\n\n if (valueOf != null && valueOf !== value) {\n return Buffer.from(valueOf, encodingOrOffset, length);\n }\n\n const b = fromObject(value);\n if (b) return b;\n\n if (typeof Symbol !== \"undefined\" && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === \"function\") {\n return Buffer.from(value[Symbol.toPrimitive](\"string\"), encodingOrOffset, length);\n }\n\n throw new TypeError(\"The first argument must be one of type string, Buffer, ArrayBuffer, Array, \" + \"or Array-like Object. Received type \" + typeof value);\n }\n /**\n * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError\n * if value is a number.\n * Buffer.from(str[, encoding])\n * Buffer.from(array)\n * Buffer.from(buffer)\n * Buffer.from(arrayBuffer[, byteOffset[, length]])\n **/\n\n\n Buffer.from = function (value, encodingOrOffset, length) {\n return from(value, encodingOrOffset, length);\n }; // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:\n // https://github.com/feross/buffer/pull/148\n\n\n Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);\n Object.setPrototypeOf(Buffer, Uint8Array);\n\n function assertSize(size) {\n if (typeof size !== \"number\") {\n throw new TypeError(\"\\\"size\\\" argument must be of type number\");\n } else if (size < 0) {\n throw new RangeError(\"The value \\\"\" + size + \"\\\" is invalid for option \\\"size\\\"\");\n }\n }\n\n function alloc(size, fill, encoding) {\n assertSize(size);\n\n if (size <= 0) {\n return createBuffer(size);\n }\n\n if (fill !== undefined) {\n // Only pay attention to encoding if it's a string. This\n // prevents accidentally sending in a number that would\n // be interpreted as a start offset.\n return typeof encoding === \"string\" ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);\n }\n\n return createBuffer(size);\n }\n /**\n * Creates a new filled Buffer instance.\n * alloc(size[, fill[, encoding]])\n **/\n\n\n Buffer.alloc = function (size, fill, encoding) {\n return alloc(size, fill, encoding);\n };\n\n function allocUnsafe(size) {\n assertSize(size);\n return createBuffer(size < 0 ? 0 : checked(size) | 0);\n }\n /**\n * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.\n * */\n\n\n Buffer.allocUnsafe = function (size) {\n return allocUnsafe(size);\n };\n /**\n * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.\n */\n\n\n Buffer.allocUnsafeSlow = function (size) {\n return allocUnsafe(size);\n };\n\n function fromString(string, encoding) {\n if (typeof encoding !== \"string\" || encoding === \"\") {\n encoding = \"utf8\";\n }\n\n if (!Buffer.isEncoding(encoding)) {\n throw new TypeError(\"Unknown encoding: \" + encoding);\n }\n\n const length = byteLength(string, encoding) | 0;\n let buf = createBuffer(length);\n const actual = buf.write(string, encoding);\n\n if (actual !== length) {\n // Writing a hex string, for example, that contains invalid characters will\n // cause everything after the first invalid character to be ignored. (e.g.\n // 'abxxcd' will be treated as 'ab')\n buf = buf.slice(0, actual);\n }\n\n return buf;\n }\n\n function fromArrayLike(array) {\n const length = array.length < 0 ? 0 : checked(array.length) | 0;\n const buf = createBuffer(length);\n\n for (let i = 0; i < length; i += 1) {\n buf[i] = array[i] & 255;\n }\n\n return buf;\n }\n\n function fromArrayView(arrayView) {\n if (isInstance(arrayView, Uint8Array)) {\n const copy = new Uint8Array(arrayView);\n return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength);\n }\n\n return fromArrayLike(arrayView);\n }\n\n function fromArrayBuffer(array, byteOffset, length) {\n if (byteOffset < 0 || array.byteLength < byteOffset) {\n throw new RangeError(\"\\\"offset\\\" is outside of buffer bounds\");\n }\n\n if (array.byteLength < byteOffset + (length || 0)) {\n throw new RangeError(\"\\\"length\\\" is outside of buffer bounds\");\n }\n\n let buf;\n\n if (byteOffset === undefined && length === undefined) {\n buf = new Uint8Array(array);\n } else if (length === undefined) {\n buf = new Uint8Array(array, byteOffset);\n } else {\n buf = new Uint8Array(array, byteOffset, length);\n } // Return an augmented `Uint8Array` instance\n\n\n Object.setPrototypeOf(buf, Buffer.prototype);\n return buf;\n }\n\n function fromObject(obj) {\n if (Buffer.isBuffer(obj)) {\n const len = checked(obj.length) | 0;\n const buf = createBuffer(len);\n\n if (buf.length === 0) {\n return buf;\n }\n\n obj.copy(buf, 0, 0, len);\n return buf;\n }\n\n if (obj.length !== undefined) {\n if (typeof obj.length !== \"number\" || numberIsNaN(obj.length)) {\n return createBuffer(0);\n }\n\n return fromArrayLike(obj);\n }\n\n if (obj.type === \"Buffer\" && Array.isArray(obj.data)) {\n return fromArrayLike(obj.data);\n }\n }\n\n function checked(length) {\n // Note: cannot use `length < K_MAX_LENGTH` here because that fails when\n // length is NaN (which is otherwise coerced to zero.)\n if (length >= K_MAX_LENGTH) {\n throw new RangeError(\"Attempt to allocate Buffer larger than maximum \" + \"size: 0x\" + K_MAX_LENGTH.toString(16) + \" bytes\");\n }\n\n return length | 0;\n }\n\n function SlowBuffer(length) {\n if (+length != length) {\n // eslint-disable-line eqeqeq\n length = 0;\n }\n\n return Buffer.alloc(+length);\n }\n\n Buffer.isBuffer = function isBuffer(b) {\n return b != null && b._isBuffer === true && b !== Buffer.prototype; // so Buffer.isBuffer(Buffer.prototype) will be false\n };\n\n Buffer.compare = function compare(a, b) {\n if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);\n if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);\n\n if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {\n throw new TypeError(\"The \\\"buf1\\\", \\\"buf2\\\" arguments must be one of type Buffer or Uint8Array\");\n }\n\n if (a === b) return 0;\n let x = a.length;\n let y = b.length;\n\n for (let i = 0, len = Math.min(x, y); i < len; ++i) {\n if (a[i] !== b[i]) {\n x = a[i];\n y = b[i];\n break;\n }\n }\n\n if (x < y) return -1;\n if (y < x) return 1;\n return 0;\n };\n\n Buffer.isEncoding = function isEncoding(encoding) {\n switch (String(encoding).toLowerCase()) {\n case \"hex\":\n case \"utf8\":\n case \"utf-8\":\n case \"ascii\":\n case \"latin1\":\n case \"binary\":\n case \"base64\":\n case \"ucs2\":\n case \"ucs-2\":\n case \"utf16le\":\n case \"utf-16le\":\n return true;\n\n default:\n return false;\n }\n };\n\n Buffer.concat = function concat(list, length) {\n if (!Array.isArray(list)) {\n throw new TypeError(\"\\\"list\\\" argument must be an Array of Buffers\");\n }\n\n if (list.length === 0) {\n return Buffer.alloc(0);\n }\n\n let i;\n\n if (length === undefined) {\n length = 0;\n\n for (i = 0; i < list.length; ++i) {\n length += list[i].length;\n }\n }\n\n const buffer = Buffer.allocUnsafe(length);\n let pos = 0;\n\n for (i = 0; i < list.length; ++i) {\n let buf = list[i];\n\n if (isInstance(buf, Uint8Array)) {\n if (pos + buf.length > buffer.length) {\n if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);\n buf.copy(buffer, pos);\n } else {\n Uint8Array.prototype.set.call(buffer, buf, pos);\n }\n } else if (!Buffer.isBuffer(buf)) {\n throw new TypeError(\"\\\"list\\\" argument must be an Array of Buffers\");\n } else {\n buf.copy(buffer, pos);\n }\n\n pos += buf.length;\n }\n\n return buffer;\n };\n\n function byteLength(string, encoding) {\n if (Buffer.isBuffer(string)) {\n return string.length;\n }\n\n if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {\n return string.byteLength;\n }\n\n if (typeof string !== \"string\") {\n throw new TypeError(\"The \\\"string\\\" argument must be one of type string, Buffer, or ArrayBuffer. \" + \"Received type \" + typeof string);\n }\n\n const len = string.length;\n const mustMatch = arguments.length > 2 && arguments[2] === true;\n if (!mustMatch && len === 0) return 0; // Use a for loop to avoid recursion\n\n let loweredCase = false;\n\n for (;;) {\n switch (encoding) {\n case \"ascii\":\n case \"latin1\":\n case \"binary\":\n return len;\n\n case \"utf8\":\n case \"utf-8\":\n return utf8ToBytes(string).length;\n\n case \"ucs2\":\n case \"ucs-2\":\n case \"utf16le\":\n case \"utf-16le\":\n return len * 2;\n\n case \"hex\":\n return len >>> 1;\n\n case \"base64\":\n return base64ToBytes(string).length;\n\n default:\n if (loweredCase) {\n return mustMatch ? -1 : utf8ToBytes(string).length; // assume utf8\n }\n\n encoding = (\"\" + encoding).toLowerCase();\n loweredCase = true;\n }\n }\n }\n\n Buffer.byteLength = byteLength;\n\n function slowToString(encoding, start, end) {\n let loweredCase = false; // No need to verify that \"this.length <= MAX_UINT32\" since it's a read-only\n // property of a typed array.\n // This behaves neither like String nor Uint8Array in that we set start/end\n // to their upper/lower bounds if the value passed is out of range.\n // undefined is handled specially as per ECMA-262 6th Edition,\n // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.\n\n if (start === undefined || start < 0) {\n start = 0;\n } // Return early if start > this.length. Done here to prevent potential uint32\n // coercion fail below.\n\n\n if (start > this.length) {\n return \"\";\n }\n\n if (end === undefined || end > this.length) {\n end = this.length;\n }\n\n if (end <= 0) {\n return \"\";\n } // Force coercion to uint32. This will also coerce falsey/NaN values to 0.\n\n\n end >>>= 0;\n start >>>= 0;\n\n if (end <= start) {\n return \"\";\n }\n\n if (!encoding) encoding = \"utf8\";\n\n while (true) {\n switch (encoding) {\n case \"hex\":\n return hexSlice(this, start, end);\n\n case \"utf8\":\n case \"utf-8\":\n return utf8Slice(this, start, end);\n\n case \"ascii\":\n return asciiSlice(this, start, end);\n\n case \"latin1\":\n case \"binary\":\n return latin1Slice(this, start, end);\n\n case \"base64\":\n return base64Slice(this, start, end);\n\n case \"ucs2\":\n case \"ucs-2\":\n case \"utf16le\":\n case \"utf-16le\":\n return utf16leSlice(this, start, end);\n\n default:\n if (loweredCase) throw new TypeError(\"Unknown encoding: \" + encoding);\n encoding = (encoding + \"\").toLowerCase();\n loweredCase = true;\n }\n }\n } // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)\n // to detect a Buffer instance. It's not possible to use `instanceof Buffer`\n // reliably in a browserify context because there could be multiple different\n // copies of the 'buffer' package in use. This method works even for Buffer\n // instances that were created from another copy of the `buffer` package.\n // See: https://github.com/feross/buffer/issues/154\n\n\n Buffer.prototype._isBuffer = true;\n\n function swap(b, n, m) {\n const i = b[n];\n b[n] = b[m];\n b[m] = i;\n }\n\n Buffer.prototype.swap16 = function swap16() {\n const len = this.length;\n\n if (len % 2 !== 0) {\n throw new RangeError(\"Buffer size must be a multiple of 16-bits\");\n }\n\n for (let i = 0; i < len; i += 2) {\n swap(this, i, i + 1);\n }\n\n return this;\n };\n\n Buffer.prototype.swap32 = function swap32() {\n const len = this.length;\n\n if (len % 4 !== 0) {\n throw new RangeError(\"Buffer size must be a multiple of 32-bits\");\n }\n\n for (let i = 0; i < len; i += 4) {\n swap(this, i, i + 3);\n swap(this, i + 1, i + 2);\n }\n\n return this;\n };\n\n Buffer.prototype.swap64 = function swap64() {\n const len = this.length;\n\n if (len % 8 !== 0) {\n throw new RangeError(\"Buffer size must be a multiple of 64-bits\");\n }\n\n for (let i = 0; i < len; i += 8) {\n swap(this, i, i + 7);\n swap(this, i + 1, i + 6);\n swap(this, i + 2, i + 5);\n swap(this, i + 3, i + 4);\n }\n\n return this;\n };\n\n Buffer.prototype.toString = function toString() {\n const length = this.length;\n if (length === 0) return \"\";\n if (arguments.length === 0) return utf8Slice(this, 0, length);\n return slowToString.apply(this, arguments);\n };\n\n Buffer.prototype.toLocaleString = Buffer.prototype.toString;\n\n Buffer.prototype.equals = function equals(b) {\n if (!Buffer.isBuffer(b)) throw new TypeError(\"Argument must be a Buffer\");\n if (this === b) return true;\n return Buffer.compare(this, b) === 0;\n };\n\n Buffer.prototype.inspect = function inspect() {\n let str = \"\";\n const max = exports$1.INSPECT_MAX_BYTES;\n str = this.toString(\"hex\", 0, max).replace(/(.{2})/g, \"$1 \").trim();\n if (this.length > max) str += \" ... \";\n return \"<Buffer \" + str + \">\";\n };\n\n if (customInspectSymbol) {\n Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;\n }\n\n Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {\n if (isInstance(target, Uint8Array)) {\n target = Buffer.from(target, target.offset, target.byteLength);\n }\n\n if (!Buffer.isBuffer(target)) {\n throw new TypeError(\"The \\\"target\\\" argument must be one of type Buffer or Uint8Array. \" + \"Received type \" + typeof target);\n }\n\n if (start === undefined) {\n start = 0;\n }\n\n if (end === undefined) {\n end = target ? target.length : 0;\n }\n\n if (thisStart === undefined) {\n thisStart = 0;\n }\n\n if (thisEnd === undefined) {\n thisEnd = this.length;\n }\n\n if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {\n throw new RangeError(\"out of range index\");\n }\n\n if (thisStart >= thisEnd && start >= end) {\n return 0;\n }\n\n if (thisStart >= thisEnd) {\n return -1;\n }\n\n if (start >= end) {\n return 1;\n }\n\n start >>>= 0;\n end >>>= 0;\n thisStart >>>= 0;\n thisEnd >>>= 0;\n if (this === target) return 0;\n let x = thisEnd - thisStart;\n let y = end - start;\n const len = Math.min(x, y);\n const thisCopy = this.slice(thisStart, thisEnd);\n const targetCopy = target.slice(start, end);\n\n for (let i = 0; i < len; ++i) {\n if (thisCopy[i] !== targetCopy[i]) {\n x = thisCopy[i];\n y = targetCopy[i];\n break;\n }\n }\n\n if (x < y) return -1;\n if (y < x) return 1;\n return 0;\n }; // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,\n // OR the last index of `val` in `buffer` at offset <= `byteOffset`.\n //\n // Arguments:\n // - buffer - a Buffer to search\n // - val - a string, Buffer, or number\n // - byteOffset - an index into `buffer`; will be clamped to an int32\n // - encoding - an optional encoding, relevant is val is a string\n // - dir - true for indexOf, false for lastIndexOf\n\n\n function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {\n // Empty buffer means no match\n if (buffer.length === 0) return -1; // Normalize byteOffset\n\n if (typeof byteOffset === \"string\") {\n encoding = byteOffset;\n byteOffset = 0;\n } else if (byteOffset > 2147483647) {\n byteOffset = 2147483647;\n } else if (byteOffset < -2147483648) {\n byteOffset = -2147483648;\n }\n\n byteOffset = +byteOffset; // Coerce to Number.\n\n if (numberIsNaN(byteOffset)) {\n // byteOffset: it it's undefined, null, NaN, \"foo\", etc, search whole buffer\n byteOffset = dir ? 0 : buffer.length - 1;\n } // Normalize byteOffset: negative offsets start from the end of the buffer\n\n\n if (byteOffset < 0) byteOffset = buffer.length + byteOffset;\n\n if (byteOffset >= buffer.length) {\n if (dir) return -1;else byteOffset = buffer.length - 1;\n } else if (byteOffset < 0) {\n if (dir) byteOffset = 0;else return -1;\n } // Normalize val\n\n\n if (typeof val === \"string\") {\n val = Buffer.from(val, encoding);\n } // Finally, search either indexOf (if dir is true) or lastIndexOf\n\n\n if (Buffer.isBuffer(val)) {\n // Special case: looking for empty string/buffer always fails\n if (val.length === 0) {\n return -1;\n }\n\n return arrayIndexOf(buffer, val, byteOffset, encoding, dir);\n } else if (typeof val === \"number\") {\n val = val & 255; // Search for a byte value [0-255]\n\n if (typeof Uint8Array.prototype.indexOf === \"function\") {\n if (dir) {\n return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);\n } else {\n return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);\n }\n }\n\n return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);\n }\n\n throw new TypeError(\"val must be string, number or Buffer\");\n }\n\n function arrayIndexOf(arr, val, byteOffset, encoding, dir) {\n let indexSize = 1;\n let arrLength = arr.length;\n let valLength = val.length;\n\n if (encoding !== undefined) {\n encoding = String(encoding).toLowerCase();\n\n if (encoding === \"ucs2\" || encoding === \"ucs-2\" || encoding === \"utf16le\" || encoding === \"utf-16le\") {\n if (arr.length < 2 || val.length < 2) {\n return -1;\n }\n\n indexSize = 2;\n arrLength /= 2;\n valLength /= 2;\n byteOffset /= 2;\n }\n }\n\n function read(buf, i) {\n if (indexSize === 1) {\n return buf[i];\n } else {\n return buf.readUInt16BE(i * indexSize);\n }\n }\n\n let i;\n\n if (dir) {\n let foundIndex = -1;\n\n for (i = byteOffset; i < arrLength; i++) {\n if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {\n if (foundIndex === -1) foundIndex = i;\n if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;\n } else {\n if (foundIndex !== -1) i -= i - foundIndex;\n foundIndex = -1;\n }\n }\n } else {\n if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;\n\n for (i = byteOffset; i >= 0; i--) {\n let found = true;\n\n for (let j = 0; j < valLength; j++) {\n if (read(arr, i + j) !== read(val, j)) {\n found = false;\n break;\n }\n }\n\n if (found) return i;\n }\n }\n\n return -1;\n }\n\n Buffer.prototype.includes = function includes(val, byteOffset, encoding) {\n return this.indexOf(val, byteOffset, encoding) !== -1;\n };\n\n Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {\n return bidirectionalIndexOf(this, val, byteOffset, encoding, true);\n };\n\n Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {\n return bidirectionalIndexOf(this, val, byteOffset, encoding, false);\n };\n\n function hexWrite(buf, string, offset, length) {\n offset = Number(offset) || 0;\n const remaining = buf.length - offset;\n\n if (!length) {\n length = remaining;\n } else {\n length = Number(length);\n\n if (length > remaining) {\n length = remaining;\n }\n }\n\n const strLen = string.length;\n\n if (length > strLen / 2) {\n length = strLen / 2;\n }\n\n let i;\n\n for (i = 0; i < length; ++i) {\n const parsed = parseInt(string.substr(i * 2, 2), 16);\n if (numberIsNaN(parsed)) return i;\n buf[offset + i] = parsed;\n }\n\n return i;\n }\n\n function utf8Write(buf, string, offset, length) {\n return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);\n }\n\n function asciiWrite(buf, string, offset, length) {\n return blitBuffer(asciiToBytes(string), buf, offset, length);\n }\n\n function base64Write(buf, string, offset, length) {\n return blitBuffer(base64ToBytes(string), buf, offset, length);\n }\n\n function ucs2Write(buf, string, offset, length) {\n return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);\n }\n\n Buffer.prototype.write = function write(string, offset, length, encoding) {\n // Buffer#write(string)\n if (offset === undefined) {\n encoding = \"utf8\";\n length = this.length;\n offset = 0; // Buffer#write(string, encoding)\n } else if (length === undefined && typeof offset === \"string\") {\n encoding = offset;\n length = this.length;\n offset = 0; // Buffer#write(string, offset[, length][, encoding])\n } else if (isFinite(offset)) {\n offset = offset >>> 0;\n\n if (isFinite(length)) {\n length = length >>> 0;\n if (encoding === undefined) encoding = \"utf8\";\n } else {\n encoding = length;\n length = undefined;\n }\n } else {\n throw new Error(\"Buffer.write(string, encoding, offset[, length]) is no longer supported\");\n }\n\n const remaining = this.length - offset;\n if (length === undefined || length > remaining) length = remaining;\n\n if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {\n throw new RangeError(\"Attempt to write outside buffer bounds\");\n }\n\n if (!encoding) encoding = \"utf8\";\n let loweredCase = false;\n\n for (;;) {\n switch (encoding) {\n case \"hex\":\n return hexWrite(this, string, offset, length);\n\n case \"utf8\":\n case \"utf-8\":\n return utf8Write(this, string, offset, length);\n\n case \"ascii\":\n case \"latin1\":\n case \"binary\":\n return asciiWrite(this, string, offset, length);\n\n case \"base64\":\n // Warning: maxLength not taken into account in base64Write\n return base64Write(this, string, offset, length);\n\n case \"ucs2\":\n case \"ucs-2\":\n case \"utf16le\":\n case \"utf-16le\":\n return ucs2Write(this, string, offset, length);\n\n default:\n if (loweredCase) throw new TypeError(\"Unknown encoding: \" + encoding);\n encoding = (\"\" + encoding).toLowerCase();\n loweredCase = true;\n }\n }\n };\n\n Buffer.prototype.toJSON = function toJSON() {\n return {\n type: \"Buffer\",\n data: Array.prototype.slice.call(this._arr || this, 0)\n };\n };\n\n function base64Slice(buf, start, end) {\n if (start === 0 && end === buf.length) {\n return base64.fromByteArray(buf);\n } else {\n return base64.fromByteArray(buf.slice(start, end));\n }\n }\n\n function utf8Slice(buf, start, end) {\n end = Math.min(buf.length, end);\n const res = [];\n let i = start;\n\n while (i < end) {\n const firstByte = buf[i];\n let codePoint = null;\n let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;\n\n if (i + bytesPerSequence <= end) {\n let secondByte, thirdByte, fourthByte, tempCodePoint;\n\n switch (bytesPerSequence) {\n case 1:\n if (firstByte < 128) {\n codePoint = firstByte;\n }\n\n break;\n\n case 2:\n secondByte = buf[i + 1];\n\n if ((secondByte & 192) === 128) {\n tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;\n\n if (tempCodePoint > 127) {\n codePoint = tempCodePoint;\n }\n }\n\n break;\n\n case 3:\n secondByte = buf[i + 1];\n thirdByte = buf[i + 2];\n\n if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {\n tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;\n\n if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {\n codePoint = tempCodePoint;\n }\n }\n\n break;\n\n case 4:\n secondByte = buf[i + 1];\n thirdByte = buf[i + 2];\n fourthByte = buf[i + 3];\n\n if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {\n tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;\n\n if (tempCodePoint > 65535 && tempCodePoint < 1114112) {\n codePoint = tempCodePoint;\n }\n }\n\n }\n }\n\n if (codePoint === null) {\n // we did not generate a valid codePoint so insert a\n // replacement char (U+FFFD) and advance only 1 byte\n codePoint = 65533;\n bytesPerSequence = 1;\n } else if (codePoint > 65535) {\n // encode to utf16 (surrogate pair dance)\n codePoint -= 65536;\n res.push(codePoint >>> 10 & 1023 | 55296);\n codePoint = 56320 | codePoint & 1023;\n }\n\n res.push(codePoint);\n i += bytesPerSequence;\n }\n\n return decodeCodePointsArray(res);\n } // Based on http://stackoverflow.com/a/22747272/680742, the browser with\n // the lowest limit is Chrome, with 0x10000 args.\n // We go 1 magnitude less, for safety\n\n\n const MAX_ARGUMENTS_LENGTH = 4096;\n\n function decodeCodePointsArray(codePoints) {\n const len = codePoints.length;\n\n if (len <= MAX_ARGUMENTS_LENGTH) {\n return String.fromCharCode.apply(String, codePoints); // avoid extra slice()\n } // Decode in chunks to avoid \"call stack size exceeded\".\n\n\n let res = \"\";\n let i = 0;\n\n while (i < len) {\n res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));\n }\n\n return res;\n }\n\n function asciiSlice(buf, start, end) {\n let ret = \"\";\n end = Math.min(buf.length, end);\n\n for (let i = start; i < end; ++i) {\n ret += String.fromCharCode(buf[i] & 127);\n }\n\n return ret;\n }\n\n function latin1Slice(buf, start, end) {\n let ret = \"\";\n end = Math.min(buf.length, end);\n\n for (let i = start; i < end; ++i) {\n ret += String.fromCharCode(buf[i]);\n }\n\n return ret;\n }\n\n function hexSlice(buf, start, end) {\n const len = buf.length;\n if (!start || start < 0) start = 0;\n if (!end || end < 0 || end > len) end = len;\n let out = \"\";\n\n for (let i = start; i < end; ++i) {\n out += hexSliceLookupTable[buf[i]];\n }\n\n return out;\n }\n\n function utf16leSlice(buf, start, end) {\n const bytes = buf.slice(start, end);\n let res = \"\"; // If bytes.length is odd, the last 8 bits must be ignored (same as node.js)\n\n for (let i = 0; i < bytes.length - 1; i += 2) {\n res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);\n }\n\n return res;\n }\n\n Buffer.prototype.slice = function slice(start, end) {\n const len = this.length;\n start = ~~start;\n end = end === undefined ? len : ~~end;\n\n if (start < 0) {\n start += len;\n if (start < 0) start = 0;\n } else if (start > len) {\n start = len;\n }\n\n if (end < 0) {\n end += len;\n if (end < 0) end = 0;\n } else if (end > len) {\n end = len;\n }\n\n if (end < start) end = start;\n const newBuf = this.subarray(start, end); // Return an augmented `Uint8Array` instance\n\n Object.setPrototypeOf(newBuf, Buffer.prototype);\n return newBuf;\n };\n /*\n * Need to make sure that buffer isn't trying to write out of bounds.\n */\n\n\n function checkOffset(offset, ext, length) {\n if (offset % 1 !== 0 || offset < 0) throw new RangeError(\"offset is not uint\");\n if (offset + ext > length) throw new RangeError(\"Trying to access beyond buffer length\");\n }\n\n Buffer.prototype.readUintLE = Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) {\n offset = offset >>> 0;\n byteLength = byteLength >>> 0;\n if (!noAssert) checkOffset(offset, byteLength, this.length);\n let val = this[offset];\n let mul = 1;\n let i = 0;\n\n while (++i < byteLength && (mul *= 256)) {\n val += this[offset + i] * mul;\n }\n\n return val;\n };\n\n Buffer.prototype.readUintBE = Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) {\n offset = offset >>> 0;\n byteLength = byteLength >>> 0;\n\n if (!noAssert) {\n checkOffset(offset, byteLength, this.length);\n }\n\n let val = this[offset + --byteLength];\n let mul = 1;\n\n while (byteLength > 0 && (mul *= 256)) {\n val += this[offset + --byteLength] * mul;\n }\n\n return val;\n };\n\n Buffer.prototype.readUint8 = Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 1, this.length);\n return this[offset];\n };\n\n Buffer.prototype.readUint16LE = Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 2, this.length);\n return this[offset] | this[offset + 1] << 8;\n };\n\n Buffer.prototype.readUint16BE = Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 2, this.length);\n return this[offset] << 8 | this[offset + 1];\n };\n\n Buffer.prototype.readUint32LE = Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 4, this.length);\n return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;\n };\n\n Buffer.prototype.readUint32BE = Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 4, this.length);\n return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);\n };\n\n Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE(offset) {\n offset = offset >>> 0;\n validateNumber(offset, \"offset\");\n const first = this[offset];\n const last = this[offset + 7];\n\n if (first === undefined || last === undefined) {\n boundsError(offset, this.length - 8);\n }\n\n const lo = first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24;\n const hi = this[++offset] + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + last * 2 ** 24;\n return BigInt(lo) + (BigInt(hi) << BigInt(32));\n });\n Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE(offset) {\n offset = offset >>> 0;\n validateNumber(offset, \"offset\");\n const first = this[offset];\n const last = this[offset + 7];\n\n if (first === undefined || last === undefined) {\n boundsError(offset, this.length - 8);\n }\n\n const hi = first * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];\n const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last;\n return (BigInt(hi) << BigInt(32)) + BigInt(lo);\n });\n\n Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {\n offset = offset >>> 0;\n byteLength = byteLength >>> 0;\n if (!noAssert) checkOffset(offset, byteLength, this.length);\n let val = this[offset];\n let mul = 1;\n let i = 0;\n\n while (++i < byteLength && (mul *= 256)) {\n val += this[offset + i] * mul;\n }\n\n mul *= 128;\n if (val >= mul) val -= Math.pow(2, 8 * byteLength);\n return val;\n };\n\n Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) {\n offset = offset >>> 0;\n byteLength = byteLength >>> 0;\n if (!noAssert) checkOffset(offset, byteLength, this.length);\n let i = byteLength;\n let mul = 1;\n let val = this[offset + --i];\n\n while (i > 0 && (mul *= 256)) {\n val += this[offset + --i] * mul;\n }\n\n mul *= 128;\n if (val >= mul) val -= Math.pow(2, 8 * byteLength);\n return val;\n };\n\n Buffer.prototype.readInt8 = function readInt8(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 1, this.length);\n if (!(this[offset] & 128)) return this[offset];\n return (255 - this[offset] + 1) * -1;\n };\n\n Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 2, this.length);\n const val = this[offset] | this[offset + 1] << 8;\n return val & 32768 ? val | 4294901760 : val;\n };\n\n Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 2, this.length);\n const val = this[offset + 1] | this[offset] << 8;\n return val & 32768 ? val | 4294901760 : val;\n };\n\n Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 4, this.length);\n return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;\n };\n\n Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 4, this.length);\n return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];\n };\n\n Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE(offset) {\n offset = offset >>> 0;\n validateNumber(offset, \"offset\");\n const first = this[offset];\n const last = this[offset + 7];\n\n if (first === undefined || last === undefined) {\n boundsError(offset, this.length - 8);\n }\n\n const val = this[offset + 4] + this[offset + 5] * 2 ** 8 + this[offset + 6] * 2 ** 16 + (last << 24); // Overflow\n\n return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24);\n });\n Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE(offset) {\n offset = offset >>> 0;\n validateNumber(offset, \"offset\");\n const first = this[offset];\n const last = this[offset + 7];\n\n if (first === undefined || last === undefined) {\n boundsError(offset, this.length - 8);\n }\n\n const val = (first << 24) + // Overflow\n this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];\n return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last);\n });\n\n Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 4, this.length);\n return ieee754.read(this, offset, true, 23, 4);\n };\n\n Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 4, this.length);\n return ieee754.read(this, offset, false, 23, 4);\n };\n\n Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 8, this.length);\n return ieee754.read(this, offset, true, 52, 8);\n };\n\n Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 8, this.length);\n return ieee754.read(this, offset, false, 52, 8);\n };\n\n function checkInt(buf, value, offset, ext, max, min) {\n if (!Buffer.isBuffer(buf)) throw new TypeError(\"\\\"buffer\\\" argument must be a Buffer instance\");\n if (value > max || value < min) throw new RangeError(\"\\\"value\\\" argument is out of bounds\");\n if (offset + ext > buf.length) throw new RangeError(\"Index out of range\");\n }\n\n Buffer.prototype.writeUintLE = Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) {\n value = +value;\n offset = offset >>> 0;\n byteLength = byteLength >>> 0;\n\n if (!noAssert) {\n const maxBytes = Math.pow(2, 8 * byteLength) - 1;\n checkInt(this, value, offset, byteLength, maxBytes, 0);\n }\n\n let mul = 1;\n let i = 0;\n this[offset] = value & 255;\n\n while (++i < byteLength && (mul *= 256)) {\n this[offset + i] = value / mul & 255;\n }\n\n return offset + byteLength;\n };\n\n Buffer.prototype.writeUintBE = Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) {\n value = +value;\n offset = offset >>> 0;\n byteLength = byteLength >>> 0;\n\n if (!noAssert) {\n const maxBytes = Math.pow(2, 8 * byteLength) - 1;\n checkInt(this, value, offset, byteLength, maxBytes, 0);\n }\n\n let i = byteLength - 1;\n let mul = 1;\n this[offset + i] = value & 255;\n\n while (--i >= 0 && (mul *= 256)) {\n this[offset + i] = value / mul & 255;\n }\n\n return offset + byteLength;\n };\n\n Buffer.prototype.writeUint8 = Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 1, 255, 0);\n this[offset] = value & 255;\n return offset + 1;\n };\n\n Buffer.prototype.writeUint16LE = Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);\n this[offset] = value & 255;\n this[offset + 1] = value >>> 8;\n return offset + 2;\n };\n\n Buffer.prototype.writeUint16BE = Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);\n this[offset] = value >>> 8;\n this[offset + 1] = value & 255;\n return offset + 2;\n };\n\n Buffer.prototype.writeUint32LE = Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);\n this[offset + 3] = value >>> 24;\n this[offset + 2] = value >>> 16;\n this[offset + 1] = value >>> 8;\n this[offset] = value & 255;\n return offset + 4;\n };\n\n Buffer.prototype.writeUint32BE = Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);\n this[offset] = value >>> 24;\n this[offset + 1] = value >>> 16;\n this[offset + 2] = value >>> 8;\n this[offset + 3] = value & 255;\n return offset + 4;\n };\n\n function wrtBigUInt64LE(buf, value, offset, min, max) {\n checkIntBI(value, min, max, buf, offset, 7);\n let lo = Number(value & BigInt(4294967295));\n buf[offset++] = lo;\n lo = lo >> 8;\n buf[offset++] = lo;\n lo = lo >> 8;\n buf[offset++] = lo;\n lo = lo >> 8;\n buf[offset++] = lo;\n let hi = Number(value >> BigInt(32) & BigInt(4294967295));\n buf[offset++] = hi;\n hi = hi >> 8;\n buf[offset++] = hi;\n hi = hi >> 8;\n buf[offset++] = hi;\n hi = hi >> 8;\n buf[offset++] = hi;\n return offset;\n }\n\n function wrtBigUInt64BE(buf, value, offset, min, max) {\n checkIntBI(value, min, max, buf, offset, 7);\n let lo = Number(value & BigInt(4294967295));\n buf[offset + 7] = lo;\n lo = lo >> 8;\n buf[offset + 6] = lo;\n lo = lo >> 8;\n buf[offset + 5] = lo;\n lo = lo >> 8;\n buf[offset + 4] = lo;\n let hi = Number(value >> BigInt(32) & BigInt(4294967295));\n buf[offset + 3] = hi;\n hi = hi >> 8;\n buf[offset + 2] = hi;\n hi = hi >> 8;\n buf[offset + 1] = hi;\n hi = hi >> 8;\n buf[offset] = hi;\n return offset + 8;\n }\n\n Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE(value, offset = 0) {\n return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt(\"0xffffffffffffffff\"));\n });\n Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value, offset = 0) {\n return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt(\"0xffffffffffffffff\"));\n });\n\n Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n const limit = Math.pow(2, 8 * byteLength - 1);\n checkInt(this, value, offset, byteLength, limit - 1, -limit);\n }\n\n let i = 0;\n let mul = 1;\n let sub = 0;\n this[offset] = value & 255;\n\n while (++i < byteLength && (mul *= 256)) {\n if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {\n sub = 1;\n }\n\n this[offset + i] = (value / mul >> 0) - sub & 255;\n }\n\n return offset + byteLength;\n };\n\n Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n const limit = Math.pow(2, 8 * byteLength - 1);\n checkInt(this, value, offset, byteLength, limit - 1, -limit);\n }\n\n let i = byteLength - 1;\n let mul = 1;\n let sub = 0;\n this[offset + i] = value & 255;\n\n while (--i >= 0 && (mul *= 256)) {\n if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {\n sub = 1;\n }\n\n this[offset + i] = (value / mul >> 0) - sub & 255;\n }\n\n return offset + byteLength;\n };\n\n Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 1, 127, -128);\n if (value < 0) value = 255 + value + 1;\n this[offset] = value & 255;\n return offset + 1;\n };\n\n Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);\n this[offset] = value & 255;\n this[offset + 1] = value >>> 8;\n return offset + 2;\n };\n\n Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);\n this[offset] = value >>> 8;\n this[offset + 1] = value & 255;\n return offset + 2;\n };\n\n Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);\n this[offset] = value & 255;\n this[offset + 1] = value >>> 8;\n this[offset + 2] = value >>> 16;\n this[offset + 3] = value >>> 24;\n return offset + 4;\n };\n\n Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);\n if (value < 0) value = 4294967295 + value + 1;\n this[offset] = value >>> 24;\n this[offset + 1] = value >>> 16;\n this[offset + 2] = value >>> 8;\n this[offset + 3] = value & 255;\n return offset + 4;\n };\n\n Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE(value, offset = 0) {\n return wrtBigUInt64LE(this, value, offset, -BigInt(\"0x8000000000000000\"), BigInt(\"0x7fffffffffffffff\"));\n });\n Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE(value, offset = 0) {\n return wrtBigUInt64BE(this, value, offset, -BigInt(\"0x8000000000000000\"), BigInt(\"0x7fffffffffffffff\"));\n });\n\n function checkIEEE754(buf, value, offset, ext, max, min) {\n if (offset + ext > buf.length) throw new RangeError(\"Index out of range\");\n if (offset < 0) throw new RangeError(\"Index out of range\");\n }\n\n function writeFloat(buf, value, offset, littleEndian, noAssert) {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n checkIEEE754(buf, value, offset, 4);\n }\n\n ieee754.write(buf, value, offset, littleEndian, 23, 4);\n return offset + 4;\n }\n\n Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {\n return writeFloat(this, value, offset, true, noAssert);\n };\n\n Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {\n return writeFloat(this, value, offset, false, noAssert);\n };\n\n function writeDouble(buf, value, offset, littleEndian, noAssert) {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n checkIEEE754(buf, value, offset, 8);\n }\n\n ieee754.write(buf, value, offset, littleEndian, 52, 8);\n return offset + 8;\n }\n\n Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {\n return writeDouble(this, value, offset, true, noAssert);\n };\n\n Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {\n return writeDouble(this, value, offset, false, noAssert);\n }; // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)\n\n\n Buffer.prototype.copy = function copy(target, targetStart, start, end) {\n if (!Buffer.isBuffer(target)) throw new TypeError(\"argument should be a Buffer\");\n if (!start) start = 0;\n if (!end && end !== 0) end = this.length;\n if (targetStart >= target.length) targetStart = target.length;\n if (!targetStart) targetStart = 0;\n if (end > 0 && end < start) end = start; // Copy 0 bytes; we're done\n\n if (end === start) return 0;\n if (target.length === 0 || this.length === 0) return 0; // Fatal error conditions\n\n if (targetStart < 0) {\n throw new RangeError(\"targetStart out of bounds\");\n }\n\n if (start < 0 || start >= this.length) throw new RangeError(\"Index out of range\");\n if (end < 0) throw new RangeError(\"sourceEnd out of bounds\"); // Are we oob?\n\n if (end > this.length) end = this.length;\n\n if (target.length - targetStart < end - start) {\n end = target.length - targetStart + start;\n }\n\n const len = end - start;\n\n if (this === target && typeof Uint8Array.prototype.copyWithin === \"function\") {\n // Use built-in when available, missing from IE11\n this.copyWithin(targetStart, start, end);\n } else {\n Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart);\n }\n\n return len;\n }; // Usage:\n // buffer.fill(number[, offset[, end]])\n // buffer.fill(buffer[, offset[, end]])\n // buffer.fill(string[, offset[, end]][, encoding])\n\n\n Buffer.prototype.fill = function fill(val, start, end, encoding) {\n // Handle string cases:\n if (typeof val === \"string\") {\n if (typeof start === \"string\") {\n encoding = start;\n start = 0;\n end = this.length;\n } else if (typeof end === \"string\") {\n encoding = end;\n end = this.length;\n }\n\n if (encoding !== undefined && typeof encoding !== \"string\") {\n throw new TypeError(\"encoding must be a string\");\n }\n\n if (typeof encoding === \"string\" && !Buffer.isEncoding(encoding)) {\n throw new TypeError(\"Unknown encoding: \" + encoding);\n }\n\n if (val.length === 1) {\n const code = val.charCodeAt(0);\n\n if (encoding === \"utf8\" && code < 128 || encoding === \"latin1\") {\n // Fast path: If `val` fits into a single byte, use that numeric value.\n val = code;\n }\n }\n } else if (typeof val === \"number\") {\n val = val & 255;\n } else if (typeof val === \"boolean\") {\n val = Number(val);\n } // Invalid ranges are not set to a default, so can range check early.\n\n\n if (start < 0 || this.length < start || this.length < end) {\n throw new RangeError(\"Out of range index\");\n }\n\n if (end <= start) {\n return this;\n }\n\n start = start >>> 0;\n end = end === undefined ? this.length : end >>> 0;\n if (!val) val = 0;\n let i;\n\n if (typeof val === \"number\") {\n for (i = start; i < end; ++i) {\n this[i] = val;\n }\n } else {\n const bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding);\n const len = bytes.length;\n\n if (len === 0) {\n throw new TypeError(\"The value \\\"\" + val + \"\\\" is invalid for argument \\\"value\\\"\");\n }\n\n for (i = 0; i < end - start; ++i) {\n this[i + start] = bytes[i % len];\n }\n }\n\n return this;\n }; // CUSTOM ERRORS\n // =============\n // Simplified versions from Node, changed for Buffer-only usage\n\n\n const errors = {};\n\n function E(sym, getMessage, Base) {\n errors[sym] = class NodeError extends Base {\n constructor() {\n super();\n Object.defineProperty(this, \"message\", {\n value: getMessage.apply(this, arguments),\n writable: true,\n configurable: true\n }); // Add the error code to the name to include it in the stack trace.\n\n this.name = `${this.name} [${sym}]`; // Access the stack to generate the error message including the error code\n // from the name.\n\n this.stack; // eslint-disable-line no-unused-expressions\n // Reset the name to the actual name.\n\n delete this.name;\n }\n\n get code() {\n return sym;\n }\n\n set code(value) {\n Object.defineProperty(this, \"code\", {\n configurable: true,\n enumerable: true,\n value,\n writable: true\n });\n }\n\n toString() {\n return `${this.name} [${sym}]: ${this.message}`;\n }\n\n };\n }\n\n E(\"ERR_BUFFER_OUT_OF_BOUNDS\", function (name) {\n if (name) {\n return `${name} is outside of buffer bounds`;\n }\n\n return \"Attempt to access memory outside buffer bounds\";\n }, RangeError);\n E(\"ERR_INVALID_ARG_TYPE\", function (name, actual) {\n return `The \"${name}\" argument must be of type number. Received type ${typeof actual}`;\n }, TypeError);\n E(\"ERR_OUT_OF_RANGE\", function (str, range, input) {\n let msg = `The value of \"${str}\" is out of range.`;\n let received = input;\n\n if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {\n received = addNumericalSeparator(String(input));\n } else if (typeof input === \"bigint\") {\n received = String(input);\n\n if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {\n received = addNumericalSeparator(received);\n }\n\n received += \"n\";\n }\n\n msg += ` It must be ${range}. Received ${received}`;\n return msg;\n }, RangeError);\n\n function addNumericalSeparator(val) {\n let res = \"\";\n let i = val.length;\n const start = val[0] === \"-\" ? 1 : 0;\n\n for (; i >= start + 4; i -= 3) {\n res = `_${val.slice(i - 3, i)}${res}`;\n }\n\n return `${val.slice(0, i)}${res}`;\n } // CHECK FUNCTIONS\n // ===============\n\n\n function checkBounds(buf, offset, byteLength) {\n validateNumber(offset, \"offset\");\n\n if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {\n boundsError(offset, buf.length - (byteLength + 1));\n }\n }\n\n function checkIntBI(value, min, max, buf, offset, byteLength) {\n if (value > max || value < min) {\n const n = typeof min === \"bigint\" ? \"n\" : \"\";\n let range;\n\n if (byteLength > 3) {\n if (min === 0 || min === BigInt(0)) {\n range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;\n } else {\n range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` + `${(byteLength + 1) * 8 - 1}${n}`;\n }\n } else {\n range = `>= ${min}${n} and <= ${max}${n}`;\n }\n\n throw new errors.ERR_OUT_OF_RANGE(\"value\", range, value);\n }\n\n checkBounds(buf, offset, byteLength);\n }\n\n function validateNumber(value, name) {\n if (typeof value !== \"number\") {\n throw new errors.ERR_INVALID_ARG_TYPE(name, \"number\", value);\n }\n }\n\n function boundsError(value, length, type) {\n if (Math.floor(value) !== value) {\n validateNumber(value, type);\n throw new errors.ERR_OUT_OF_RANGE(type || \"offset\", \"an integer\", value);\n }\n\n if (length < 0) {\n throw new errors.ERR_BUFFER_OUT_OF_BOUNDS();\n }\n\n throw new errors.ERR_OUT_OF_RANGE(type || \"offset\", `>= ${type ? 1 : 0} and <= ${length}`, value);\n } // HELPER FUNCTIONS\n // ================\n\n\n const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;\n\n function base64clean(str) {\n // Node takes equal signs as end of the Base64 encoding\n str = str.split(\"=\")[0]; // Node strips out invalid characters like \\n and \\t from the string, base64-js does not\n\n str = str.trim().replace(INVALID_BASE64_RE, \"\"); // Node converts strings with length < 2 to ''\n\n if (str.length < 2) return \"\"; // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not\n\n while (str.length % 4 !== 0) {\n str = str + \"=\";\n }\n\n return str;\n }\n\n function utf8ToBytes(string, units) {\n units = units || Infinity;\n let codePoint;\n const length = string.length;\n let leadSurrogate = null;\n const bytes = [];\n\n for (let i = 0; i < length; ++i) {\n codePoint = string.charCodeAt(i); // is surrogate component\n\n if (codePoint > 55295 && codePoint < 57344) {\n // last char was a lead\n if (!leadSurrogate) {\n // no lead yet\n if (codePoint > 56319) {\n // unexpected trail\n if ((units -= 3) > -1) bytes.push(239, 191, 189);\n continue;\n } else if (i + 1 === length) {\n // unpaired lead\n if ((units -= 3) > -1) bytes.push(239, 191, 189);\n continue;\n } // valid lead\n\n\n leadSurrogate = codePoint;\n continue;\n } // 2 leads in a row\n\n\n if (codePoint < 56320) {\n if ((units -= 3) > -1) bytes.push(239, 191, 189);\n leadSurrogate = codePoint;\n continue;\n } // valid surrogate pair\n\n\n codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;\n } else if (leadSurrogate) {\n // valid bmp char, but last char was a lead\n if ((units -= 3) > -1) bytes.push(239, 191, 189);\n }\n\n leadSurrogate = null; // encode utf8\n\n if (codePoint < 128) {\n if ((units -= 1) < 0) break;\n bytes.push(codePoint);\n } else if (codePoint < 2048) {\n if ((units -= 2) < 0) break;\n bytes.push(codePoint >> 6 | 192, codePoint & 63 | 128);\n } else if (codePoint < 65536) {\n if ((units -= 3) < 0) break;\n bytes.push(codePoint >> 12 | 224, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);\n } else if (codePoint < 1114112) {\n if ((units -= 4) < 0) break;\n bytes.push(codePoint >> 18 | 240, codePoint >> 12 & 63 | 128, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);\n } else {\n throw new Error(\"Invalid code point\");\n }\n }\n\n return bytes;\n }\n\n function asciiToBytes(str) {\n const byteArray = [];\n\n for (let i = 0; i < str.length; ++i) {\n // Node's code seems to be doing this and not & 0x7F..\n byteArray.push(str.charCodeAt(i) & 255);\n }\n\n return byteArray;\n }\n\n function utf16leToBytes(str, units) {\n let c, hi, lo;\n const byteArray = [];\n\n for (let i = 0; i < str.length; ++i) {\n if ((units -= 2) < 0) break;\n c = str.charCodeAt(i);\n hi = c >> 8;\n lo = c % 256;\n byteArray.push(lo);\n byteArray.push(hi);\n }\n\n return byteArray;\n }\n\n function base64ToBytes(str) {\n return base64.toByteArray(base64clean(str));\n }\n\n function blitBuffer(src, dst, offset, length) {\n let i;\n\n for (i = 0; i < length; ++i) {\n if (i + offset >= dst.length || i >= src.length) break;\n dst[i + offset] = src[i];\n }\n\n return i;\n } // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass\n // the `instanceof` check but they should be treated as of that type.\n // See: https://github.com/feross/buffer/issues/166\n\n\n function isInstance(obj, type) {\n return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;\n }\n\n function numberIsNaN(obj) {\n // For IE11 support\n return obj !== obj; // eslint-disable-line no-self-compare\n } // Create lookup table for `toString('hex')`\n // See: https://github.com/feross/buffer/issues/219\n\n\n const hexSliceLookupTable = function () {\n const alphabet = \"0123456789abcdef\";\n const table = new Array(256);\n\n for (let i = 0; i < 16; ++i) {\n const i16 = i * 16;\n\n for (let j = 0; j < 16; ++j) {\n table[i16 + j] = alphabet[i] + alphabet[j];\n }\n }\n\n return table;\n }(); // Return not function with Error if BigInt not supported\n\n\n function defineBigIntMethod(fn) {\n return typeof BigInt === \"undefined\" ? BufferBigIntNotDefined : fn;\n }\n\n function BufferBigIntNotDefined() {\n throw new Error(\"BigInt not supported\");\n }\n\n return exports$1;\n}\n\nconst exports = dew();\nexports['Buffer']; exports['SlowBuffer']; exports['INSPECT_MAX_BYTES']; exports['kMaxLength'];\n\nvar Buffer = exports.Buffer;\r\nvar INSPECT_MAX_BYTES = exports.INSPECT_MAX_BYTES;\r\nvar kMaxLength = exports.kMaxLength;\n\nexport { Buffer, INSPECT_MAX_BYTES, exports as default, kMaxLength };\n", "export * from './callbacks';\nexport * from './sync';\nexport * as promises from './promises';\nexport * as constants from './constants';\nexport { initialize, getMount, getMounts, mount, umount, _toUnixTimestamp } from './shared';\n", "import { Buffer } from 'buffer';\n/**\n * Standard libc error codes. More will be added to this enum and ErrorStrings as they are\n * needed.\n * @url http://www.gnu.org/software/libc/manual/html_node/Error-Codes.html\n */\nexport enum ErrorCode {\n\tEPERM = 1,\n\tENOENT = 2,\n\tEIO = 5,\n\tEBADF = 9,\n\tEACCES = 13,\n\tEBUSY = 16,\n\tEEXIST = 17,\n\tENOTDIR = 20,\n\tEISDIR = 21,\n\tEINVAL = 22,\n\tEFBIG = 27,\n\tENOSPC = 28,\n\tEROFS = 30,\n\tENOTEMPTY = 39,\n\tENOTSUP = 95,\n}\n\n/**\n * Strings associated with each error code.\n * @internal\n */\nexport const ErrorStrings: { [code: string | number]: string } = {};\nErrorStrings[ErrorCode.EPERM] = 'Operation not permitted.';\nErrorStrings[ErrorCode.ENOENT] = 'No such file or directory.';\nErrorStrings[ErrorCode.EIO] = 'Input/output error.';\nErrorStrings[ErrorCode.EBADF] = 'Bad file descriptor.';\nErrorStrings[ErrorCode.EACCES] = 'Permission denied.';\nErrorStrings[ErrorCode.EBUSY] = 'Resource busy or locked.';\nErrorStrings[ErrorCode.EEXIST] = 'File exists.';\nErrorStrings[ErrorCode.ENOTDIR] = 'File is not a directory.';\nErrorStrings[ErrorCode.EISDIR] = 'File is a directory.';\nErrorStrings[ErrorCode.EINVAL] = 'Invalid argument.';\nErrorStrings[ErrorCode.EFBIG] = 'File is too big.';\nErrorStrings[ErrorCode.ENOSPC] = 'No space left on disk.';\nErrorStrings[ErrorCode.EROFS] = 'Cannot modify a read-only file system.';\nErrorStrings[ErrorCode.ENOTEMPTY] = 'Directory is not empty.';\nErrorStrings[ErrorCode.ENOTSUP] = 'Operation is not supported.';\n\ninterface ApiErrorJSON {\n\terrno: ErrorCode;\n\tmessage: string;\n\tpath: string;\n\tcode: string;\n\tstack: string;\n}\n\n/**\n * Represents a ZenFS error. Passed back to applications after a failed\n * call to the ZenFS API.\n */\nexport class ApiError extends Error implements NodeJS.ErrnoException {\n\tpublic static fromJSON(json: ApiErrorJSON): ApiError {\n\t\tconst err = new ApiError(json.errno, json.message, json.path);\n\t\terr.code = json.code;\n\t\terr.stack = json.stack;\n\t\treturn err;\n\t}\n\n\t/**\n\t * Creates an ApiError object from a buffer.\n\t */\n\tpublic static fromBuffer(buffer: Buffer, i: number = 0): ApiError {\n\t\treturn ApiError.fromJSON(JSON.parse(buffer.toString('utf8', i + 4, i + 4 + buffer.readUInt32LE(i))));\n\t}\n\n\tpublic static FileError(code: ErrorCode, p: string): ApiError {\n\t\treturn new ApiError(code, ErrorStrings[code], p);\n\t}\n\n\tpublic static EACCES(path: string): ApiError {\n\t\treturn this.FileError(ErrorCode.EACCES, path);\n\t}\n\n\tpublic static ENOENT(path: string): ApiError {\n\t\treturn this.FileError(ErrorCode.ENOENT, path);\n\t}\n\n\tpublic static EEXIST(path: string): ApiError {\n\t\treturn this.FileError(ErrorCode.EEXIST, path);\n\t}\n\n\tpublic static EISDIR(path: string): ApiError {\n\t\treturn this.FileError(ErrorCode.EISDIR, path);\n\t}\n\n\tpublic static ENOTDIR(path: string): ApiError {\n\t\treturn this.FileError(ErrorCode.ENOTDIR, path);\n\t}\n\n\tpublic static EPERM(path: string): ApiError {\n\t\treturn this.FileError(ErrorCode.EPERM, path);\n\t}\n\n\tpublic static ENOTEMPTY(path: string): ApiError {\n\t\treturn this.FileError(ErrorCode.ENOTEMPTY, path);\n\t}\n\n\tpublic errno: ErrorCode;\n\tpublic code: string;\n\tpublic path?: string;\n\t// Unsupported.\n\tpublic syscall: string = '';\n\tpublic stack?: string;\n\n\t/**\n\t * Represents a ZenFS error. Passed back to applications after a failed\n\t * call to the ZenFS API.\n\t *\n\t * Error codes mirror those returned by regular Unix file operations, which is\n\t * what Node returns.\n\t * @constructor ApiError\n\t * @param type The type of the error.\n\t * @param [message] A descriptive error message.\n\t */\n\tconstructor(type: ErrorCode, message: string = ErrorStrings[type], path?: string) {\n\t\tsuper(message);\n\t\tthis.errno = type;\n\t\tthis.code = ErrorCode[type];\n\t\tthis.path = path;\n\t\tthis.message = `Error: ${this.code}: ${message}${this.path ? `, '${this.path}'` : ''}`;\n\t}\n\n\t/**\n\t * @return A friendly error message.\n\t */\n\tpublic toString(): string {\n\t\treturn this.message;\n\t}\n\n\tpublic toJSON(): any {\n\t\treturn {\n\t\t\terrno: this.errno,\n\t\t\tcode: this.code,\n\t\t\tpath: this.path,\n\t\t\tstack: this.stack,\n\t\t\tmessage: this.message,\n\t\t};\n\t}\n\n\t/**\n\t * Writes the API error into a buffer.\n\t */\n\tpublic writeToBuffer(buffer: Buffer = Buffer.alloc(this.bufferSize()), i: number = 0): Buffer {\n\t\tconst bytesWritten = buffer.write(JSON.stringify(this.toJSON()), i + 4);\n\t\tbuffer.writeUInt32LE(bytesWritten, i);\n\t\treturn buffer;\n\t}\n\n\t/**\n\t * The size of the API error in buffer-form in bytes.\n\t */\n\tpublic bufferSize(): number {\n\t\t// 4 bytes for string length.\n\t\treturn 4 + Buffer.byteLength(JSON.stringify(this.toJSON()));\n\t}\n}\n", "var exports = {},\n _dewExec = false;\n\nvar _global = typeof globalThis !== \"undefined\" ? globalThis : typeof self !== \"undefined\" ? self : global;\n\nfunction dew() {\n if (_dewExec) return exports;\n _dewExec = true;\n // shim for using process in browser\n var process = exports = {}; // cached from whatever global is present so that test runners that stub it\n // don't break things. But we need to wrap it in a try catch in case it is\n // wrapped in strict mode code which doesn't define any globals. It's inside a\n // function because try/catches deoptimize in certain engines.\n\n var cachedSetTimeout;\n var cachedClearTimeout;\n\n function defaultSetTimout() {\n throw new Error(\"setTimeout has not been defined\");\n }\n\n function defaultClearTimeout() {\n throw new Error(\"clearTimeout has not been defined\");\n }\n\n (function () {\n try {\n if (typeof setTimeout === \"function\") {\n cachedSetTimeout = setTimeout;\n } else {\n cachedSetTimeout = defaultSetTimout;\n }\n } catch (e) {\n cachedSetTimeout = defaultSetTimout;\n }\n\n try {\n if (typeof clearTimeout === \"function\") {\n cachedClearTimeout = clearTimeout;\n } else {\n cachedClearTimeout = defaultClearTimeout;\n }\n } catch (e) {\n cachedClearTimeout = defaultClearTimeout;\n }\n })();\n\n function runTimeout(fun) {\n if (cachedSetTimeout === setTimeout) {\n //normal enviroments in sane situations\n return setTimeout(fun, 0);\n } // if setTimeout wasn't available but was latter defined\n\n\n if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {\n cachedSetTimeout = setTimeout;\n return setTimeout(fun, 0);\n }\n\n try {\n // when when somebody has screwed with setTimeout but no I.E. maddness\n return cachedSetTimeout(fun, 0);\n } catch (e) {\n try {\n // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally\n return cachedSetTimeout.call(null, fun, 0);\n } catch (e) {\n // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error\n return cachedSetTimeout.call(this || _global, fun, 0);\n }\n }\n }\n\n function runClearTimeout(marker) {\n if (cachedClearTimeout === clearTimeout) {\n //normal enviroments in sane situations\n return clearTimeout(marker);\n } // if clearTimeout wasn't available but was latter defined\n\n\n if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {\n cachedClearTimeout = clearTimeout;\n return clearTimeout(marker);\n }\n\n try {\n // when when somebody has screwed with setTimeout but no I.E. maddness\n return cachedClearTimeout(marker);\n } catch (e) {\n try {\n // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally\n return cachedClearTimeout.call(null, marker);\n } catch (e) {\n // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.\n // Some versions of I.E. have different rules for clearTimeout vs setTimeout\n return cachedClearTimeout.call(this || _global, marker);\n }\n }\n }\n\n var queue = [];\n var draining = false;\n var currentQueue;\n var queueIndex = -1;\n\n function cleanUpNextTick() {\n if (!draining || !currentQueue) {\n return;\n }\n\n draining = false;\n\n if (currentQueue.length) {\n queue = currentQueue.concat(queue);\n } else {\n queueIndex = -1;\n }\n\n if (queue.length) {\n drainQueue();\n }\n }\n\n function drainQueue() {\n if (draining) {\n return;\n }\n\n var timeout = runTimeout(cleanUpNextTick);\n draining = true;\n var len = queue.length;\n\n while (len) {\n currentQueue = queue;\n queue = [];\n\n while (++queueIndex < len) {\n if (currentQueue) {\n currentQueue[queueIndex].run();\n }\n }\n\n queueIndex = -1;\n len = queue.length;\n }\n\n currentQueue = null;\n draining = false;\n runClearTimeout(timeout);\n }\n\n process.nextTick = function (fun) {\n var args = new Array(arguments.length - 1);\n\n if (arguments.length > 1) {\n for (var i = 1; i < arguments.length; i++) {\n args[i - 1] = arguments[i];\n }\n }\n\n queue.push(new Item(fun, args));\n\n if (queue.length === 1 && !draining) {\n runTimeout(drainQueue);\n }\n }; // v8 likes predictible objects\n\n\n function Item(fun, array) {\n (this || _global).fun = fun;\n (this || _global).array = array;\n }\n\n Item.prototype.run = function () {\n (this || _global).fun.apply(null, (this || _global).array);\n };\n\n process.title = \"browser\";\n process.browser = true;\n process.env = {};\n process.argv = [];\n process.version = \"\"; // empty string to avoid regexp issues\n\n process.versions = {};\n\n function noop() {}\n\n process.on = noop;\n process.addListener = noop;\n process.once = noop;\n process.off = noop;\n process.removeListener = noop;\n process.removeAllListeners = noop;\n process.emit = noop;\n process.prependListener = noop;\n process.prependOnceListener = noop;\n\n process.listeners = function (name) {\n return [];\n };\n\n process.binding = function (name) {\n throw new Error(\"process.binding is not supported\");\n };\n\n process.cwd = function () {\n return \"/\";\n };\n\n process.chdir = function (dir) {\n throw new Error(\"process.chdir is not supported\");\n };\n\n process.umask = function () {\n return 0;\n };\n\n return exports;\n}\n\nvar process = dew();\n\nprocess.platform = 'browser';\nprocess.addListener;\nprocess.argv;\nprocess.binding;\nprocess.browser;\nprocess.chdir;\nprocess.cwd;\nprocess.emit;\nprocess.env;\nprocess.listeners;\nprocess.nextTick;\nprocess.off;\nprocess.on;\nprocess.once;\nprocess.prependListener;\nprocess.prependOnceListener;\nprocess.removeAllListeners;\nprocess.removeListener;\nprocess.title;\nprocess.umask;\nprocess.version;\nprocess.versions;\n\nexport { process as p };\n", "import { p as process } from './chunk-2eac56ff.js';\n\nvar exports$1 = {},\n _dewExec = false;\nfunction dew() {\n if (_dewExec) return exports$1;\n _dewExec = true;\n var process$1 = process;\n\n function assertPath(path) {\n if (typeof path !== \"string\") {\n throw new TypeError(\"Path must be a string. Received \" + JSON.stringify(path));\n }\n } // Resolves . and .. elements in a path with directory names\n\n\n function normalizeStringPosix(path, allowAboveRoot) {\n var res = \"\";\n var lastSegmentLength = 0;\n var lastSlash = -1;\n var dots = 0;\n var code;\n\n for (var i = 0; i <= path.length; ++i) {\n if (i < path.length) code = path.charCodeAt(i);else if (code === 47\n /*/*/\n ) break;else code = 47\n /*/*/\n ;\n\n if (code === 47\n /*/*/\n ) {\n if (lastSlash === i - 1 || dots === 1) ; else if (lastSlash !== i - 1 && dots === 2) {\n if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46\n /*.*/\n || res.charCodeAt(res.length - 2) !== 46\n /*.*/\n ) {\n if (res.length > 2) {\n var lastSlashIndex = res.lastIndexOf(\"/\");\n\n if (lastSlashIndex !== res.length - 1) {\n if (lastSlashIndex === -1) {\n res = \"\";\n lastSegmentLength = 0;\n } else {\n res = res.slice(0, lastSlashIndex);\n lastSegmentLength = res.length - 1 - res.lastIndexOf(\"/\");\n }\n\n lastSlash = i;\n dots = 0;\n continue;\n }\n } else if (res.length === 2 || res.length === 1) {\n res = \"\";\n lastSegmentLength = 0;\n lastSlash = i;\n dots = 0;\n continue;\n }\n }\n\n if (allowAboveRoot) {\n if (res.length > 0) res += \"/..\";else res = \"..\";\n lastSegmentLength = 2;\n }\n } else {\n if (res.length > 0) res += \"/\" + path.slice(lastSlash + 1, i);else res = path.slice(lastSlash + 1, i);\n lastSegmentLength = i - lastSlash - 1;\n }\n\n lastSlash = i;\n dots = 0;\n } else if (code === 46\n /*.*/\n && dots !== -1) {\n ++dots;\n } else {\n dots = -1;\n }\n }\n\n return res;\n }\n\n function _format(sep, pathObject) {\n var dir = pathObject.dir || pathObject.root;\n var base = pathObject.base || (pathObject.name || \"\") + (pathObject.ext || \"\");\n\n if (!dir) {\n return base;\n }\n\n if (dir === pathObject.root) {\n return dir + base;\n }\n\n return dir + sep + base;\n }\n\n var posix = {\n // path.resolve([from ...], to)\n resolve: function resolve() {\n var resolvedPath = \"\";\n var resolvedAbsolute = false;\n var cwd;\n\n for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {\n var path;\n if (i >= 0) path = arguments[i];else {\n if (cwd === undefined) cwd = process$1.cwd();\n path = cwd;\n }\n assertPath(path); // Skip empty entries\n\n if (path.length === 0) {\n continue;\n }\n\n resolvedPath = path + \"/\" + resolvedPath;\n resolvedAbsolute = path.charCodeAt(0) === 47\n /*/*/\n ;\n } // At this point the path should be resolved to a full absolute path, but\n // handle relative paths to be safe (might happen when process.cwd() fails)\n // Normalize the path\n\n\n resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);\n\n if (resolvedAbsolute) {\n if (resolvedPath.length > 0) return \"/\" + resolvedPath;else return \"/\";\n } else if (resolvedPath.length > 0) {\n return resolvedPath;\n } else {\n return \".\";\n }\n },\n normalize: function normalize(path) {\n assertPath(path);\n if (path.length === 0) return \".\";\n var isAbsolute = path.charCodeAt(0) === 47\n /*/*/\n ;\n var trailingSeparator = path.charCodeAt(path.length - 1) === 47\n /*/*/\n ; // Normalize the path\n\n path = normalizeStringPosix(path, !isAbsolute);\n if (path.length === 0 && !isAbsolute) path = \".\";\n if (path.length > 0 && trailingSeparator) path += \"/\";\n if (isAbsolute) return \"/\" + path;\n return path;\n },\n isAbsolute: function isAbsolute(path) {\n assertPath(path);\n return path.length > 0 && path.charCodeAt(0) === 47\n /*/*/\n ;\n },\n join: function join() {\n if (arguments.length === 0) return \".\";\n var joined;\n\n for (var i = 0; i < arguments.length; ++i) {\n var arg = arguments[i];\n assertPath(arg);\n\n if (arg.length > 0) {\n if (joined === undefined) joined = arg;else joined += \"/\" + arg;\n }\n }\n\n if (joined === undefined) return \".\";\n return posix.normalize(joined);\n },\n relative: function relative(from, to) {\n assertPath(from);\n assertPath(to);\n if (from === to) return \"\";\n from = posix.resolve(from);\n to = posix.resolve(to);\n if (from === to) return \"\"; // Trim any leading backslashes\n\n var fromStart = 1;\n\n for (; fromStart < from.length; ++fromStart) {\n if (from.charCodeAt(fromStart) !== 47\n /*/*/\n ) break;\n }\n\n var fromEnd = from.length;\n var fromLen = fromEnd - fromStart; // Trim any leading backslashes\n\n var toStart = 1;\n\n for (; toStart < to.length; ++toStart) {\n if (to.charCodeAt(toStart) !== 47\n /*/*/\n ) break;\n }\n\n var toEnd = to.length;\n var toLen = toEnd - toStart; // Compare paths to find the longest common path from root\n\n var length = fromLen < toLen ? fromLen : toLen;\n var lastCommonSep = -1;\n var i = 0;\n\n for (; i <= length; ++i) {\n if (i === length) {\n if (toLen > length) {\n if (to.charCodeAt(toStart + i) === 47\n /*/*/\n ) {\n // We get here if `from` is the exact base path for `to`.\n // For example: from='/foo/bar'; to='/foo/bar/baz'\n return to.slice(toStart + i + 1);\n } else if (i === 0) {\n // We get here if `from` is the root\n // For example: from='/'; to='/foo'\n return to.slice(toStart + i);\n }\n } else if (fromLen > length) {\n if (from.charCodeAt(fromStart + i) === 47\n /*/*/\n ) {\n // We get here if `to` is the exact base path for `from`.\n // For example: from='/foo/bar/baz'; to='/foo/bar'\n lastCommonSep = i;\n } else if (i === 0) {\n // We get here if `to` is the root.\n // For example: from='/foo'; to='/'\n lastCommonSep = 0;\n }\n }\n\n break;\n }\n\n var fromCode = from.charCodeAt(fromStart + i);\n var toCode = to.charCodeAt(toStart + i);\n if (fromCode !== toCode) break;else if (fromCode === 47\n /*/*/\n ) lastCommonSep = i;\n }\n\n var out = \"\"; // Generate the relative path based on the path difference between `to`\n // and `from`\n\n for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {\n if (i === fromEnd || from.charCodeAt(i) === 47\n /*/*/\n ) {\n if (out.length === 0) out += \"..\";else out += \"/..\";\n }\n } // Lastly, append the rest of the destination (`to`) path that comes after\n // the common path parts\n\n\n if (out.length > 0) return out + to.slice(toStart + lastCommonSep);else {\n toStart += lastCommonSep;\n if (to.charCodeAt(toStart) === 47\n /*/*/\n ) ++toStart;\n return to.slice(toStart);\n }\n },\n _makeLong: function _makeLong(path) {\n return path;\n },\n dirname: function dirname(path) {\n assertPath(path);\n if (path.length === 0) return \".\";\n var code = path.charCodeAt(0);\n var hasRoot = code === 47\n /*/*/\n ;\n var end = -1;\n var matchedSlash = true;\n\n for (var i = path.length - 1; i >= 1; --i) {\n code = path.charCodeAt(i);\n\n if (code === 47\n /*/*/\n ) {\n if (!matchedSlash) {\n end = i;\n break;\n }\n } else {\n // We saw the first non-path separator\n matchedSlash = false;\n }\n }\n\n if (end === -1) return hasRoot ? \"/\" : \".\";\n if (hasRoot && end === 1) return \"//\";\n return path.slice(0, end);\n },\n basename: function basename(path, ext) {\n if (ext !== undefined && typeof ext !== \"string\") throw new TypeError(\"\\\"ext\\\" argument must be a string\");\n assertPath(path);\n var start = 0;\n var end = -1;\n var matchedSlash = true;\n var i;\n\n if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {\n if (ext.length === path.length && ext === path) return \"\";\n var extIdx = ext.length - 1;\n var firstNonSlashEnd = -1;\n\n for (i = path.length - 1; i >= 0; --i) {\n var code = path.charCodeAt(i);\n\n if (code === 47\n /*/*/\n ) {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n start = i + 1;\n break;\n }\n } else {\n if (firstNonSlashEnd === -1) {\n // We saw the first non-path separator, remember this index in case\n // we need it if the extension ends up not matching\n matchedSlash = false;\n firstNonSlashEnd = i + 1;\n }\n\n if (extIdx >= 0) {\n // Try to match the explicit extension\n if (code === ext.charCodeAt(extIdx)) {\n if (--extIdx === -1) {\n // We matched the extension, so mark this as the end of our path\n // component\n end = i;\n }\n } else {\n // Extension does not match, so our result is the entire path\n // component\n extIdx = -1;\n end = firstNonSlashEnd;\n }\n }\n }\n }\n\n if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length;\n return path.slice(start, end);\n } else {\n for (i = path.length - 1; i >= 0; --i) {\n if (path.charCodeAt(i) === 47\n /*/*/\n ) {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n start = i + 1;\n break;\n }\n } else if (end === -1) {\n // We saw the first non-path separator, mark this as the end of our\n // path component\n matchedSlash = false;\n end = i + 1;\n }\n }\n\n if (end === -1) return \"\";\n return path.slice(start, end);\n }\n },\n extname: function extname(path) {\n assertPath(path);\n var startDot = -1;\n var startPart = 0;\n var end = -1;\n var matchedSlash = true; // Track the state of characters (if any) we see before our first dot and\n // after any path separator we find\n\n var preDotState = 0;\n\n for (var i = path.length - 1; i >= 0; --i) {\n var code = path.charCodeAt(i);\n\n if (code === 47\n /*/*/\n ) {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n startPart = i + 1;\n break;\n }\n\n continue;\n }\n\n if (end === -1) {\n // We saw the first non-path separator, mark this as the end of our\n // extension\n matchedSlash = false;\n end = i + 1;\n }\n\n if (code === 46\n /*.*/\n ) {\n // If this is our first dot, mark it as the start of our extension\n if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1;\n } else if (startDot !== -1) {\n // We saw a non-dot and non-path separator before our dot, so we should\n // have a good chance at having a non-empty extension\n preDotState = -1;\n }\n }\n\n if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot\n preDotState === 0 || // The (right-most) trimmed path component is exactly '..'\n preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {\n return \"\";\n }\n\n return path.slice(startDot, end);\n },\n format: function format(pathObject) {\n if (pathObject === null || typeof pathObject !== \"object\") {\n throw new TypeError(\"The \\\"pathObject\\\" argument must be of type Object. Received type \" + typeof pathObject);\n }\n\n return _format(\"/\", pathObject);\n },\n parse: function parse(path) {\n assertPath(path);\n var ret = {\n root: \"\",\n dir: \"\",\n base: \"\",\n ext: \"\",\n name: \"\"\n };\n if (path.length === 0) return ret;\n var code = path.charCodeAt(0);\n var isAbsolute = code === 47\n /*/*/\n ;\n var start;\n\n if (isAbsolute) {\n ret.root = \"/\";\n start = 1;\n } else {\n start = 0;\n }\n\n var startDot = -1;\n var startPart = 0;\n var end = -1;\n var matchedSlash = true;\n var i = path.length - 1; // Track the state of characters (if any) we see before our first dot and\n // after any path separator we find\n\n var preDotState = 0; // Get non-dir info\n\n for (; i >= start; --i) {\n code = path.charCodeAt(i);\n\n if (code === 47\n /*/*/\n ) {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n startPart = i + 1;\n break;\n }\n\n continue;\n }\n\n if (end === -1) {\n // We saw the first non-path separator, mark this as the end of our\n // extension\n matchedSlash = false;\n end = i + 1;\n }\n\n if (code === 46\n /*.*/\n ) {\n // If this is our first dot, mark it as the start of our extension\n if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1;\n } else if (startDot !== -1) {\n // We saw a non-dot and non-path separator before our dot, so we should\n // have a good chance at having a non-empty extension\n preDotState = -1;\n }\n }\n\n if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot\n preDotState === 0 || // The (right-most) trimmed path component is exactly '..'\n preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {\n if (end !== -1) {\n if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end);\n }\n } else {\n if (startPart === 0 && isAbsolute) {\n ret.name = path.slice(1, startDot);\n ret.base = path.slice(1, end);\n } else {\n ret.name = path.slice(startPart, startDot);\n ret.base = path.slice(startPart, end);\n }\n\n ret.ext = path.slice(startDot, end);\n }\n\n if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = \"/\";\n return ret;\n },\n sep: \"/\",\n delimiter: \":\",\n win32: null,\n posix: null\n };\n posix.posix = posix;\n exports$1 = posix;\n return exports$1;\n}\n\nconst exports = dew();\n\nexport { exports as e };\n", "import { e as exports } from './chunk-23dbec7b.js';\nexport { e as default } from './chunk-23dbec7b.js';\nimport './chunk-2eac56ff.js';\n\nvar _makeLong = exports._makeLong;\r\nvar basename = exports.basename;\r\nvar delimiter = exports.delimiter;\r\nvar dirname = exports.dirname;\r\nvar extname = exports.extname;\r\nvar format = exports.format;\r\nvar isAbsolute = exports.isAbsolute;\r\nvar join = exports.join;\r\nvar normalize = exports.normalize;\r\nvar parse = exports.parse;\r\nvar posix = exports.posix;\r\nvar relative = exports.relative;\r\nvar resolve = exports.resolve;\r\nvar sep = exports.sep;\r\nvar win32 = exports.win32;\n\nexport { _makeLong, basename, delimiter, dirname, extname, format, isAbsolute, join, normalize, parse, posix, relative, resolve, sep, win32 };\n", "/*\nFS Constants\nSee https://nodejs.org/api/fs.html#file-access-constants\n*/\n\n// File Access Constants\n\n/** Constant for fs.access(). File is visible to the calling process. */\nexport const F_OK = 0;\n\n/** Constant for fs.access(). File can be read by the calling process. */\nexport const R_OK = 4;\n\n/** Constant for fs.access(). File can be written by the calling process. */\nexport const W_OK = 2;\n\n/** Constant for fs.access(). File can be executed by the calling process. */\nexport const X_OK = 1;\n\n// File Copy Constants\n\n/** Constant for fs.copyFile. Flag indicating the destination file should not be overwritten if it already exists. */\nexport const COPYFILE_EXCL = 1;\n\n/**\n * Constant for fs.copyFile. Copy operation will attempt to create a copy-on-write reflink.\n * If the underlying platform does not support copy-on-write, then a fallback copy mechanism is used.\n */\nexport const COPYFILE_FICLONE = 2;\n\n/**\n * Constant for fs.copyFile. Copy operation will attempt to create a copy-on-write reflink.\n * If the underlying platform does not support copy-on-write, then the operation will fail with an error.\n */\nexport const COPYFILE_FICLONE_FORCE = 4;\n\n// File Open Constants\n\n/** Constant for fs.open(). Flag indicating to open a file for read-only access. */\nexport const O_RDONLY = 0;\n\n/** Constant for fs.open(). Flag indicating to open a file for write-only access. */\nexport const O_WRONLY = 1;\n\n/** Constant for fs.open(). Flag indicating to open a file for read-write access. */\nexport const O_RDWR = 2;\n\n/** Constant for fs.open(). Flag indicating to create the file if it does not already exist. */\nexport const O_CREAT = 0o100; // Node internal is\n\n/** Constant for fs.open(). Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists. */\nexport const O_EXCL = 0o200;\n\n/**\n * Constant for fs.open(). Flag indicating that if path identifies a terminal device,\n * opening the path shall not cause that terminal to become the controlling terminal for the process\n * (if the process does not already have one).\n */\nexport const O_NOCTTY = 0o400;\n\n/** Constant for fs.open(). Flag indicating that if the file exists and is a regular file, and the file is opened successfully for write access, its length shall be truncated to zero. */\nexport const O_TRUNC = 0o1000;\n\n/** Constant for fs.open(). Flag indicating that data will be appended to the end of the file. */\nexport const O_APPEND = 0o2000;\n\n/** Constant for fs.open(). Flag indicating that the open should fail if the path is not a directory. */\nexport const O_DIRECTORY = 0o200000;\n\n/**\n * constant for fs.open().\n * Flag indicating reading accesses to the file system will no longer result in\n * an update to the atime information associated with the file.\n * This flag is available on Linux operating systems only.\n */\nexport const O_NOATIME = 0o1000000;\n\n/** Constant for fs.open(). Flag indicating that the open should fail if the path is a symbolic link. */\nexport const O_NOFOLLOW = 0o400000;\n\n/** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O. */\nexport const O_SYNC = 0o4010000;\n\n/** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O with write operations waiting for data integrity. */\nexport const O_DSYNC = 0o10000;\n\n/** Constant for fs.open(). Flag indicating to open the symbolic link itself rather than the resource it is pointing to. */\nexport const O_SYMLINK = 0o100000;\n\n/** Constant for fs.open(). When set, an attempt will be made to minimize caching effects of file I/O. */\nexport const O_DIRECT = 0o40000;\n\n/** Constant for fs.open(). Flag indicating to open the file in nonblocking mode when possible. */\nexport const O_NONBLOCK = 0o4000;\n\n// File Type Constants\n\n/** Constant for fs.Stats mode property for determining a file's type. Bit mask used to extract the file type code. */\nexport const S_IFMT = 0o170000;\n\n/** Constant for fs.Stats mode property for determining a file's type. File type constant for a regular file. */\nexport const S_IFREG = 0o100000;\n\n/** Constant for fs.Stats mode property for determining a file's type. File type constant for a directory. */\nexport const S_IFDIR = 0o40000;\n\n/** Constant for fs.Stats mode property for determining a file's type. File type constant for a character-oriented device file. */\nexport const S_IFCHR = 0o20000;\n\n/** Constant for fs.Stats mode property for determining a file's type. File type constant for a block-oriented device file. */\nexport const S_IFBLK = 0o60000;\n\n/** Constant for fs.Stats mode property for determining a file's type. File type constant for a FIFO/pipe. */\nexport const S_IFIFO = 0o10000;\n\n/** Constant for fs.Stats mode property for determining a file's type. File type constant for a symbolic link. */\nexport const S_IFLNK = 0o120000;\n\n/** Constant for fs.Stats mode property for determining a file's type. File type constant for a socket. */\nexport const S_IFSOCK = 0o140000;\n\n// File Mode Constants\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by owner. */\nexport const S_IRWXU = 0o700;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by owner. */\nexport const S_IRUSR = 0o400;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by owner. */\nexport const S_IWUSR = 0o200;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by owner. */\nexport const S_IXUSR = 0o100;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by group. */\nexport const S_IRWXG = 0o70;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by group. */\nexport const S_IRGRP = 0o40;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by group. */\nexport const S_IWGRP = 0o20;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by group. */\nexport const S_IXGRP = 0o10;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by others. */\nexport const S_IRWXO = 7;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by others. */\nexport const S_IROTH = 4;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by others. */\nexport const S_IWOTH = 2;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by others. */\nexport const S_IXOTH = 1;\n", "/**\n * Credentials used for FS ops.\n * Similar to Linux's cred struct. See https://github.com/torvalds/linux/blob/master/include/linux/cred.h\n */\nexport class Cred {\n\tconstructor(public uid: number, public gid: number, public suid: number, public sgid: number, public euid: number, public egid: number) {}\n\n\tpublic static Root = new Cred(0, 0, 0, 0, 0, 0);\n}\n", "import type { StatsBase } from 'fs';\nimport { Cred } from './cred';\nimport { Buffer } from 'buffer';\nimport { S_IFDIR, S_IFLNK, S_IFMT, S_IFREG } from './emulation/constants';\n\n/**\n * Indicates the type of the given file. Applied to 'mode'.\n */\nexport enum FileType {\n\tFILE = S_IFREG,\n\tDIRECTORY = S_IFDIR,\n\tSYMLINK = S_IFLNK,\n}\n\n/**\n * Implementation of Node's `Stats`.\n *\n * Attribute descriptions are from `man 2 stat'\n * @see http://nodejs.org/api/fs.html#fs_class_fs_stats\n * @see http://man7.org/linux/man-pages/man2/stat.2.html\n */\nexport class Stats implements StatsBase<number> {\n\tpublic static fromBuffer(buffer: Buffer): Stats {\n\t\tconst size = buffer.readUInt32LE(0),\n\t\t\tmode = buffer.readUInt32LE(4),\n\t\t\tatime = buffer.readDoubleLE(8),\n\t\t\tmtime = buffer.readDoubleLE(16),\n\t\t\tctime = buffer.readDoubleLE(24),\n\t\t\tuid = buffer.readUInt32LE(32),\n\t\t\tgid = buffer.readUInt32LE(36);\n\n\t\treturn new Stats(mode & S_IFMT, size, mode & ~S_IFMT, atime, mtime, ctime, uid, gid);\n\t}\n\n\t/**\n\t * Clones the stats object.\n\t */\n\tpublic static clone(s: Stats): Stats {\n\t\treturn new Stats(s.mode & S_IFMT, s.size, s.mode & ~S_IFMT, s.atimeMs, s.mtimeMs, s.ctimeMs, s.uid, s.gid, s.birthtimeMs);\n\t}\n\n\tpublic blocks: number;\n\tpublic mode: number;\n\t// ID of device containing file\n\tpublic dev: number = 0;\n\t// inode number\n\tpublic ino: number = 0;\n\t// device ID (if special file)\n\tpublic rdev: number = 0;\n\t// number of hard links\n\tpublic nlink: number = 1;\n\t// blocksize for file system I/O\n\tpublic blksize: number = 4096;\n\t// user ID of owner\n\tpublic uid: number = 0;\n\t// group ID of owner\n\tpublic gid: number = 0;\n\t// Some file systems stash data on stats objects.\n\tpublic fileData: Buffer | null = null;\n\tpublic atimeMs: number;\n\tpublic mtimeMs: number;\n\tpublic ctimeMs: number;\n\tpublic birthtimeMs: number;\n\tpublic size: number;\n\n\tpublic get atime(): Date {\n\t\treturn new Date(this.atimeMs);\n\t}\n\n\tpublic get mtime(): Date {\n\t\treturn new Date(this.mtimeMs);\n\t}\n\n\tpublic get ctime(): Date {\n\t\treturn new Date(this.ctimeMs);\n\t}\n\n\tpublic get birthtime(): Date {\n\t\treturn new Date(this.birthtimeMs);\n\t}\n\n\t/**\n\t * Provides information about a particular entry in the file system.\n\t * @param itemType Type of the item (FILE, DIRECTORY, SYMLINK, or SOCKET)\n\t * @param size Size of the item in bytes. For directories/symlinks,\n\t * this is normally the size of the struct that represents the item.\n\t * @param mode Unix-style file mode (e.g. 0o644)\n\t * @param atimeMs time of last access, in milliseconds since epoch\n\t * @param mtimeMs time of last modification, in milliseconds since epoch\n\t * @param ctimeMs time of last time file status was changed, in milliseconds since epoch\n\t * @param uid the id of the user that owns the file\n\t * @param gid the id of the group that owns the file\n\t * @param birthtimeMs time of file creation, in milliseconds since epoch\n\t */\n\tconstructor(itemType: FileType, size: number, mode?: number, atimeMs?: number, mtimeMs?: number, ctimeMs?: number, uid?: number, gid?: number, birthtimeMs?: number) {\n\t\tthis.size = size;\n\t\tlet currentTime = 0;\n\t\tif (typeof atimeMs !== 'number') {\n\t\t\tcurrentTime = Date.now();\n\t\t\tatimeMs = currentTime;\n\t\t}\n\t\tif (typeof mtimeMs !== 'number') {\n\t\t\tif (!currentTime) {\n\t\t\t\tcurrentTime = Date.now();\n\t\t\t}\n\t\t\tmtimeMs = currentTime;\n\t\t}\n\t\tif (typeof ctimeMs !== 'number') {\n\t\t\tif (!currentTime) {\n\t\t\t\tcurrentTime = Date.now();\n\t\t\t}\n\t\t\tctimeMs = currentTime;\n\t\t}\n\t\tif (typeof birthtimeMs !== 'number') {\n\t\t\tif (!currentTime) {\n\t\t\t\tcurrentTime = Date.now();\n\t\t\t}\n\t\t\tbirthtimeMs = currentTime;\n\t\t}\n\t\tif (typeof uid !== 'number') {\n\t\t\tuid = 0;\n\t\t}\n\t\tif (typeof gid !== 'number') {\n\t\t\tgid = 0;\n\t\t}\n\t\tthis.atimeMs = atimeMs;\n\t\tthis.ctimeMs = ctimeMs;\n\t\tthis.mtimeMs = mtimeMs;\n\t\tthis.birthtimeMs = birthtimeMs;\n\n\t\tif (!mode) {\n\t\t\tswitch (itemType) {\n\t\t\t\tcase FileType.FILE:\n\t\t\t\t\tthis.mode = 0o644;\n\t\t\t\t\tbreak;\n\t\t\t\tcase FileType.DIRECTORY:\n\t\t\t\tdefault:\n\t\t\t\t\tthis.mode = 0o777;\n\t\t\t}\n\t\t} else {\n\t\t\tthis.mode = mode;\n\t\t}\n\t\t// number of 512B blocks allocated\n\t\tthis.blocks = Math.ceil(size / 512);\n\t\t// Check if mode also includes top-most bits, which indicate the file's\n\t\t// type.\n\t\tif ((this.mode & S_IFMT) == 0) {\n\t\t\tthis.mode |= itemType;\n\t\t}\n\t}\n\n\tpublic toBuffer(): Buffer {\n\t\tconst buffer = Buffer.alloc(32);\n\t\tbuffer.writeUInt32LE(this.size, 0);\n\t\tbuffer.writeUInt32LE(this.mode, 4);\n\t\tbuffer.writeDoubleLE(this.atime.getTime(), 8);\n\t\tbuffer.writeDoubleLE(this.mtime.getTime(), 16);\n\t\tbuffer.writeDoubleLE(this.ctime.getTime(), 24);\n\t\tbuffer.writeUInt32LE(this.uid, 32);\n\t\tbuffer.writeUInt32LE(this.gid, 36);\n\t\treturn buffer;\n\t}\n\n\t/**\n\t * @return [Boolean] True if this item is a file.\n\t */\n\tpublic isFile(): boolean {\n\t\treturn (this.mode & S_IFMT) === S_IFREG;\n\t}\n\n\t/**\n\t * @return [Boolean] True if this item is a directory.\n\t */\n\tpublic isDirectory(): boolean {\n\t\treturn (this.mode & S_IFMT) === S_IFDIR;\n\t}\n\n\t/**\n\t * @return [Boolean] True if this item is a symbolic link (only valid through lstat)\n\t */\n\tpublic isSymbolicLink(): boolean {\n\t\treturn (this.mode & S_IFMT) === S_IFLNK;\n\t}\n\n\t/**\n\t * Checks if a given user/group has access to this item\n\t * @param mode The request access as 4 bits (unused, read, write, execute)\n\t * @param uid The requesting UID\n\t * @param gid The requesting GID\n\t * @returns [Boolean] True if the request has access, false if the request does not\n\t */\n\tpublic hasAccess(mode: number, cred: Cred): boolean {\n\t\tif (cred.euid === 0 || cred.egid === 0) {\n\t\t\t//Running as root\n\t\t\treturn true;\n\t\t}\n\t\tconst perms = this.mode & ~S_IFMT;\n\t\tlet uMode = 0xf,\n\t\t\tgMode = 0xf,\n\t\t\twMode = 0xf;\n\n\t\tif (cred.euid == this.uid) {\n\t\t\tconst uPerms = (0xf00 & perms) >> 8;\n\t\t\tuMode = (mode ^ uPerms) & mode;\n\t\t}\n\t\tif (cred.egid == this.gid) {\n\t\t\tconst gPerms = (0xf0 & perms) >> 4;\n\t\t\tgMode = (mode ^ gPerms) & mode;\n\t\t}\n\t\tconst wPerms = 0xf & perms;\n\t\twMode = (mode ^ wPerms) & mode;\n\t\t/*\n Result = 0b0xxx (read, write, execute)\n If any bits are set that means the request does not have that permission.\n */\n\t\tconst result = uMode & gMode & wMode;\n\t\treturn !result;\n\t}\n\n\t/**\n\t * Convert the current stats object into a cred object\n\t */\n\tpublic getCred(uid: number = this.uid, gid: number = this.gid): Cred {\n\t\treturn new Cred(uid, gid, this.uid, this.gid, uid, gid);\n\t}\n\n\t/**\n\t * Change the mode of the file. We use this helper function to prevent messing\n\t * up the type of the file, which is encoded in mode.\n\t */\n\tpublic chmod(mode: number): void {\n\t\tthis.mode = (this.mode & S_IFMT) | mode;\n\t}\n\n\t/**\n\t * Change the owner user/group of the file.\n\t * This function makes sure it is a valid UID/GID (that is, a 32 unsigned int)\n\t */\n\tpublic chown(uid: number, gid: number): void {\n\t\tif (!isNaN(+uid) && 0 <= +uid && +uid < 2 ** 32) {\n\t\t\tthis.uid = uid;\n\t\t}\n\t\tif (!isNaN(+gid) && 0 <= +gid && +gid < 2 ** 32) {\n\t\t\tthis.gid = gid;\n\t\t}\n\t}\n\n\t// We don't support the following types of files.\n\n\tpublic isSocket(): boolean {\n\t\treturn false;\n\t}\n\n\tpublic isBlockDevice(): boolean {\n\t\treturn false;\n\t}\n\n\tpublic isCharacterDevice(): boolean {\n\t\treturn false;\n\t}\n\n\tpublic isFIFO(): boolean {\n\t\treturn false;\n\t}\n}\n", "import { ApiError, ErrorCode } from './ApiError';\nimport { Stats } from './stats';\nimport { FileSystem } from './filesystem';\nimport { getMount } from './emulation/shared';\nimport { Buffer } from 'buffer';\n\nexport enum ActionType {\n\t// Indicates that the code should not do anything.\n\tNOP = 0,\n\t// Indicates that the code should throw an exception.\n\tTHROW_EXCEPTION = 1,\n\t// Indicates that the code should truncate the file, but only if it is a file.\n\tTRUNCATE_FILE = 2,\n\t// Indicates that the code should create the file.\n\tCREATE_FILE = 3,\n}\n\n/**\n * Represents one of the following file flags. A convenience object.\n *\n * * `'r'` - Open file for reading. An exception occurs if the file does not exist.\n * * `'r+'` - Open file for reading and writing. An exception occurs if the file does not exist.\n * * `'rs'` - Open file for reading in synchronous mode. Instructs the filesystem to not cache writes.\n * * `'rs+'` - Open file for reading and writing, and opens the file in synchronous mode.\n * * `'w'` - Open file for writing. The file is created (if it does not exist) or truncated (if it exists).\n * * `'wx'` - Like 'w' but opens the file in exclusive mode.\n * * `'w+'` - Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).\n * * `'wx+'` - Like 'w+' but opens the file in exclusive mode.\n * * `'a'` - Open file for appending. The file is created if it does not exist.\n * * `'ax'` - Like 'a' but opens the file in exclusive mode.\n * * `'a+'` - Open file for reading and appending. The file is created if it does not exist.\n * * `'ax+'` - Like 'a+' but opens the file in exclusive mode.\n *\n * Exclusive mode ensures that the file path is newly created.\n */\nexport class FileFlag {\n\t// Contains cached FileMode instances.\n\tprivate static flagCache: Map<string, FileFlag> = new Map();\n\t// Array of valid mode strings.\n\tprivate static validFlagStrs = ['r', 'r+', 'rs', 'rs+', 'w', 'wx', 'w+', 'wx+', 'a', 'ax', 'a+', 'ax+'];\n\n\t/**\n\t * Get an object representing the given file flag.\n\t * @param modeStr The string representing the flag\n\t * @return The FileFlag object representing the flag\n\t * @throw when the flag string is invalid\n\t */\n\tpublic static getFileFlag(flagStr: string): FileFlag {\n\t\t// Check cache first.\n\t\tif (!FileFlag.flagCache.has(flagStr)) {\n\t\t\tFileFlag.flagCache.set(flagStr, new FileFlag(flagStr));\n\t\t}\n\t\treturn FileFlag.flagCache.get(flagStr);\n\t}\n\n\tprivate flagStr: string;\n\t/**\n\t * This should never be called directly.\n\t * @param modeStr The string representing the mode\n\t * @throw when the mode string is invalid\n\t */\n\tconstructor(flagStr: string) {\n\t\tthis.flagStr = flagStr;\n\t\tif (FileFlag.validFlagStrs.indexOf(flagStr) < 0) {\n\t\t\tthrow new ApiError(ErrorCode.EINVAL, 'Invalid flag: ' + flagStr);\n\t\t}\n\t}\n\n\t/**\n\t * Get the underlying flag string for this flag.\n\t */\n\tpublic getFlagString(): string {\n\t\treturn this.flagStr;\n\t}\n\n\t/**\n\t * Get the equivalent mode (0b0xxx: read, write, execute)\n\t * Note: Execute will always be 0\n\t */\n\tpublic getMode(): number {\n\t\tlet mode = 0;\n\t\tmode <<= 1;\n\t\tmode += +this.isReadable();\n\t\tmode <<= 1;\n\t\tmode += +this.isWriteable();\n\t\tmode <<= 1;\n\t\treturn mode;\n\t}\n\n\t/**\n\t * Returns true if the file is readable.\n\t */\n\tpublic isReadable(): boolean {\n\t\treturn this.flagStr.indexOf('r') !== -1 || this.flagStr.indexOf('+') !== -1;\n\t}\n\t/**\n\t * Returns true if the file is writeable.\n\t */\n\tpublic isWriteable(): boolean {\n\t\treturn this.flagStr.indexOf('w') !== -1 || this.flagStr.indexOf('a') !== -1 || this.flagStr.indexOf('+') !== -1;\n\t}\n\t/**\n\t * Returns true if the file mode should truncate.\n\t */\n\tpublic isTruncating(): boolean {\n\t\treturn this.flagStr.indexOf('w') !== -1;\n\t}\n\t/**\n\t * Returns true if the file is appendable.\n\t */\n\tpublic isAppendable(): boolean {\n\t\treturn this.flagStr.indexOf('a') !== -1;\n\t}\n\t/**\n\t * Returns true if the file is open in synchronous mode.\n\t */\n\tpublic isSynchronous(): boolean {\n\t\treturn this.flagStr.indexOf('s') !== -1;\n\t}\n\t/**\n\t * Returns true if the file is open in exclusive mode.\n\t */\n\tpublic isExclusive(): boolean {\n\t\treturn this.flagStr.indexOf('x') !== -1;\n\t}\n\t/**\n\t * Returns one of the static fields on this object that indicates the\n\t * appropriate response to the path existing.\n\t */\n\tpublic pathExistsAction(): ActionType {\n\t\tif (this.isExclusive()) {\n\t\t\treturn ActionType.THROW_EXCEPTION;\n\t\t} else if (this.isTruncating()) {\n\t\t\treturn ActionType.TRUNCATE_FILE;\n\t\t} else {\n\t\t\treturn ActionType.NOP;\n\t\t}\n\t}\n\t/**\n\t * Returns one of the static fields on this object that indicates the\n\t * appropriate response to the path not existing.\n\t */\n\tpublic pathNotExistsAction(): ActionType {\n\t\tif ((this.isWriteable() || this.isAppendable()) && this.flagStr !== 'r+') {\n\t\t\treturn ActionType.CREATE_FILE;\n\t\t} else {\n\t\t\treturn ActionType.THROW_EXCEPTION;\n\t\t}\n\t}\n}\n\nexport interface File {\n\t/**\n\t * **Core**: Get the current file position.\n\t */\n\tgetPos(): number | undefined;\n\t/**\n\t * **Core**: Asynchronous `stat`.\n\t */\n\tstat(): Promise<Stats>;\n\t/**\n\t * **Core**: Synchronous `stat`.\n\t */\n\tstatSync(): Stats;\n\t/**\n\t * **Core**: Asynchronous close.\n\t */\n\tclose(): Promise<void>;\n\t/**\n\t * **Core**: Synchronous close.\n\t */\n\tcloseSync(): void;\n\t/**\n\t * **Core**: Asynchronous truncate.\n\t */\n\ttruncate(len: number): Promise<void>;\n\t/**\n\t * **Core**: Synchronous truncate.\n\t */\n\ttruncateSync(len: number): void;\n\t/**\n\t * **Core**: Asynchronous sync.\n\t */\n\tsync(): Promise<void>;\n\t/**\n\t * **Core**: Synchronous sync.\n\t */\n\tsyncSync(): void;\n\t/**\n\t * **Core**: Write buffer to the file.\n\t * Note that it is unsafe to use fs.write multiple times on the same file\n\t * without waiting for the callback.\n\t * @param buffer Buffer containing the data to write to\n\t * the file.\n\t * @param offset Offset in the buffer to start reading data from.\n\t * @param length The amount of bytes to write to the file.\n\t * @param position Offset from the beginning of the file where this\n\t * data should be written. If position is null, the data will be written at\n\t * the current position.\n\t * @returns Promise resolving to the new length of the buffer\n\t */\n\twrite(buffer: Buffer, offset: number, length: number, position: number | null): Promise<number>;\n\t/**\n\t * **Core**: Write buffer to the file.\n\t * Note that it is unsafe to use fs.writeSync multiple times on the same file\n\t * without waiting for it to return.\n\t * @param buffer Buffer containing the data to write to\n\t * the file.\n\t * @param offset Offset in the buffer to start reading data from.\n\t * @param length The amount of bytes to write to the file.\n\t * @param position Offset from the beginning of the file where this\n\t * data should be written. If position is null, the data will be written at\n\t * the current position.\n\t */\n\twriteSync(buffer: Buffer, offset: number, length: number, position: number | null): number;\n\t/**\n\t * **Core**: Read data from the file.\n\t * @param buffer The buffer that the data will be\n\t * written to.\n\t * @param offset The offset within the buffer where writing will\n\t * start.\n\t * @param length An integer specifying the number of bytes to read.\n\t * @param position An integer specifying where to begin reading from\n\t * in the file. If position is null, data will be read from the current file\n\t * position.\n\t * @returns Promise resolving to the new length of the buffer\n\t */\n\tread(buffer: Buffer, offset: number, length: number, position: number | null): Promise<{ bytesRead: number; buffer: Buffer }>;\n\t/**\n\t * **Core**: Read data from the file.\n\t * @param buffer The buffer that the data will be written to.\n\t * @param offset The offset within the buffer where writing will start.\n\t * @param length An integer specifying the number of bytes to read.\n\t * @param position An integer specifying where to begin reading from\n\t * in the file. If position is null, data will be read from the current file\n\t * position.\n\t */\n\treadSync(buffer: Buffer, offset: number, length: number, position: number): number;\n\t/**\n\t * **Supplementary**: Asynchronous `datasync`.\n\t *\n\t * Default implementation maps to `sync`.\n\t */\n\tdatasync(): Promise<void>;\n\t/**\n\t * **Supplementary**: Synchronous `datasync`.\n\t *\n\t * Default implementation maps to `syncSync`.\n\t */\n\tdatasyncSync(): void;\n\t/**\n\t * **Optional**: Asynchronous `chown`.\n\t */\n\tchown(uid: number, gid: number): Promise<void>;\n\t/**\n\t * **Optional**: Synchronous `chown`.\n\t */\n\tchownSync(uid: number, gid: number): void;\n\t/**\n\t * **Optional**: Asynchronous `fchmod`.\n\t */\n\tchmod(mode: number): Promise<void>;\n\t/**\n\t * **Optional**: Synchronous `fchmod`.\n\t */\n\tchmodSync(mode: number): void;\n\t/**\n\t * **Optional**: Change the file timestamps of the file.\n\t */\n\tutimes(atime: Date, mtime: Date): Promise<void>;\n\t/**\n\t * **Optional**: Change the file timestamps of the file.\n\t */\n\tutimesSync(atime: Date, mtime: Date): void;\n}\n\n/**\n * Base class that contains shared implementations of functions for the file\n * object.\n */\nexport class BaseFile {\n\tpublic async sync(): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic syncSync(): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async datasync(): Promise<void> {\n\t\treturn this.sync();\n\t}\n\tpublic datasyncSync(): void {\n\t\treturn this.syncSync();\n\t}\n\tpublic async chown(uid: number, gid: number): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic chownSync(uid: number, gid: number): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async chmod(mode: number): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic chmodSync(mode: number): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async utimes(atime: Date, mtime: Date): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic utimesSync(atime: Date, mtime: Date): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n}\n\n/**\n * An implementation of the File interface that operates on a file that is\n * completely in-memory. PreloadFiles are backed by a Buffer.\n *\n * This is also an abstract class, as it lacks an implementation of 'sync' and\n * 'close'. Each filesystem that wishes to use this file representation must\n * extend this class and implement those two methods.\n * @todo 'close' lever that disables functionality once closed.\n */\nexport class PreloadFile<T extends FileSystem> extends BaseFile {\n\tprotected _fs: T;\n\tprotected _pos: number = 0;\n\tprotected _path: string;\n\tprotected _stat: Stats;\n\tprotected _flag: FileFlag;\n\tprotected _buffer: Buffer;\n\tprotected _dirty: boolean = false;\n\t/**\n\t * Creates a file with the given path and, optionally, the given contents. Note\n\t * that, if contents is specified, it will be mutated by the file!\n\t * @param _fs The file system that created the file.\n\t * @param _path\n\t * @param _mode The mode that the file was opened using.\n\t * Dictates permissions and where the file pointer starts.\n\t * @param _stat The stats object for the given file.\n\t * PreloadFile will mutate this object. Note that this object must contain\n\t * the appropriate mode that the file was opened as.\n\t * @param contents A buffer containing the entire\n\t * contents of the file. PreloadFile will mutate this buffer. If not\n\t * specified, we assume it is a new file.\n\t */\n\tconstructor(_fs: T, _path: string, _flag: FileFlag, _stat: Stats, contents?: Buffer) {\n\t\tsuper();\n\t\tthis._fs = _fs;\n\t\tthis._path = _path;\n\t\tthis._flag = _flag;\n\t\tthis._stat = _stat;\n\t\tthis._buffer = contents ? contents : Buffer.alloc(0);\n\t\t// Note: This invariant is *not* maintained once the file starts getting\n\t\t// modified.\n\t\t// Note: Only actually matters if file is readable, as writeable modes may\n\t\t// truncate/append to file.\n\t\tif (this._stat.size !== this._buffer.length && this._flag.isReadable()) {\n\t\t\tthrow new Error(`Invalid buffer: Buffer is ${this._buffer.length} long, yet Stats object specifies that file is ${this._stat.size} long.`);\n\t\t}\n\t}\n\n\t/**\n\t * NONSTANDARD: Get the underlying buffer for this file. !!DO NOT MUTATE!! Will mess up dirty tracking.\n\t */\n\tpublic getBuffer(): Buffer {\n\t\treturn this._buffer;\n\t}\n\n\t/**\n\t * NONSTANDARD: Get underlying stats for this file. !!DO NOT MUTATE!!\n\t */\n\tpublic getStats(): Stats {\n\t\treturn this._stat;\n\t}\n\n\tpublic getFlag(): FileFlag {\n\t\treturn this._flag;\n\t}\n\n\t/**\n\t * Get the path to this file.\n\t * @return [String] The path to the file.\n\t */\n\tpublic getPath(): string {\n\t\treturn this._path;\n\t}\n\n\t/**\n\t * Get the current file position.\n\t *\n\t * We emulate the following bug mentioned in the Node documentation:\n\t * > On Linux, positional writes don't work when the file is opened in append\n\t * mode. The kernel ignores the position argument and always appends the data\n\t * to the end of the file.\n\t * @return [Number] The current file position.\n\t */\n\tpublic getPos(): number {\n\t\tif (this._flag.isAppendable()) {\n\t\t\treturn this._stat.size;\n\t\t}\n\t\treturn this._pos;\n\t}\n\n\t/**\n\t * Advance the current file position by the indicated number of positions.\n\t * @param [Number] delta\n\t */\n\tpublic advancePos(delta: number): number {\n\t\treturn (this._pos += delta);\n\t}\n\n\t/**\n\t * Set the file position.\n\t * @param [Number] newPos\n\t */\n\tpublic setPos(newPos: number): number {\n\t\treturn (this._pos = newPos);\n\t}\n\n\t/**\n\t * **Core**: Asynchronous sync. Must be implemented by subclasses of this\n\t * class.\n\t * @param [Function(ZenFS.ApiError)] cb\n\t */\n\tpublic async sync(): Promise<void> {\n\t\tthis.syncSync();\n\t}\n\n\t/**\n\t * **Core**: Synchronous sync.\n\t */\n\tpublic syncSync(): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\n\t/**\n\t * **Core**: Asynchronous close. Must be implemented by subclasses of this\n\t * class.\n\t * @param [Function(ZenFS.ApiError)] cb\n\t */\n\tpublic async close(): Promise<void> {\n\t\tthis.closeSync();\n\t}\n\n\t/**\n\t * **Core**: Synchronous close.\n\t */\n\tpublic closeSync(): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\n\t/**\n\t * Asynchronous `stat`.\n\t * @param [Function(ZenFS.ApiError, ZenFS.node.fs.Stats)] cb\n\t */\n\tpublic async stat(): Promise<Stats> {\n\t\treturn Stats.clone(this._stat);\n\t}\n\n\t/**\n\t * Synchronous `stat`.\n\t */\n\tpublic statSync(): Stats {\n\t\treturn Stats.clone(this._stat);\n\t}\n\n\t/**\n\t * Asynchronous truncate.\n\t * @param [Number] len\n\t * @param [Function(ZenFS.ApiError)] cb\n\t */\n\tpublic truncate(len: number): Promise<void> {\n\t\tthis.truncateSync(len);\n\t\tif (this._flag.isSynchronous() && !getMount('/')!.metadata.synchronous) {\n\t\t\treturn this.sync();\n\t\t}\n\t}\n\n\t/**\n\t * Synchronous truncate.\n\t * @param [Number] len\n\t */\n\tpublic truncateSync(len: number): void {\n\t\tthis._dirty = true;\n\t\tif (!this._flag.isWriteable()) {\n\t\t\tthrow new ApiError(ErrorCode.EPERM, 'File not opened with a writeable mode.');\n\t\t}\n\t\tthis._stat.mtimeMs = Date.now();\n\t\tif (len > this._buffer.length) {\n\t\t\tconst buf = Buffer.alloc(len - this._buffer.length, 0);\n\t\t\t// Write will set @_stat.size for us.\n\t\t\tthis.writeSync(buf, 0, buf.length, this._buffer.length);\n\t\t\tif (this._flag.isSynchronous() && getMount('/')!.metadata.synchronous) {\n\t\t\t\tthis.syncSync();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tthis._stat.size = len;\n\t\t// Truncate buffer to 'len'.\n\t\tconst newBuff = Buffer.alloc(len);\n\t\tthis._buffer.copy(newBuff, 0, 0, len);\n\t\tthis._buffer = newBuff;\n\t\tif (this._flag.isSynchronous() && getMount('/')!.metadata.synchronous) {\n\t\t\tthis.syncSync();\n\t\t}\n\t}\n\n\t/**\n\t * Write buffer to the file.\n\t * Note that it is unsafe to use fs.write multiple times on the same file\n\t * without waiting for the callback.\n\t * @param [ZenFS.node.Buffer] buffer Buffer containing the data to write to\n\t * the file.\n\t * @param [Number] offset Offset in the buffer to start reading data from.\n\t * @param [Number] length The amount of bytes to write to the file.\n\t * @param [Number] position Offset from the beginning of the file where this\n\t * data should be written. If position is null, the data will be written at\n\t * the current position.\n\t * @param [Function(ZenFS.ApiError, Number, ZenFS.node.Buffer)]\n\t * cb The number specifies the number of bytes written into the file.\n\t */\n\tpublic async write(buffer: Buffer, offset: number, length: number, position: number): Promise<number> {\n\t\treturn this.writeSync(buffer, offset, length, position);\n\t}\n\n\t/**\n\t * Write buffer to the file.\n\t * Note that it is unsafe to use fs.writeSync multiple times on the same file\n\t * without waiting for the callback.\n\t * @param [ZenFS.node.Buffer] buffer Buffer containing the data to write to\n\t * the file.\n\t * @param [Number] offset Offset in the buffer to start reading data from.\n\t * @param [Number] length The amount of bytes to write to the file.\n\t * @param [Number] position Offset from the beginning of the file where this\n\t * data should be written. If position is null, the data will be written at\n\t * the current position.\n\t * @return [Number]\n\t */\n\tpublic writeSync(buffer: Buffer, offset: number, length: number, position: number): number {\n\t\tthis._dirty = true;\n\t\tif (position === undefined || position === null) {\n\t\t\tposition = this.getPos();\n\t\t}\n\t\tif (!this._flag.isWriteable()) {\n\t\t\tthrow new ApiError(ErrorCode.EPERM, 'File not opened with a writeable mode.');\n\t\t}\n\t\tconst endFp = position + length;\n\t\tif (endFp > this._stat.size) {\n\t\t\tthis._stat.size = endFp;\n\t\t\tif (endFp > this._buffer.length) {\n\t\t\t\t// Extend the buffer!\n\t\t\t\tconst newBuff = Buffer.alloc(endFp);\n\t\t\t\tthis._buffer.copy(newBuff);\n\t\t\t\tthis._buffer = newBuff;\n\t\t\t}\n\t\t}\n\t\tconst len = buffer.copy(this._buffer, position, offset, offset + length);\n\t\tthis._stat.mtimeMs = Date.now();\n\t\tif (this._flag.isSynchronous()) {\n\t\t\tthis.syncSync();\n\t\t\treturn len;\n\t\t}\n\t\tthis.setPos(position + len);\n\t\treturn len;\n\t}\n\n\t/**\n\t * Read data from the file.\n\t * @param [ZenFS.node.Buffer] buffer The buffer that the data will be\n\t * written to.\n\t * @param [Number] offset The offset within the buffer where writing will\n\t * start.\n\t * @param [Number] length An integer specifying the number of bytes to read.\n\t * @param [Number] position An integer specifying where to begin reading from\n\t * in the file. If position is null, data will be read from the current file\n\t * position.\n\t * @param [Function(ZenFS.ApiError, Number, ZenFS.node.Buffer)] cb The\n\t * number is the number of bytes read\n\t */\n\tpublic async read(buffer: Buffer, offset: number, length: number, position: number): Promise<{ bytesRead: number; buffer: Buffer }> {\n\t\treturn { bytesRead: this.readSync(buffer, offset, length, position), buffer };\n\t}\n\n\t/**\n\t * Read data from the file.\n\t * @param [ZenFS.node.Buffer] buffer The buffer that the data will be\n\t * written to.\n\t * @param [Number] offset The offset within the buffer where writing will\n\t * start.\n\t * @param [Number] length An integer specifying the number of bytes to read.\n\t * @param [Number] position An integer specifying where to begin reading from\n\t * in the file. If position is null, data will be read from the current file\n\t * position.\n\t * @return [Number]\n\t */\n\tpublic readSync(buffer: Buffer, offset: number, length: number, position: number): number {\n\t\tif (!this._flag.isReadable()) {\n\t\t\tthrow new ApiError(ErrorCode.EPERM, 'File not opened with a readable mode.');\n\t\t}\n\t\tif (position === undefined || position === null) {\n\t\t\tposition = this.getPos();\n\t\t}\n\t\tconst endRead = position + length;\n\t\tif (endRead > this._stat.size) {\n\t\t\tlength = this._stat.size - position;\n\t\t}\n\t\tconst rv = this._buffer.copy(buffer, offset, position, position + length);\n\t\tthis._stat.atimeMs = Date.now();\n\t\tthis._pos = position + length;\n\t\treturn rv;\n\t}\n\n\t/**\n\t * Asynchronous `fchmod`.\n\t * @param [Number|String] mode\n\t */\n\tpublic async chmod(mode: number): Promise<void> {\n\t\tthis.chmodSync(mode);\n\t}\n\n\t/**\n\t * Synchronous `fchmod`.\n\t * @param [Number] mode\n\t */\n\tpublic chmodSync(mode: number): void {\n\t\tif (!this._fs.metadata.supportsProperties) {\n\t\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t\t}\n\t\tthis._dirty = true;\n\t\tthis._stat.chmod(mode);\n\t\tthis.syncSync();\n\t}\n\n\t/**\n\t * Asynchronous `fchown`.\n\t * @param [Number] uid\n\t * @param [Number] gid\n\t */\n\tpublic async chown(uid: number, gid: number): Promise<void> {\n\t\tthis.chownSync(uid, gid);\n\t}\n\n\t/**\n\t * Synchronous `fchown`.\n\t * @param [Number] uid\n\t * @param [Number] gid\n\t */\n\tpublic chownSync(uid: number, gid: number): void {\n\t\tif (!this._fs.metadata.supportsProperties) {\n\t\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t\t}\n\t\tthis._dirty = true;\n\t\tthis._stat.chown(uid, gid);\n\t\tthis.syncSync();\n\t}\n\n\tprotected isDirty(): boolean {\n\t\treturn this._dirty;\n\t}\n\n\t/**\n\t * Resets the dirty bit. Should only be called after a sync has completed successfully.\n\t */\n\tprotected resetDirty() {\n\t\tthis._dirty = false;\n\t}\n}\n\n/**\n * File class for the InMemory and XHR file systems.\n * Doesn't sync to anything, so it works nicely for memory-only files.\n */\nexport class NoSyncFile<T extends FileSystem> extends PreloadFile<T> implements File {\n\tconstructor(_fs: T, _path: string, _flag: FileFlag, _stat: Stats, contents?: Buffer) {\n\t\tsuper(_fs, _path, _flag, _stat, contents);\n\t}\n\t/**\n\t * Asynchronous sync. Doesn't do anything, simply calls the cb.\n\t * @param [Function(ZenFS.ApiError)] cb\n\t */\n\tpublic async sync(): Promise<void> {\n\t\treturn;\n\t}\n\t/**\n\t * Synchronous sync. Doesn't do anything.\n\t */\n\tpublic syncSync(): void {\n\t\t// NOP.\n\t}\n\t/**\n\t * Asynchronous close. Doesn't do anything, simply calls the cb.\n\t * @param [Function(ZenFS.ApiError)] cb\n\t */\n\tpublic async close(): Promise<void> {\n\t\treturn;\n\t}\n\t/**\n\t * Synchronous close. Doesn't do anything.\n\t */\n\tpublic closeSync(): void {\n\t\t// NOP.\n\t}\n}\n", "/* eslint-disable @typescript-eslint/no-unused-vars */\n// disable no-unused-vars since BaseFileSystem uses them a lot\n\nimport { ApiError, ErrorCode } from './ApiError';\nimport { Stats } from './stats';\nimport { File, FileFlag, ActionType } from './file';\nimport * as path from 'path';\nimport { Cred } from './cred';\nimport { Buffer } from 'buffer';\n\nexport type BFSOneArgCallback = (e?: ApiError) => unknown;\nexport type BFSCallback<T> = (e?: ApiError, rv?: T) => unknown;\nexport type BFSThreeArgCallback<T, U> = (e?: ApiError, arg1?: T, arg2?: U) => unknown;\n\nexport type FileContents = Buffer | string;\n\n/**\n * Metadata about a FileSystem\n */\nexport interface FileSystemMetadata {\n\t/**\n\t * The name of the FS\n\t */\n\tname: string;\n\n\t/**\n\t * Wheter the FS is readonly or not\n\t */\n\treadonly: boolean;\n\n\t/**\n\t * Does the FS support synchronous operations\n\t */\n\tsynchronous: boolean;\n\n\t/**\n\t * Does the FS support properties\n\t */\n\tsupportsProperties: boolean;\n\n\t/**\n\t * Does the FS support links\n\t */\n\tsupportsLinks: boolean;\n\n\t/**\n\t * The total space\n\t */\n\ttotalSpace: number;\n\n\t/**\n\t * The available space\n\t */\n\tfreeSpace: number;\n}\n\n/**\n * Structure for a filesystem. **All** ZenFS FileSystems must implement\n * this.\n *\n * ### Argument Assumptions\n *\n * You can assume the following about arguments passed to each API method:\n *\n * - Every path is an absolute path. `.`, `..`, and other items\n * are resolved into an absolute form.\n * - All arguments are present. Any optional arguments at the Node API level\n * have been passed in with their default values.\n */\nexport abstract class FileSystem {\n\tstatic readonly Name: string;\n\n\tabstract readonly metadata: FileSystemMetadata;\n\n\tconstructor(options?: object) {\n\t\t// unused\n\t}\n\n\tabstract whenReady(): Promise<this>;\n\n\t// File or directory operations\n\t/**\n\t * Asynchronous access.\n\t */\n\tabstract access(p: string, mode: number, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous access.\n\t */\n\tabstract accessSync(p: string, mode: number, cred: Cred): void;\n\t/**\n\t * Asynchronous rename. No arguments other than a possible exception\n\t * are given to the completion callback.\n\t */\n\tabstract rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous rename.\n\t */\n\tabstract renameSync(oldPath: string, newPath: string, cred: Cred): void;\n\t/**\n\t * Asynchronous `stat`.\n\t */\n\tabstract stat(p: string, cred: Cred): Promise<Stats>;\n\t/**\n\t * Synchronous `stat`.\n\t */\n\tabstract statSync(p: string, cred: Cred): Stats;\n\t// File operations\n\t/**\n\t * Asynchronous file open.\n\t * @see http://www.manpagez.com/man/2/open/\n\t * @param flags Handles the complexity of the various file\n\t * modes. See its API for more details.\n\t * @param mode Mode to use to open the file. Can be ignored if the\n\t * filesystem doesn't support permissions.\n\t */\n\tabstract open(p: string, flag: FileFlag, mode: number, cred: Cred): Promise<File>;\n\t/**\n\t * Synchronous file open.\n\t * @see http://www.manpagez.com/man/2/open/\n\t * @param flags Handles the complexity of the various file\n\t * modes. See its API for more details.\n\t * @param mode Mode to use to open the file. Can be ignored if the\n\t * filesystem doesn't support permissions.\n\t */\n\tabstract openSync(p: string, flag: FileFlag, mode: number, cred: Cred): File;\n\t/**\n\t * Asynchronous `unlink`.\n\t */\n\tabstract unlink(p: string, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous `unlink`.\n\t */\n\tabstract unlinkSync(p: string, cred: Cred): void;\n\t// Directory operations\n\t/**\n\t * Asynchronous `rmdir`.\n\t */\n\tabstract rmdir(p: string, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous `rmdir`.\n\t */\n\tabstract rmdirSync(p: string, cred: Cred): void;\n\t/**\n\t * Asynchronous `mkdir`.\n\t * @param mode Mode to make the directory using. Can be ignored if\n\t * the filesystem doesn't support permissions.\n\t */\n\tabstract mkdir(p: string, mode: number, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous `mkdir`.\n\t * @param mode Mode to make the directory using. Can be ignored if\n\t * the filesystem doesn't support permissions.\n\t */\n\tabstract mkdirSync(p: string, mode: number, cred: Cred): void;\n\t/**\n\t * Asynchronous `readdir`. Reads the contents of a directory.\n\t *\n\t * The callback gets two arguments `(err, files)` where `files` is an array of\n\t * the names of the files in the directory excluding `'.'` and `'..'`.\n\t */\n\tabstract readdir(p: string, cred: Cred): Promise<string[]>;\n\t/**\n\t * Synchronous `readdir`. Reads the contents of a directory.\n\t */\n\tabstract readdirSync(p: string, cred: Cred): string[];\n\t// **SUPPLEMENTAL INTERFACE METHODS**\n\t// File or directory operations\n\t/**\n\t * Test whether or not the given path exists by checking with\n\t * the file system. Then call the callback argument with either true or false.\n\t */\n\tabstract exists(p: string, cred: Cred): Promise<boolean>;\n\t/**\n\t * Test whether or not the given path exists by checking with\n\t * the file system.\n\t */\n\tabstract existsSync(p: string, cred: Cred): boolean;\n\t/**\n\t * Asynchronous `realpath`. The callback gets two arguments\n\t * `(err, resolvedPath)`.\n\t *\n\t * Note that the Node API will resolve `path` to an absolute path.\n\t * @param cache An object literal of mapped paths that can be used to\n\t * force a specific path resolution or avoid additional `fs.stat` calls for\n\t * known real paths. If not supplied by the user, it'll be an empty object.\n\t */\n\tabstract realpath(p: string, cred: Cred): Promise<string>;\n\t/**\n\t * Synchronous `realpath`.\n\t *\n\t * Note that the Node API will resolve `path` to an absolute path.\n\t * @param cache An object literal of mapped paths that can be used to\n\t * force a specific path resolution or avoid additional `fs.stat` calls for\n\t * known real paths. If not supplied by the user, it'll be an empty object.\n\t */\n\tabstract realpathSync(p: string, cred: Cred): string;\n\t// File operations\n\t/**\n\t * Asynchronous `truncate`.\n\t */\n\tabstract truncate(p: string, len: number, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous `truncate`.\n\t */\n\tabstract truncateSync(p: string, len: number, cred: Cred): void;\n\t/**\n\t * Asynchronously reads the entire contents of a file.\n\t * @param encoding If non-null, the file's contents should be decoded\n\t * into a string using that encoding. Otherwise, if encoding is null, fetch\n\t * the file's contents as a Buffer.\n\t * If no encoding is specified, then the raw buffer is returned.\n\t */\n\tabstract readFile(fname: string, encoding: BufferEncoding | null, flag: FileFlag, cred: Cred): Promise<FileContents>;\n\t/**\n\t * Synchronously reads the entire contents of a file.\n\t * @param encoding If non-null, the file's contents should be decoded\n\t * into a string using that encoding. Otherwise, if encoding is null, fetch\n\t * the file's contents as a Buffer.\n\t */\n\tabstract readFileSync(fname: string, encoding: BufferEncoding | null, flag: FileFlag, cred: Cred): FileContents;\n\t/**\n\t * Asynchronously writes data to a file, replacing the file\n\t * if it already exists.\n\t *\n\t * The encoding option is ignored if data is a buffer.\n\t */\n\tabstract writeFile(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronously writes data to a file, replacing the file\n\t * if it already exists.\n\t *\n\t * The encoding option is ignored if data is a buffer.\n\t */\n\tabstract writeFileSync(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): void;\n\t/**\n\t * Asynchronously append data to a file, creating the file if\n\t * it not yet exists.\n\t */\n\tabstract appendFile(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronously append data to a file, creating the file if\n\t * it not yet exists.\n\t */\n\tabstract appendFileSync(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): void;\n\t// **OPTIONAL INTERFACE METHODS**\n\t// Property operations\n\t// This isn't always possible on some filesystem types (e.g. Dropbox).\n\t/**\n\t * Asynchronous `chmod`.\n\t */\n\tabstract chmod(p: string, mode: number, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous `chmod`.\n\t */\n\tabstract chmodSync(p: string, mode: number, cred: Cred): void;\n\t/**\n\t * Asynchronous `chown`.\n\t */\n\tabstract chown(p: string, new_uid: number, new_gid: number, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous `chown`.\n\t */\n\tabstract chownSync(p: string, new_uid: number, new_gid: number, cred: Cred): void;\n\t/**\n\t * Change file timestamps of the file referenced by the supplied\n\t * path.\n\t */\n\tabstract utimes(p: string, atime: Date, mtime: Date, cred: Cred): Promise<void>;\n\t/**\n\t * Change file timestamps of the file referenced by the supplied\n\t * path.\n\t */\n\tabstract utimesSync(p: string, atime: Date, mtime: Date, cred: Cred): void;\n\t// Symlink operations\n\t// Symlinks aren't always supported.\n\t/**\n\t * Asynchronous `link`.\n\t */\n\tabstract link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous `link`.\n\t */\n\tabstract linkSync(srcpath: string, dstpath: string, cred: Cred): void;\n\t/**\n\t * Asynchronous `symlink`.\n\t * @param type can be either `'dir'` or `'file'`\n\t */\n\tabstract symlink(srcpath: string, dstpath: string, type: string, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous `symlink`.\n\t * @param type can be either `'dir'` or `'file'`\n\t */\n\tabstract symlinkSync(srcpath: string, dstpath: string, type: string, cred: Cred): void;\n\t/**\n\t * Asynchronous readlink.\n\t */\n\tabstract readlink(p: string, cred: Cred): Promise<string>;\n\t/**\n\t * Synchronous readlink.\n\t */\n\tabstract readlinkSync(p: string, cred: Cred): string;\n}\n\n/**\n * Basic filesystem class. Most filesystems should extend this class, as it\n * provides default implementations for a handful of methods.\n */\nexport class BaseFileSystem extends FileSystem {\n\tstatic readonly Name: string = this.name;\n\n\tprotected _ready: Promise<this> = Promise.resolve(this);\n\n\tpublic constructor(options?: { [key: string]: unknown }) {\n\t\tsuper();\n\t}\n\n\tpublic get metadata(): FileSystemMetadata {\n\t\treturn {\n\t\t\tname: this.constructor.name,\n\t\t\treadonly: false,\n\t\t\tsynchronous: false,\n\t\t\tsupportsProperties: false,\n\t\t\tsupportsLinks: false,\n\t\t\ttotalSpace: 0,\n\t\t\tfreeSpace: 0,\n\t\t};\n\t}\n\n\tpublic whenReady(): Promise<this> {\n\t\treturn this._ready;\n\t}\n\n\t/**\n\t * Opens the file at path p with the given flag. The file must exist.\n\t * @param p The path to open.\n\t * @param flag The flag to use when opening the file.\n\t */\n\tpublic async openFile(p: string, flag: FileFlag, cred: Cred): Promise<File> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\t/**\n\t * Create the file at path p with the given mode. Then, open it with the given\n\t * flag.\n\t */\n\tpublic async createFile(p: string, flag: FileFlag, mode: number, cred: Cred): Promise<File> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async open(p: string, flag: FileFlag, mode: number, cred: Cred): Promise<File> {\n\t\ttry {\n\t\t\tconst stats = await this.stat(p, cred);\n\t\t\tswitch (flag.pathExistsAction()) {\n\t\t\t\tcase ActionType.THROW_EXCEPTION:\n\t\t\t\t\tthrow ApiError.EEXIST(p);\n\t\t\t\tcase ActionType.TRUNCATE_FILE:\n\t\t\t\t\t// NOTE: In a previous implementation, we deleted the file and\n\t\t\t\t\t// re-created it. However, this created a race condition if another\n\t\t\t\t\t// asynchronous request was trying to read the file, as the file\n\t\t\t\t\t// would not exist for a small period of time.\n\t\t\t\t\tconst fd = await this.openFile(p, flag, cred);\n\t\t\t\t\tif (!fd) throw new Error('BFS has reached an impossible code path; please file a bug.');\n\n\t\t\t\t\tawait fd.truncate(0);\n\t\t\t\t\tawait fd.sync();\n\t\t\t\t\treturn fd;\n\t\t\t\tcase ActionType.NOP:\n\t\t\t\t\treturn this.openFile(p, flag, cred);\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');\n\t\t\t}\n\t\t\t// File exists.\n\t\t} catch (e) {\n\t\t\t// File does not exist.\n\t\t\tswitch (flag.pathNotExistsAction()) {\n\t\t\t\tcase ActionType.CREATE_FILE:\n\t\t\t\t\t// Ensure parent exists.\n\t\t\t\t\tconst parentStats = await this.stat(path.dirname(p), cred);\n\t\t\t\t\tif (parentStats && !parentStats.isDirectory()) {\n\t\t\t\t\t\tthrow ApiError.ENOTDIR(path.dirname(p));\n\t\t\t\t\t}\n\t\t\t\t\treturn this.createFile(p, flag, mode, cred);\n\t\t\t\tcase ActionType.THROW_EXCEPTION:\n\t\t\t\t\tthrow ApiError.ENOENT(p);\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');\n\t\t\t}\n\t\t}\n\t}\n\tpublic async access(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic accessSync(p: string, mode: number, cred: Cred): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async rename(oldPath: string, newPath: string, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic renameSync(oldPath: string, newPath: string, cred: Cred): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async stat(p: string, cred: Cred): Promise<Stats> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic statSync(p: string, cred: Cred): Stats {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\t/**\n\t * Opens the file at path p with the given flag. The file must exist.\n\t * @param p The path to open.\n\t * @param flag The flag to use when opening the file.\n\t * @return A File object corresponding to the opened file.\n\t */\n\tpublic openFileSync(p: string, flag: FileFlag, cred: Cred): File {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\t/**\n\t * Create the file at path p with the given mode. Then, open it with the given\n\t * flag.\n\t */\n\tpublic createFileSync(p: string, flag: FileFlag, mode: number, cred: Cred): File {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic openSync(p: string, flag: FileFlag, mode: number, cred: Cred): File {\n\t\t// Check if the path exists, and is a file.\n\t\tlet stats: Stats;\n\t\ttry {\n\t\t\tstats = this.statSync(p, cred);\n\t\t} catch (e) {\n\t\t\t// File does not exist.\n\t\t\tswitch (flag.pathNotExistsAction()) {\n\t\t\t\tcase ActionType.CREATE_FILE:\n\t\t\t\t\t// Ensure parent exists.\n\t\t\t\t\tconst parentStats = this.statSync(path.dirname(p), cred);\n\t\t\t\t\tif (!parentStats.isDirectory()) {\n\t\t\t\t\t\tthrow ApiError.ENOTDIR(path.dirname(p));\n\t\t\t\t\t}\n\t\t\t\t\treturn this.createFileSync(p, flag, mode, cred);\n\t\t\t\tcase ActionType.THROW_EXCEPTION:\n\t\t\t\t\tthrow ApiError.ENOENT(p);\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');\n\t\t\t}\n\t\t}\n\t\tif (!stats.hasAccess(mode, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\n\t\t// File exists.\n\t\tswitch (flag.pathExistsAction()) {\n\t\t\tcase ActionType.THROW_EXCEPTION:\n\t\t\t\tthrow ApiError.EEXIST(p);\n\t\t\tcase ActionType.TRUNCATE_FILE:\n\t\t\t\t// Delete file.\n\t\t\t\tthis.unlinkSync(p, cred);\n\t\t\t\t// Create file. Use the same mode as the old file.\n\t\t\t\t// Node itself modifies the ctime when this occurs, so this action\n\t\t\t\t// will preserve that behavior if the underlying file system\n\t\t\t\t// supports those properties.\n\t\t\t\treturn this.createFileSync(p, flag, stats.mode, cred);\n\t\t\tcase ActionType.NOP:\n\t\t\t\treturn this.openFileSync(p, flag, cred);\n\t\t\tdefault:\n\t\t\t\tthrow new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');\n\t\t}\n\t}\n\tpublic async unlink(p: string, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic unlinkSync(p: string, cred: Cred): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async rmdir(p: string, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic rmdirSync(p: string, cred: Cred): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async mkdir(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic mkdirSync(p: string, mode: number, cred: Cred): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async readdir(p: string, cred: Cred): Promise<string[]> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic readdirSync(p: string, cred: Cred): string[] {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async exists(p: string, cred: Cred): Promise<boolean> {\n\t\ttry {\n\t\t\tawait this.stat(p, cred);\n\t\t\treturn true;\n\t\t} catch (e) {\n\t\t\treturn false;\n\t\t}\n\t}\n\tpublic existsSync(p: string, cred: Cred): boolean {\n\t\ttry {\n\t\t\tthis.statSync(p, cred);\n\t\t\treturn true;\n\t\t} catch (e) {\n\t\t\treturn false;\n\t\t}\n\t}\n\tpublic async realpath(p: string, cred: Cred): Promise<string> {\n\t\tif (this.metadata.supportsLinks) {\n\t\t\t// The path could contain symlinks. Split up the path,\n\t\t\t// resolve any symlinks, return the resolved string.\n\t\t\tconst splitPath = p.split(path.sep);\n\t\t\t// TODO: Simpler to just pass through file, find sep and such.\n\t\t\tfor (let i = 0; i < splitPath.length; i++) {\n\t\t\t\tconst addPaths = splitPath.slice(0, i + 1);\n\t\t\t\tsplitPath[i] = path.join(...addPaths);\n\t\t\t}\n\t\t\treturn splitPath.join(path.sep);\n\t\t} else {\n\t\t\t// No symlinks. We just need to verify that it exists.\n\t\t\tif (!(await this.exists(p, cred))) {\n\t\t\t\tthrow ApiError.ENOENT(p);\n\t\t\t}\n\t\t\treturn p;\n\t\t}\n\t}\n\tpublic realpathSync(p: string, cred: Cred): string {\n\t\tif (this.metadata.supportsLinks) {\n\t\t\t// The path could contain symlinks. Split up the path,\n\t\t\t// resolve any symlinks, return the resolved string.\n\t\t\tconst splitPath = p.split(path.sep);\n\t\t\t// TODO: Simpler to just pass through file, find sep and such.\n\t\t\tfor (let i = 0; i < splitPath.length; i++) {\n\t\t\t\tconst addPaths = splitPath.slice(0, i + 1);\n\t\t\t\tsplitPath[i] = path.join(...addPaths);\n\t\t\t}\n\t\t\treturn splitPath.join(path.sep);\n\t\t} else {\n\t\t\t// No symlinks. We just need to verify that it exists.\n\t\t\tif (this.existsSync(p, cred)) {\n\t\t\t\treturn p;\n\t\t\t} else {\n\t\t\t\tthrow ApiError.ENOENT(p);\n\t\t\t}\n\t\t}\n\t}\n\tpublic async truncate(p: string, len: number, cred: Cred): Promise<void> {\n\t\tconst fd = await this.open(p, FileFlag.getFileFlag('r+'), 0o644, cred);\n\t\ttry {\n\t\t\tawait fd.truncate(len);\n\t\t} finally {\n\t\t\tawait fd.close();\n\t\t}\n\t}\n\tpublic truncateSync(p: string, len: number, cred: Cred): void {\n\t\tconst fd = this.openSync(p, FileFlag.getFileFlag('r+'), 0o644, cred);\n\t\t// Need to safely close FD, regardless of whether or not truncate succeeds.\n\t\ttry {\n\t\t\tfd.truncateSync(len);\n\t\t} finally {\n\t\t\tfd.closeSync();\n\t\t}\n\t}\n\tpublic async readFile(fname: string, encoding: BufferEncoding | null, flag: FileFlag, cred: Cred): Promise<FileContents> {\n\t\t// Get file.\n\t\tconst fd = await this.open(fname, flag, 0o644, cred);\n\t\ttry {\n\t\t\tconst stat = await fd.stat();\n\t\t\t// Allocate buffer.\n\t\t\tconst buf = Buffer.alloc(stat.size);\n\t\t\tawait fd.read(buf, 0, stat.size, 0);\n\t\t\tawait fd.close();\n\t\t\tif (encoding === null) {\n\t\t\t\treturn buf;\n\t\t\t}\n\t\t\treturn buf.toString(encoding);\n\t\t} finally {\n\t\t\tawait fd.close();\n\t\t}\n\t}\n\tpublic readFileSync(fname: string, encoding: BufferEncoding | null, flag: FileFlag, cred: Cred): FileContents {\n\t\t// Get file.\n\t\tconst fd = this.openSync(fname, flag, 0o644, cred);\n\t\ttry {\n\t\t\tconst stat = fd.statSync();\n\t\t\t// Allocate buffer.\n\t\t\tconst buf = Buffer.alloc(stat.size);\n\t\t\tfd.readSync(buf, 0, stat.size, 0);\n\t\t\tfd.closeSync();\n\t\t\tif (encoding === null) {\n\t\t\t\treturn buf;\n\t\t\t}\n\t\t\treturn buf.toString(encoding);\n\t\t} finally {\n\t\t\tfd.closeSync();\n\t\t}\n\t}\n\tpublic async writeFile(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): Promise<void> {\n\t\t// Get file.\n\t\tconst fd = await this.open(fname, flag, mode, cred);\n\t\ttry {\n\t\t\tif (typeof data === 'string') {\n\t\t\t\tdata = Buffer.from(data, encoding!);\n\t\t\t}\n\t\t\t// Write into file.\n\t\t\tawait fd.write(data, 0, data.length, 0);\n\t\t} finally {\n\t\t\tawait fd.close();\n\t\t}\n\t}\n\tpublic writeFileSync(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): void {\n\t\t// Get file.\n\t\tconst fd = this.openSync(fname, flag, mode, cred);\n\t\ttry {\n\t\t\tif (typeof data === 'string') {\n\t\t\t\tdata = Buffer.from(data, encoding!);\n\t\t\t}\n\t\t\t// Write into file.\n\t\t\tfd.writeSync(data, 0, data.length, 0);\n\t\t} finally {\n\t\t\tfd.closeSync();\n\t\t}\n\t}\n\tpublic async appendFile(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): Promise<void> {\n\t\tconst fd = await this.open(fname, flag, mode, cred);\n\t\ttry {\n\t\t\tif (typeof data === 'string') {\n\t\t\t\tdata = Buffer.from(data, encoding!);\n\t\t\t}\n\t\t\tawait fd.write(data, 0, data.length, null);\n\t\t} finally {\n\t\t\tawait fd.close();\n\t\t}\n\t}\n\tpublic appendFileSync(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): void {\n\t\tconst fd = this.openSync(fname, flag, mode, cred);\n\t\ttry {\n\t\t\tif (typeof data === 'string') {\n\t\t\t\tdata = Buffer.from(data, encoding!);\n\t\t\t}\n\t\t\tfd.writeSync(data, 0, data.length, null);\n\t\t} finally {\n\t\t\tfd.closeSync();\n\t\t}\n\t}\n\tpublic async chmod(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic chmodSync(p: string, mode: number, cred: Cred) {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async chown(p: string, new_uid: number, new_gid: number, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic chownSync(p: string, new_uid: number, new_gid: number, cred: Cred): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async utimes(p: string, atime: Date, mtime: Date, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic utimesSync(p: string, atime: Date, mtime: Date, cred: Cred): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async link(srcpath: string, dstpath: string, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic linkSync(srcpath: string, dstpath: string, cred: Cred): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async symlink(srcpath: string, dstpath: string, type: string, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic symlinkSync(srcpath: string, dstpath: string, type: string, cred: Cred): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async readlink(p: string, cred: Cred): Promise<string> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic readlinkSync(p: string, cred: Cred): string {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n}\n\n/**\n * Implements the asynchronous API in terms of the synchronous API.\n */\nexport class SynchronousFileSystem extends BaseFileSystem {\n\tpublic get metadata(): FileSystemMetadata {\n\t\treturn { ...super.metadata, synchronous: true };\n\t}\n\n\tpublic async access(p: string, mode: number, cred: Cred): Promise<void> {\n\t\treturn this.accessSync(p, mode, cred);\n\t}\n\n\tpublic async rename(oldPath: string, newPath: string, cred: Cred): Promise<void> {\n\t\treturn this.renameSync(oldPath, newPath, cred);\n\t}\n\n\tpublic async stat(p: string | null, cred: Cred): Promise<Stats> {\n\t\treturn this.statSync(p, cred);\n\t}\n\n\tpublic async open(p: string, flags: FileFlag, mode: number, cred: Cred): Promise<File> {\n\t\treturn this.openSync(p, flags, mode, cred);\n\t}\n\n\tpublic async unlink(p: string, cred: Cred): Promise<void> {\n\t\treturn this.unlinkSync(p, cred);\n\t}\n\n\tpublic async rmdir(p: string, cred: Cred): Promise<void> {\n\t\treturn this.rmdirSync(p, cred);\n\t}\n\n\tpublic async mkdir(p: string, mode: number, cred: Cred): Promise<void> {\n\t\treturn this.mkdirSync(p, mode, cred);\n\t}\n\n\tpublic async readdir(p: string, cred: Cred): Promise<string[]> {\n\t\treturn this.readdirSync(p, cred);\n\t}\n\n\tpublic async chmod(p: string, mode: number, cred: Cred): Promise<void> {\n\t\treturn this.chmodSync(p, mode, cred);\n\t}\n\n\tpublic async chown(p: string, new_uid: number, new_gid: number, cred: Cred): Promise<void> {\n\t\treturn this.chownSync(p, new_uid, new_gid, cred);\n\t}\n\n\tpublic async utimes(p: string, atime: Date, mtime: Date, cred: Cred): Promise<void> {\n\t\treturn this.utimesSync(p, atime, mtime, cred);\n\t}\n\n\tpublic async link(srcpath: string, dstpath: string, cred: Cred): Promise<void> {\n\t\treturn this.linkSync(srcpath, dstpath, cred);\n\t}\n\n\tpublic async symlink(srcpath: string, dstpath: string, type: string, cred: Cred): Promise<void> {\n\t\treturn this.symlinkSync(srcpath, dstpath, type, cred);\n\t}\n\n\tpublic async readlink(p: string, cred: Cred): Promise<string> {\n\t\treturn this.readlinkSync(p, cred);\n\t}\n}\n", "import { Stats, FileType } from './stats';\nimport { Buffer } from 'buffer';\n\n/**\n * Generic inode definition that can easily be serialized.\n */\nexport default class Inode {\n\t/**\n\t * Converts the buffer into an Inode.\n\t */\n\tpublic static fromBuffer(buffer: Buffer): Inode {\n\t\tif (buffer === undefined) {\n\t\t\tthrow new Error('NO');\n\t\t}\n\t\treturn new Inode(\n\t\t\tbuffer.toString('ascii', 38),\n\t\t\tbuffer.readUInt32LE(0),\n\t\t\tbuffer.readUInt16LE(4),\n\t\t\tbuffer.readDoubleLE(6),\n\t\t\tbuffer.readDoubleLE(14),\n\t\t\tbuffer.readDoubleLE(22),\n\t\t\tbuffer.readUInt32LE(30),\n\t\t\tbuffer.readUInt32LE(34)\n\t\t);\n\t}\n\n\tconstructor(\n\t\tpublic id: string,\n\t\tpublic size: number,\n\t\tpublic mode: number,\n\t\tpublic atime: number,\n\t\tpublic mtime: number,\n\t\tpublic ctime: number,\n\t\tpublic uid: number,\n\t\tpublic gid: number\n\t) {}\n\n\t/**\n\t * Handy function that converts the Inode to a Node Stats object.\n\t */\n\tpublic toStats(): Stats {\n\t\treturn new Stats(\n\t\t\t(this.mode & 0xf000) === FileType.DIRECTORY ? FileType.DIRECTORY : FileType.FILE,\n\t\t\tthis.size,\n\t\t\tthis.mode,\n\t\t\tthis.atime,\n\t\t\tthis.mtime,\n\t\t\tthis.ctime,\n\t\t\tthis.uid,\n\t\t\tthis.gid\n\t\t);\n\t}\n\n\t/**\n\t * Get the size of this Inode, in bytes.\n\t */\n\tpublic getSize(): number {\n\t\t// ASSUMPTION: ID is ASCII (1 byte per char).\n\t\treturn 38 + this.id.length;\n\t}\n\n\t/**\n\t * Writes the inode into the start of the buffer.\n\t */\n\tpublic toBuffer(buff: Buffer = Buffer.alloc(this.getSize())): Buffer {\n\t\tbuff.writeUInt32LE(this.size, 0);\n\t\tbuff.writeUInt16LE(this.mode, 4);\n\t\tbuff.writeDoubleLE(this.atime, 6);\n\t\tbuff.writeDoubleLE(this.mtime, 14);\n\t\tbuff.writeDoubleLE(this.ctime, 22);\n\t\tbuff.writeUInt32LE(this.uid, 30);\n\t\tbuff.writeUInt32LE(this.gid, 34);\n\t\tbuff.write(this.id, 38, this.id.length, 'ascii');\n\t\treturn buff;\n\t}\n\n\t/**\n\t * Updates the Inode using information from the stats object. Used by file\n\t * systems at sync time, e.g.:\n\t * - Program opens file and gets a File object.\n\t * - Program mutates file. File object is responsible for maintaining\n\t * metadata changes locally -- typically in a Stats object.\n\t * - Program closes file. File object's metadata changes are synced with the\n\t * file system.\n\t * @return True if any changes have occurred.\n\t */\n\tpublic update(stats: Stats): boolean {\n\t\tlet hasChanged = false;\n\t\tif (this.size !== stats.size) {\n\t\t\tthis.size = stats.size;\n\t\t\thasChanged = true;\n\t\t}\n\n\t\tif (this.mode !== stats.mode) {\n\t\t\tthis.mode = stats.mode;\n\t\t\thasChanged = true;\n\t\t}\n\n\t\tconst atimeMs = stats.atime.getTime();\n\t\tif (this.atime !== atimeMs) {\n\t\t\tthis.atime = atimeMs;\n\t\t\thasChanged = true;\n\t\t}\n\n\t\tconst mtimeMs = stats.mtime.getTime();\n\t\tif (this.mtime !== mtimeMs) {\n\t\t\tthis.mtime = mtimeMs;\n\t\t\thasChanged = true;\n\t\t}\n\n\t\tconst ctimeMs = stats.ctime.getTime();\n\t\tif (this.ctime !== ctimeMs) {\n\t\t\tthis.ctime = ctimeMs;\n\t\t\thasChanged = true;\n\t\t}\n\n\t\tif (this.uid !== stats.uid) {\n\t\t\tthis.uid = stats.uid;\n\t\t\thasChanged = true;\n\t\t}\n\n\t\tif (this.uid !== stats.uid) {\n\t\t\tthis.uid = stats.uid;\n\t\t\thasChanged = true;\n\t\t}\n\n\t\treturn hasChanged;\n\t}\n\n\t// XXX: Copied from Stats. Should reconcile these two into something more\n\t// compact.\n\n\t/**\n\t * @return [Boolean] True if this item is a file.\n\t */\n\tpublic isFile(): boolean {\n\t\treturn (this.mode & 0xf000) === FileType.FILE;\n\t}\n\n\t/**\n\t * @return [Boolean] True if this item is a directory.\n\t */\n\tpublic isDirectory(): boolean {\n\t\treturn (this.mode & 0xf000) === FileType.DIRECTORY;\n\t}\n}\n", "/**\n * Grab bag of utility functions used across the code.\n */\nimport { FileSystem } from './filesystem';\nimport { ErrorCode, ApiError } from './ApiError';\nimport * as path from 'path';\nimport { Cred } from './cred';\nimport { Buffer } from 'buffer';\nimport type { BaseBackendConstructor } from './backends/backend';\n\n/**\n * Synchronous recursive makedir.\n * @internal\n */\nexport function mkdirpSync(p: string, mode: number, cred: Cred, fs: FileSystem): void {\n\tif (!fs.existsSync(p, cred)) {\n\t\tmkdirpSync(path.dirname(p), mode, cred, fs);\n\t\tfs.mkdirSync(p, mode, cred);\n\t}\n}\n\n/**\n * Copies a slice of the given buffer\n * @internal\n */\nexport function copyingSlice(buff: Buffer, start: number = 0, end = buff.length): Buffer {\n\tif (start < 0 || end < 0 || end > buff.length || start > end) {\n\t\tthrow new TypeError(`Invalid slice bounds on buffer of length ${buff.length}: [${start}, ${end}]`);\n\t}\n\tif (buff.length === 0) {\n\t\t// Avoid s0 corner case in ArrayBuffer case.\n\t\treturn Buffer.alloc(0);\n\t} else {\n\t\treturn buff.subarray(start, end);\n\t}\n}\n\n/**\n * Option validator for a Buffer file system option.\n * @internal\n */\nexport async function bufferValidator(v: object): Promise<void> {\n\tif (!Buffer.isBuffer(v)) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'option must be a Buffer.');\n\t}\n}\n\n/*\n * Levenshtein distance, from the `js-levenshtein` NPM module.\n * Copied here to avoid complexity of adding another CommonJS module dependency.\n */\n\nfunction _min(d0: number, d1: number, d2: number, bx: number, ay: number): number {\n\treturn Math.min(d0 + 1, d1 + 1, d2 + 1, bx === ay ? d1 : d1 + 1);\n}\n\n/**\n * Calculates levenshtein distance.\n * @param a\n * @param b\n */\nfunction levenshtein(a: string, b: string): number {\n\tif (a === b) {\n\t\treturn 0;\n\t}\n\n\tif (a.length > b.length) {\n\t\t[a, b] = [b, a]; // Swap a and b\n\t}\n\n\tlet la = a.length;\n\tlet lb = b.length;\n\n\t// Trim common suffix\n\twhile (la > 0 && a.charCodeAt(la - 1) === b.charCodeAt(lb - 1)) {\n\t\tla--;\n\t\tlb--;\n\t}\n\n\tlet offset = 0;\n\n\t// Trim common prefix\n\twhile (offset < la && a.charCodeAt(offset) === b.charCodeAt(offset)) {\n\t\toffset++;\n\t}\n\n\tla -= offset;\n\tlb -= offset;\n\n\tif (la === 0 || lb === 1) {\n\t\treturn lb;\n\t}\n\n\tconst vector = new Array<number>(la << 1);\n\n\tfor (let y = 0; y < la; ) {\n\t\tvector[la + y] = a.charCodeAt(offset + y);\n\t\tvector[y] = ++y;\n\t}\n\n\tlet x: number;\n\tlet d0: number;\n\tlet d1: number;\n\tlet d2: number;\n\tlet d3: number;\n\tfor (x = 0; x + 3 < lb; ) {\n\t\tconst bx0 = b.charCodeAt(offset + (d0 = x));\n\t\tconst bx1 = b.charCodeAt(offset + (d1 = x + 1));\n\t\tconst bx2 = b.charCodeAt(offset + (d2 = x + 2));\n\t\tconst bx3 = b.charCodeAt(offset + (d3 = x + 3));\n\t\tlet dd = (x += 4);\n\t\tfor (let y = 0; y < la; ) {\n\t\t\tconst ay = vector[la + y];\n\t\t\tconst dy = vector[y];\n\t\t\td0 = _min(dy, d0, d1, bx0, ay);\n\t\t\td1 = _min(d0, d1, d2, bx1, ay);\n\t\t\td2 = _min(d1, d2, d3, bx2, ay);\n\t\t\tdd = _min(d2, d3, dd, bx3, ay);\n\t\t\tvector[y++] = dd;\n\t\t\td3 = d2;\n\t\t\td2 = d1;\n\t\t\td1 = d0;\n\t\t\td0 = dy;\n\t\t}\n\t}\n\n\tlet dd: number = 0;\n\tfor (; x < lb; ) {\n\t\tconst bx0 = b.charCodeAt(offset + (d0 = x));\n\t\tdd = ++x;\n\t\tfor (let y = 0; y < la; y++) {\n\t\t\tconst dy = vector[y];\n\t\t\tvector[y] = dd = dy < d0 || dd < d0 ? (dy > dd ? dd + 1 : dy + 1) : bx0 === vector[la + y] ? d0 : d0 + 1;\n\t\t\td0 = dy;\n\t\t}\n\t}\n\n\treturn dd;\n}\n\n/**\n * Checks that the given options object is valid for the file system options.\n * @internal\n */\nexport async function checkOptions(backend: BaseBackendConstructor, opts: object): Promise<void> {\n\tconst optsInfo = backend.Options;\n\tconst fsName = backend.Name;\n\n\tlet pendingValidators = 0;\n\tlet callbackCalled = false;\n\tlet loopEnded = false;\n\n\t// Check for required options.\n\tfor (const optName in optsInfo) {\n\t\tif (Object.prototype.hasOwnProperty.call(optsInfo, optName)) {\n\t\t\tconst opt = optsInfo[optName];\n\t\t\tconst providedValue = opts && opts[optName];\n\n\t\t\tif (providedValue === undefined || providedValue === null) {\n\t\t\t\tif (!opt.optional) {\n\t\t\t\t\t// Required option, not provided.\n\t\t\t\t\t// Any incorrect options provided? Which ones are close to the provided one?\n\t\t\t\t\t// (edit distance 5 === close)\n\t\t\t\t\tconst incorrectOptions = Object.keys(opts)\n\t\t\t\t\t\t.filter(o => !(o in optsInfo))\n\t\t\t\t\t\t.map((a: string) => {\n\t\t\t\t\t\t\treturn { str: a, distance: levenshtein(optName, a) };\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.filter(o => o.distance < 5)\n\t\t\t\t\t\t.sort((a, b) => a.distance - b.distance);\n\t\t\t\t\t// Validators may be synchronous.\n\t\t\t\t\tif (callbackCalled) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcallbackCalled = true;\n\t\t\t\t\tthrow new ApiError(\n\t\t\t\t\t\tErrorCode.EINVAL,\n\t\t\t\t\t\t`[${fsName}] Required option '${optName}' not provided.${\n\t\t\t\t\t\t\tincorrectOptions.length > 0 ? ` You provided unrecognized option '${incorrectOptions[0].str}'; perhaps you meant to type '${optName}'.` : ''\n\t\t\t\t\t\t}\\nOption description: ${opt.description}`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// Else: Optional option, not provided. That is OK.\n\t\t\t} else {\n\t\t\t\t// Option provided! Check type.\n\t\t\t\tlet typeMatches = false;\n\t\t\t\tif (Array.isArray(opt.type)) {\n\t\t\t\t\ttypeMatches = opt.type.indexOf(typeof providedValue) !== -1;\n\t\t\t\t} else {\n\t\t\t\t\ttypeMatches = typeof providedValue === opt.type;\n\t\t\t\t}\n\t\t\t\tif (!typeMatches) {\n\t\t\t\t\t// Validators may be synchronous.\n\t\t\t\t\tif (callbackCalled) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcallbackCalled = true;\n\t\t\t\t\tthrow new ApiError(\n\t\t\t\t\t\tErrorCode.EINVAL,\n\t\t\t\t\t\t`[${fsName}] Value provided for option ${optName} is not the proper type. Expected ${\n\t\t\t\t\t\t\tArray.isArray(opt.type) ? `one of {${opt.type.join(', ')}}` : opt.type\n\t\t\t\t\t\t}, but received ${typeof providedValue}\\nOption description: ${opt.description}`\n\t\t\t\t\t);\n\t\t\t\t} else if (opt.validator) {\n\t\t\t\t\tpendingValidators++;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait opt.validator(providedValue);\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tif (!callbackCalled) {\n\t\t\t\t\t\t\tif (e) {\n\t\t\t\t\t\t\t\tcallbackCalled = true;\n\t\t\t\t\t\t\t\tthrow e;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tpendingValidators--;\n\t\t\t\t\t\t\tif (pendingValidators === 0 && loopEnded) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Otherwise: All good!\n\t\t\t}\n\t\t}\n\t}\n\tloopEnded = true;\n\tif (pendingValidators === 0 && !callbackCalled) {\n\t\treturn;\n\t}\n}\n\n/** Waits n ms. */\nexport function wait(ms: number): Promise<void> {\n\treturn new Promise(resolve => {\n\t\tsetTimeout(resolve, ms);\n\t});\n}\n\n/**\n * Converts a callback into a promise. Assumes last parameter is the callback\n * @todo Look at changing resolve value from cbArgs[0] to include other callback arguments?\n */\nexport function toPromise(fn: (...fnArgs: unknown[]) => unknown) {\n\treturn function (...args: unknown[]): Promise<unknown> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\targs.push((e: ApiError, ...cbArgs: unknown[]) => {\n\t\t\t\tif (e) {\n\t\t\t\t\treject(e);\n\t\t\t\t} else {\n\t\t\t\t\tresolve(cbArgs[0]);\n\t\t\t\t}\n\t\t\t});\n\t\t\tfn(...args);\n\t\t});\n\t};\n}\n\n/**\n * @internal\n */\nexport const setImmediate = typeof globalThis.setImmediate == 'function' ? globalThis.setImmediate : cb => setTimeout(cb, 0);\n\n/**\n * @internal\n */\nexport const ROOT_NODE_ID: string = '/';\n\n/**\n * Returns an empty directory node.\n * @internal\n */\nexport function getEmptyDirNode(): Buffer {\n\treturn Buffer.from('{}');\n}\n\n/**\n * Generates a random ID.\n * @internal\n */\nexport function randomUUID(): string {\n\t// From http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript\n\treturn 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {\n\t\tconst r = (Math.random() * 16) | 0;\n\t\tconst v = c === 'x' ? r : (r & 0x3) | 0x8;\n\t\treturn v.toString(16);\n\t});\n}\n", "import * as path from 'path';\nimport { ApiError, ErrorCode } from '../ApiError';\nimport { Cred } from '../cred';\nimport { W_OK, R_OK } from '../emulation/constants';\nimport { File, FileFlag, PreloadFile } from '../file';\nimport { SynchronousFileSystem } from '../filesystem';\nimport Inode from '../inode';\nimport { Stats, FileType } from '../stats';\nimport { randomUUID, getEmptyDirNode, ROOT_NODE_ID } from '../utils';\n\n/**\n * Represents a *synchronous* key-value store.\n */\nexport interface SyncKeyValueStore {\n\t/**\n\t * The name of the key-value store.\n\t */\n\tname(): string;\n\t/**\n\t * Empties the key-value store completely.\n\t */\n\tclear(): void;\n\t/**\n\t * Begins a new read-only transaction.\n\t */\n\tbeginTransaction(type: 'readonly'): SyncKeyValueROTransaction;\n\t/**\n\t * Begins a new read-write transaction.\n\t */\n\tbeginTransaction(type: 'readwrite'): SyncKeyValueRWTransaction;\n\tbeginTransaction(type: string): SyncKeyValueROTransaction;\n}\n\n/**\n * A read-only transaction for a synchronous key value store.\n */\nexport interface SyncKeyValueROTransaction {\n\t/**\n\t * Retrieves the data at the given key. Throws an ApiError if an error occurs\n\t * or if the key does not exist.\n\t * @param key The key to look under for data.\n\t * @return The data stored under the key, or undefined if not present.\n\t */\n\tget(key: string): Buffer | undefined;\n}\n\n/**\n * A read-write transaction for a synchronous key value store.\n */\nexport interface SyncKeyValueRWTransaction extends SyncKeyValueROTransaction {\n\t/**\n\t * Adds the data to the store under the given key.\n\t * @param key The key to add the data under.\n\t * @param data The data to add to the store.\n\t * @param overwrite If 'true', overwrite any existing data. If 'false',\n\t * avoids storing the data if the key exists.\n\t * @return True if storage succeeded, false otherwise.\n\t */\n\tput(key: string, data: Buffer, overwrite: boolean): boolean;\n\t/**\n\t * Deletes the data at the given key.\n\t * @param key The key to delete from the store.\n\t */\n\tdel(key: string): void;\n\t/**\n\t * Commits the transaction.\n\t */\n\tcommit(): void;\n\t/**\n\t * Aborts and rolls back the transaction.\n\t */\n\tabort(): void;\n}\n\n/**\n * An interface for simple synchronous key-value stores that don't have special\n * support for transactions and such.\n */\nexport interface SimpleSyncStore {\n\tget(key: string): Buffer | undefined;\n\tput(key: string, data: Buffer, overwrite: boolean): boolean;\n\tdel(key: string): void;\n}\n\n/**\n * A simple RW transaction for simple synchronous key-value stores.\n */\nexport class SimpleSyncRWTransaction implements SyncKeyValueRWTransaction {\n\t/**\n\t * Stores data in the keys we modify prior to modifying them.\n\t * Allows us to roll back commits.\n\t */\n\tprivate originalData: { [key: string]: Buffer | undefined } = {};\n\t/**\n\t * List of keys modified in this transaction, if any.\n\t */\n\tprivate modifiedKeys: string[] = [];\n\n\tconstructor(private store: SimpleSyncStore) {}\n\n\tpublic get(key: string): Buffer | undefined {\n\t\tconst val = this.store.get(key);\n\t\tthis.stashOldValue(key, val);\n\t\treturn val;\n\t}\n\n\tpublic put(key: string, data: Buffer, overwrite: boolean): boolean {\n\t\tthis.markModified(key);\n\t\treturn this.store.put(key, data, overwrite);\n\t}\n\n\tpublic del(key: string): void {\n\t\tthis.markModified(key);\n\t\tthis.store.del(key);\n\t}\n\n\tpublic commit(): void {\n\t\t/* NOP */\n\t}\n\n\tpublic abort(): void {\n\t\t// Rollback old values.\n\t\tfor (const key of this.modifiedKeys) {\n\t\t\tconst value = this.originalData[key];\n\t\t\tif (!value) {\n\t\t\t\t// Key didn't exist.\n\t\t\t\tthis.store.del(key);\n\t\t\t} else {\n\t\t\t\t// Key existed. Store old value.\n\t\t\t\tthis.store.put(key, value, true);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate _has(key: string) {\n\t\treturn Object.prototype.hasOwnProperty.call(this.originalData, key);\n\t}\n\n\t/**\n\t * Stashes given key value pair into `originalData` if it doesn't already\n\t * exist. Allows us to stash values the program is requesting anyway to\n\t * prevent needless `get` requests if the program modifies the data later\n\t * on during the transaction.\n\t */\n\tprivate stashOldValue(key: string, value: Buffer | undefined) {\n\t\t// Keep only the earliest value in the transaction.\n\t\tif (!this._has(key)) {\n\t\t\tthis.originalData[key] = value;\n\t\t}\n\t}\n\n\t/**\n\t * Marks the given key as modified, and stashes its value if it has not been\n\t * stashed already.\n\t */\n\tprivate markModified(key: string) {\n\t\tif (this.modifiedKeys.indexOf(key) === -1) {\n\t\t\tthis.modifiedKeys.push(key);\n\t\t\tif (!this._has(key)) {\n\t\t\t\tthis.originalData[key] = this.store.get(key);\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport interface SyncKeyValueFileSystemOptions {\n\t/**\n\t * The actual key-value store to read from/write to.\n\t */\n\tstore: SyncKeyValueStore;\n\t/**\n\t * Should the file system support properties (mtime/atime/ctime/chmod/etc)?\n\t * Enabling this slightly increases the storage space per file, and adds\n\t * atime updates every time a file is accessed, mtime updates every time\n\t * a file is modified, and permission checks on every operation.\n\t *\n\t * Defaults to *false*.\n\t */\n\tsupportProps?: boolean;\n\t/**\n\t * Should the file system support links?\n\t */\n\tsupportLinks?: boolean;\n}\n\nexport class SyncKeyValueFile extends PreloadFile<SyncKeyValueFileSystem> implements File {\n\tconstructor(_fs: SyncKeyValueFileSystem, _path: string, _flag: FileFlag, _stat: Stats, contents?: Buffer) {\n\t\tsuper(_fs, _path, _flag, _stat, contents);\n\t}\n\n\tpublic syncSync(): void {\n\t\tif (this.isDirty()) {\n\t\t\tthis._fs._syncSync(this.getPath(), this.getBuffer(), this.getStats());\n\t\t\tthis.resetDirty();\n\t\t}\n\t}\n\n\tpublic closeSync(): void {\n\t\tthis.syncSync();\n\t}\n}\n\n/**\n * A \"Synchronous key-value file system\". Stores data to/retrieves data from an\n * underlying key-value store.\n *\n * We use a unique ID for each node in the file system. The root node has a\n * fixed ID.\n * @todo Introduce Node ID caching.\n * @todo Check modes.\n */\nexport class SyncKeyValueFileSystem extends SynchronousFileSystem {\n\tpublic static isAvailable(): boolean {\n\t\treturn true;\n\t}\n\n\tprivate store: SyncKeyValueStore;\n\n\tconstructor(options: SyncKeyValueFileSystemOptions) {\n\t\tsuper();\n\t\tthis.store = options.store;\n\t\t// INVARIANT: Ensure that the root exists.\n\t\tthis.makeRootDirectory();\n\t}\n\n\tpublic getName(): string {\n\t\treturn this.store.name();\n\t}\n\tpublic isReadOnly(): boolean {\n\t\treturn false;\n\t}\n\tpublic supportsSymlinks(): boolean {\n\t\treturn false;\n\t}\n\tpublic supportsProps(): boolean {\n\t\treturn true;\n\t}\n\tpublic supportsSynch(): boolean {\n\t\treturn true;\n\t}\n\n\t/**\n\t * Delete all contents stored in the file system.\n\t */\n\tpublic empty(): void {\n\t\tthis.store.clear();\n\t\t// INVARIANT: Root always exists.\n\t\tthis.makeRootDirectory();\n\t}\n\n\tpublic accessSync(p: string, mode: number, cred: Cred): void {\n\t\tconst tx = this.store.beginTransaction('readonly'),\n\t\t\tnode = this.findINode(tx, p);\n\t\tif (!node.toStats().hasAccess(mode, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\t}\n\n\tpublic renameSync(oldPath: string, newPath: string, cred: Cred): void {\n\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\toldParent = path.dirname(oldPath),\n\t\t\toldName = path.basename(oldPath),\n\t\t\tnewParent = path.dirname(newPath),\n\t\t\tnewName = path.basename(newPath),\n\t\t\t// Remove oldPath from parent's directory listing.\n\t\t\toldDirNode = this.findINode(tx, oldParent),\n\t\t\toldDirList = this.getDirListing(tx, oldParent, oldDirNode);\n\n\t\tif (!oldDirNode.toStats().hasAccess(W_OK, cred)) {\n\t\t\tthrow ApiError.EACCES(oldPath);\n\t\t}\n\n\t\tif (!oldDirList[oldName]) {\n\t\t\tthrow ApiError.ENOENT(oldPath);\n\t\t}\n\t\tconst nodeId: string = oldDirList[oldName];\n\t\tdelete oldDirList[oldName];\n\n\t\t// Invariant: Can't move a folder inside itself.\n\t\t// This funny little hack ensures that the check passes only if oldPath\n\t\t// is a subpath of newParent. We append '/' to avoid matching folders that\n\t\t// are a substring of the bottom-most folder in the path.\n\t\tif ((newParent + '/').indexOf(oldPath + '/') === 0) {\n\t\t\tthrow new ApiError(ErrorCode.EBUSY, oldParent);\n\t\t}\n\n\t\t// Add newPath to parent's directory listing.\n\t\tlet newDirNode: Inode, newDirList: typeof oldDirList;\n\t\tif (newParent === oldParent) {\n\t\t\t// Prevent us from re-grabbing the same directory listing, which still\n\t\t\t// contains oldName.\n\t\t\tnewDirNode = oldDirNode;\n\t\t\tnewDirList = oldDirList;\n\t\t} else {\n\t\t\tnewDirNode = this.findINode(tx, newParent);\n\t\t\tnewDirList = this.getDirListing(tx, newParent, newDirNode);\n\t\t}\n\n\t\tif (newDirList[newName]) {\n\t\t\t// If it's a file, delete it.\n\t\t\tconst newNameNode = this.getINode(tx, newPath, newDirList[newName]);\n\t\t\tif (newNameNode.isFile()) {\n\t\t\t\ttry {\n\t\t\t\t\ttx.del(newNameNode.id);\n\t\t\t\t\ttx.del(newDirList[newName]);\n\t\t\t\t} catch (e) {\n\t\t\t\t\ttx.abort();\n\t\t\t\t\tthrow e;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// If it's a directory, throw a permissions error.\n\t\t\t\tthrow ApiError.EPERM(newPath);\n\t\t\t}\n\t\t}\n\t\tnewDirList[newName] = nodeId;\n\n\t\t// Commit the two changed directory listings.\n\t\ttry {\n\t\t\ttx.put(oldDirNode.id, Buffer.from(JSON.stringify(oldDirList)), true);\n\t\t\ttx.put(newDirNode.id, Buffer.from(JSON.stringify(newDirList)), true);\n\t\t} catch (e) {\n\t\t\ttx.abort();\n\t\t\tthrow e;\n\t\t}\n\n\t\ttx.commit();\n\t}\n\n\tpublic statSync(p: string, cred: Cred): Stats {\n\t\t// Get the inode to the item, convert it into a Stats object.\n\t\tconst stats = this.findINode(this.store.beginTransaction('readonly'), p).toStats();\n\t\tif (!stats.hasAccess(R_OK, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\t\treturn stats;\n\t}\n\n\tpublic createFileSync(p: string, flag: FileFlag, mode: number, cred: Cred): File {\n\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\tdata = Buffer.alloc(0),\n\t\t\tnewFile = this.commitNewFile(tx, p, FileType.FILE, mode, cred, data);\n\t\t// Open the file.\n\t\treturn new SyncKeyValueFile(this, p, flag, newFile.toStats(), data);\n\t}\n\n\tpublic openFileSync(p: string, flag: FileFlag, cred: Cred): File {\n\t\tconst tx = this.store.beginTransaction('readonly'),\n\t\t\tnode = this.findINode(tx, p),\n\t\t\tdata = tx.get(node.id);\n\t\tif (!node.toStats().hasAccess(flag.getMode(), cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\t\tif (data === undefined) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t\treturn new SyncKeyValueFile(this, p, flag, node.toStats(), data);\n\t}\n\n\tpublic unlinkSync(p: string, cred: Cred): void {\n\t\tthis.removeEntry(p, false, cred);\n\t}\n\n\tpublic rmdirSync(p: string, cred: Cred): void {\n\t\t// Check first if directory is empty.\n\t\tif (this.readdirSync(p, cred).length > 0) {\n\t\t\tthrow ApiError.ENOTEMPTY(p);\n\t\t} else {\n\t\t\tthis.removeEntry(p, true, cred);\n\t\t}\n\t}\n\n\tpublic mkdirSync(p: string, mode: number, cred: Cred): void {\n\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\tdata = Buffer.from('{}');\n\t\tthis.commitNewFile(tx, p, FileType.DIRECTORY, mode, cred, data);\n\t}\n\n\tpublic readdirSync(p: string, cred: Cred): string[] {\n\t\tconst tx = this.store.beginTransaction('readonly');\n\t\tconst node = this.findINode(tx, p);\n\t\tif (!node.toStats().hasAccess(R_OK, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\t\treturn Object.keys(this.getDirListing(tx, p, node));\n\t}\n\n\tpublic chmodSync(p: string, mode: number, cred: Cred): void {\n\t\tconst fd = this.openFileSync(p, FileFlag.getFileFlag('r+'), cred);\n\t\tfd.chmodSync(mode);\n\t}\n\n\tpublic chownSync(p: string, new_uid: number, new_gid: number, cred: Cred): void {\n\t\tconst fd = this.openFileSync(p, FileFlag.getFileFlag('r+'), cred);\n\t\tfd.chownSync(new_uid, new_gid);\n\t}\n\n\tpublic _syncSync(p: string, data: Buffer, stats: Stats): void {\n\t\t// @todo Ensure mtime updates properly, and use that to determine if a data\n\t\t// update is required.\n\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\t// We use the _findInode helper because we actually need the INode id.\n\t\t\tfileInodeId = this._findINode(tx, path.dirname(p), path.basename(p)),\n\t\t\tfileInode = this.getINode(tx, p, fileInodeId),\n\t\t\tinodeChanged = fileInode.update(stats);\n\n\t\ttry {\n\t\t\t// Sync data.\n\t\t\ttx.put(fileInode.id, data, true);\n\t\t\t// Sync metadata.\n\t\t\tif (inodeChanged) {\n\t\t\t\ttx.put(fileInodeId, fileInode.toBuffer(), true);\n\t\t\t}\n\t\t} catch (e) {\n\t\t\ttx.abort();\n\t\t\tthrow e;\n\t\t}\n\t\ttx.commit();\n\t}\n\n\t/**\n\t * Checks if the root directory exists. Creates it if it doesn't.\n\t */\n\tprivate makeRootDirectory() {\n\t\tconst tx = this.store.beginTransaction('readwrite');\n\t\tif (tx.get(ROOT_NODE_ID) === undefined) {\n\t\t\t// Create new inode.\n\t\t\tconst currTime = new Date().getTime(),\n\t\t\t\t// Mode 0666, owned by root:root\n\t\t\t\tdirInode = new Inode(randomUUID(), 4096, 511 | FileType.DIRECTORY, currTime, currTime, currTime, 0, 0);\n\t\t\t// If the root doesn't exist, the first random ID shouldn't exist,\n\t\t\t// either.\n\t\t\ttx.put(dirInode.id, getEmptyDirNode(), false);\n\t\t\ttx.put(ROOT_NODE_ID, dirInode.toBuffer(), false);\n\t\t\ttx.commit();\n\t\t}\n\t}\n\n\t/**\n\t * Helper function for findINode.\n\t * @param parent The parent directory of the file we are attempting to find.\n\t * @param filename The filename of the inode we are attempting to find, minus\n\t * the parent.\n\t * @return string The ID of the file's inode in the file system.\n\t */\n\tprivate _findINode(tx: SyncKeyValueROTransaction, parent: string, filename: string, visited: Set<string> = new Set<string>()): string {\n\t\tconst currentPath = path.posix.join(parent, filename);\n\t\tif (visited.has(currentPath)) {\n\t\t\tthrow new ApiError(ErrorCode.EIO, 'Infinite loop detected while finding inode', currentPath);\n\t\t}\n\n\t\tvisited.add(currentPath);\n\t\tconst readDirectory = (inode: Inode): string => {\n\t\t\t// Get the root's directory listing.\n\t\t\tconst dirList = this.getDirListing(tx, parent, inode);\n\t\t\t// Get the file's ID.\n\t\t\tif (dirList[filename]) {\n\t\t\t\treturn dirList[filename];\n\t\t\t} else {\n\t\t\t\tthrow ApiError.ENOENT(path.resolve(parent, filename));\n\t\t\t}\n\t\t};\n\t\tif (parent === '.') {\n\t\t\tparent = process.cwd();\n\t\t}\n\t\tif (parent === '/') {\n\t\t\tif (filename === '') {\n\t\t\t\t// BASE CASE #1: Return the root's ID.\n\t\t\t\treturn ROOT_NODE_ID;\n\t\t\t} else {\n\t\t\t\t// BASE CASE #2: Find the item in the root node.\n\t\t\t\treturn readDirectory(this.getINode(tx, parent, ROOT_NODE_ID));\n\t\t\t}\n\t\t} else {\n\t\t\treturn readDirectory(this.getINode(tx, parent + path.sep + filename, this._findINode(tx, path.dirname(parent), path.basename(parent), visited)));\n\t\t}\n\t}\n\n\t/**\n\t * Finds the Inode of the given path.\n\t * @param p The path to look up.\n\t * @return The Inode of the path p.\n\t * @todo memoize/cache\n\t */\n\tprivate findINode(tx: SyncKeyValueROTransaction, p: string): Inode {\n\t\treturn this.getINode(tx, p, this._findINode(tx, path.dirname(p), path.basename(p)));\n\t}\n\n\t/**\n\t * Given the ID of a node, retrieves the corresponding Inode.\n\t * @param tx The transaction to use.\n\t * @param p The corresponding path to the file (used for error messages).\n\t * @param id The ID to look up.\n\t */\n\tprivate getINode(tx: SyncKeyValueROTransaction, p: string, id: string): Inode {\n\t\tconst inode = tx.get(id);\n\t\tif (inode === undefined) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t\treturn Inode.fromBuffer(inode);\n\t}\n\n\t/**\n\t * Given the Inode of a directory, retrieves the corresponding directory\n\t * listing.\n\t */\n\tprivate getDirListing(tx: SyncKeyValueROTransaction, p: string, inode: Inode): { [fileName: string]: string } {\n\t\tif (!inode.isDirectory()) {\n\t\t\tthrow ApiError.ENOTDIR(p);\n\t\t}\n\t\tconst data = tx.get(inode.id);\n\t\tif (data === undefined) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t\treturn JSON.parse(data.toString());\n\t}\n\n\t/**\n\t * Creates a new node under a random ID. Retries 5 times before giving up in\n\t * the exceedingly unlikely chance that we try to reuse a random GUID.\n\t * @return The GUID that the data was stored under.\n\t */\n\tprivate addNewNode(tx: SyncKeyValueRWTransaction, data: Buffer): string {\n\t\tconst retries = 0;\n\t\tlet currId: string;\n\t\twhile (retries < 5) {\n\t\t\ttry {\n\t\t\t\tcurrId = randomUUID();\n\t\t\t\ttx.put(currId, data, false);\n\t\t\t\treturn currId;\n\t\t\t} catch (e) {\n\t\t\t\t// Ignore and reroll.\n\t\t\t}\n\t\t}\n\t\tthrow new ApiError(ErrorCode.EIO, 'Unable to commit data to key-value store.');\n\t}\n\n\t/**\n\t * Commits a new file (well, a FILE or a DIRECTORY) to the file system with\n\t * the given mode.\n\t * Note: This will commit the transaction.\n\t * @param p The path to the new file.\n\t * @param type The type of the new file.\n\t * @param mode The mode to create the new file with.\n\t * @param data The data to store at the file's data node.\n\t * @return The Inode for the new file.\n\t */\n\tprivate commitNewFile(tx: SyncKeyValueRWTransaction, p: string, type: FileType, mode: number, cred: Cred, data: Buffer): Inode {\n\t\tconst parentDir = path.dirname(p),\n\t\t\tfname = path.basename(p),\n\t\t\tparentNode = this.findINode(tx, parentDir),\n\t\t\tdirListing = this.getDirListing(tx, parentDir, parentNode),\n\t\t\tcurrTime = new Date().getTime();\n\n\t\t//Check that the creater has correct access\n\t\tif (!parentNode.toStats().hasAccess(0b0100 /* Write */, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\n\t\t// Invariant: The root always exists.\n\t\t// If we don't check this prior to taking steps below, we will create a\n\t\t// file with name '' in root should p == '/'.\n\t\tif (p === '/') {\n\t\t\tthrow ApiError.EEXIST(p);\n\t\t}\n\n\t\t// Check if file already exists.\n\t\tif (dirListing[fname]) {\n\t\t\tthrow ApiError.EEXIST(p);\n\t\t}\n\n\t\tlet fileNode: Inode;\n\t\ttry {\n\t\t\t// Commit data.\n\t\t\tconst dataId = this.addNewNode(tx, data);\n\t\t\tfileNode = new Inode(dataId, data.length, mode | type, currTime, currTime, currTime, cred.uid, cred.gid);\n\t\t\t// Commit file node.\n\t\t\tconst fileNodeId = this.addNewNode(tx, fileNode.toBuffer());\n\t\t\t// Update and commit parent directory listing.\n\t\t\tdirListing[fname] = fileNodeId;\n\t\t\ttx.put(parentNode.id, Buffer.from(JSON.stringify(dirListing)), true);\n\t\t} catch (e) {\n\t\t\ttx.abort();\n\t\t\tthrow e;\n\t\t}\n\t\ttx.commit();\n\t\treturn fileNode;\n\t}\n\n\t/**\n\t * Remove all traces of the given path from the file system.\n\t * @param p The path to remove from the file system.\n\t * @param isDir Does the path belong to a directory, or a file?\n\t * @todo Update mtime.\n\t */\n\tprivate removeEntry(p: string, isDir: boolean, cred: Cred): void {\n\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\tparent: string = path.dirname(p),\n\t\t\tparentNode = this.findINode(tx, parent),\n\t\t\tparentListing = this.getDirListing(tx, parent, parentNode),\n\t\t\tfileName: string = path.basename(p);\n\n\t\tif (!parentListing[fileName]) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\n\t\tconst fileNodeId = parentListing[fileName];\n\n\t\t// Get file inode.\n\t\tconst fileNode = this.getINode(tx, p, fileNodeId);\n\n\t\tif (!fileNode.toStats().hasAccess(W_OK, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\n\t\t// Remove from directory listing of parent.\n\t\tdelete parentListing[fileName];\n\n\t\tif (!isDir && fileNode.isDirectory()) {\n\t\t\tthrow ApiError.EISDIR(p);\n\t\t} else if (isDir && !fileNode.isDirectory()) {\n\t\t\tthrow ApiError.ENOTDIR(p);\n\t\t}\n\n\t\ttry {\n\t\t\t// Delete data.\n\t\t\ttx.del(fileNode.id);\n\t\t\t// Delete node.\n\t\t\ttx.del(fileNodeId);\n\t\t\t// Update directory listing.\n\t\t\ttx.put(parentNode.id, Buffer.from(JSON.stringify(parentListing)), true);\n\t\t} catch (e) {\n\t\t\ttx.abort();\n\t\t\tthrow e;\n\t\t}\n\t\t// Success.\n\t\ttx.commit();\n\t}\n}\n", "import type { BFSCallback, FileSystem } from '../filesystem';\nimport { checkOptions } from '../utils';\n\n/**\n * Describes a file system option.\n */\nexport interface BackendOption<T> {\n\t/**\n\t * The basic JavaScript type(s) for this option.\n\t */\n\ttype: string | string[];\n\n\t/**\n\t * Whether or not the option is optional (e.g., can be set to null or undefined).\n\t * Defaults to `false`.\n\t */\n\toptional?: boolean;\n\n\t/**\n\t * Description of the option. Used in error messages and documentation.\n\t */\n\tdescription: string;\n\n\t/**\n\t * A custom validation function to check if the option is valid.\n\t * Resolves if valid and rejects if not.\n\t */\n\tvalidator?(opt: T): Promise<void>;\n}\n\n/**\n * Describes all of the options available in a file system.\n */\nexport interface BackendOptions {\n\t[name: string]: BackendOption<unknown>;\n}\n\n/**\n * Contains types for static functions on a backend.\n */\nexport interface BaseBackendConstructor<FS extends typeof FileSystem = typeof FileSystem> {\n\tnew (...params: ConstructorParameters<FS>): InstanceType<FS>;\n\n\t/**\n\t * A name to identify the backend.\n\t */\n\tName: string;\n\n\t/**\n\t * Describes all of the options available for this backend.\n\t */\n\tOptions: BackendOptions;\n\n\t/**\n\t * Whether the backend is available in the current environment.\n\t * It supports checking synchronously and asynchronously\n\t * Sync:\n\t * Returns 'true' if this backend is available in the current\n\t * environment. For example, a `localStorage`-backed filesystem will return\n\t * 'false' if the browser does not support that API.\n\t *\n\t * Defaults to 'false', as the FileSystem base class isn't usable alone.\n\t */\n\tisAvailable(): boolean;\n}\n\n/**\n * Contains types for static functions on a backend.\n */\nexport interface BackendConstructor<FS extends typeof FileSystem = typeof FileSystem> extends BaseBackendConstructor<FS> {\n\t/**\n\t * Creates backend of this given type with the given\n\t * options, and either returns the result in a promise or callback.\n\t */\n\tCreate(): Promise<InstanceType<FS>>;\n\tCreate(options: object): Promise<InstanceType<FS>>;\n\tCreate(cb: BFSCallback<InstanceType<FS>>): void;\n\tCreate(options: object, cb: BFSCallback<InstanceType<FS>>): void;\n\tCreate(options: object, cb?: BFSCallback<InstanceType<FS>>): Promise<InstanceType<FS>> | void;\n}\n\nexport function CreateBackend<FS extends BaseBackendConstructor>(this: FS): Promise<InstanceType<FS>>;\nexport function CreateBackend<FS extends BaseBackendConstructor>(this: FS, options: BackendOptions): Promise<InstanceType<FS>>;\nexport function CreateBackend<FS extends BaseBackendConstructor>(this: FS, cb: BFSCallback<InstanceType<FS>>): void;\nexport function CreateBackend<FS extends BaseBackendConstructor>(this: FS, options: BackendOptions, cb: BFSCallback<InstanceType<FS>>): void;\nexport function CreateBackend<FS extends BaseBackendConstructor>(\n\tthis: FS,\n\toptions?: BackendOptions | BFSCallback<InstanceType<FS>>,\n\tcb?: BFSCallback<InstanceType<FS>>\n): Promise<InstanceType<FS>> | void {\n\tcb = typeof options === 'function' ? options : cb;\n\n\tcheckOptions(this, options);\n\n\tconst fs = new this(typeof options === 'function' ? {} : options) as InstanceType<FS>;\n\n\t// Promise\n\tif (typeof cb != 'function') {\n\t\treturn fs.whenReady();\n\t}\n\n\t// Callback\n\tfs.whenReady()\n\t\t.then(fs => cb(null, fs))\n\t\t.catch(err => cb(err));\n}\n", "import { SyncKeyValueStore, SimpleSyncStore, SimpleSyncRWTransaction, SyncKeyValueRWTransaction, SyncKeyValueFileSystem } from './SyncStore';\nimport { CreateBackend, type BackendOptions } from './backend';\n\n/**\n * A simple in-memory key-value store backed by a JavaScript object.\n */\nexport class InMemoryStore implements SyncKeyValueStore, SimpleSyncStore {\n\tprivate store: Map<string, Buffer> = new Map<string, Buffer>();\n\n\tpublic name() {\n\t\treturn InMemoryFileSystem.Name;\n\t}\n\tpublic clear() {\n\t\tthis.store.clear();\n\t}\n\n\tpublic beginTransaction(type: string): SyncKeyValueRWTransaction {\n\t\treturn new SimpleSyncRWTransaction(this);\n\t}\n\n\tpublic get(key: string): Buffer {\n\t\treturn this.store.get(key);\n\t}\n\n\tpublic put(key: string, data: Buffer, overwrite: boolean): boolean {\n\t\tif (!overwrite && this.store.has(key)) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.store.set(key, data);\n\t\treturn true;\n\t}\n\n\tpublic del(key: string): void {\n\t\tthis.store.delete(key);\n\t}\n}\n\n/**\n * A simple in-memory file system backed by an InMemoryStore.\n * Files are not persisted across page loads.\n */\nexport class InMemoryFileSystem extends SyncKeyValueFileSystem {\n\tpublic static readonly Name = 'InMemory';\n\n\tpublic static Create = CreateBackend.bind(this);\n\n\tpublic static readonly Options: BackendOptions = {};\n\n\tpublic constructor() {\n\t\tsuper({ store: new InMemoryStore() });\n\t}\n}\n", "// Utilities and shared data\n\nimport { posix as path } from 'path';\nimport { ApiError, ErrorCode } from '../ApiError';\nimport { Cred } from '../cred';\nimport { FileSystem } from '../filesystem';\nimport { File } from '../file';\n//import { BackendConstructor } from '../backends';\nimport { InMemoryFileSystem } from '../backends/InMemory';\nimport { BackendConstructor } from '../backends/backend';\n\n/**\n * converts Date or number to a fractional UNIX timestamp\n * Grabbed from NodeJS sources (lib/fs.js)\n */\nexport function _toUnixTimestamp(time: Date | number): number {\n\tif (typeof time === 'number') {\n\t\treturn time;\n\t} else if (time instanceof Date) {\n\t\treturn time.getTime() / 1000;\n\t}\n\tthrow new Error('Cannot parse time: ' + time);\n}\n\nexport function normalizeMode(mode: unknown, def: number): number {\n\tswitch (typeof mode) {\n\t\tcase 'number':\n\t\t\t// (path, flag, mode, cb?)\n\t\t\treturn mode;\n\t\tcase 'string':\n\t\t\t// (path, flag, modeString, cb?)\n\t\t\tconst trueMode = parseInt(mode, 8);\n\t\t\tif (!isNaN(trueMode)) {\n\t\t\t\treturn trueMode;\n\t\t\t}\n\t\t\t// Invalid string.\n\t\t\treturn def;\n\t\tdefault:\n\t\t\treturn def;\n\t}\n}\n\nexport function normalizeTime(time: number | Date): Date {\n\tif (time instanceof Date) {\n\t\treturn time;\n\t}\n\n\tif (typeof time === 'number') {\n\t\treturn new Date(time * 1000);\n\t}\n\n\tthrow new ApiError(ErrorCode.EINVAL, `Invalid time.`);\n}\n\nexport function normalizePath(p: string): string {\n\t// Node doesn't allow null characters in paths.\n\tif (p.indexOf('\\u0000') >= 0) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Path must be a string without null bytes.');\n\t}\n\tif (p === '') {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Path must not be empty.');\n\t}\n\tp = p.replaceAll(/\\/+/g, '/');\n\treturn path.resolve(p);\n}\n\nexport function normalizeOptions(options: any, defEnc: string | null, defFlag: string, defMode: number | null): { encoding: BufferEncoding; flag: string; mode: number } {\n\t// typeof null === 'object' so special-case handing is needed.\n\tswitch (options === null ? 'null' : typeof options) {\n\t\tcase 'object':\n\t\t\treturn {\n\t\t\t\tencoding: typeof options['encoding'] !== 'undefined' ? options['encoding'] : defEnc,\n\t\t\t\tflag: typeof options['flag'] !== 'undefined' ? options['flag'] : defFlag,\n\t\t\t\tmode: normalizeMode(options['mode'], defMode!),\n\t\t\t};\n\t\tcase 'string':\n\t\t\treturn {\n\t\t\t\tencoding: options,\n\t\t\t\tflag: defFlag,\n\t\t\t\tmode: defMode!,\n\t\t\t};\n\t\tcase 'null':\n\t\tcase 'undefined':\n\t\tcase 'function':\n\t\t\treturn {\n\t\t\t\tencoding: defEnc! as BufferEncoding,\n\t\t\t\tflag: defFlag,\n\t\t\t\tmode: defMode!,\n\t\t\t};\n\t\tdefault:\n\t\t\tthrow new TypeError(`\"options\" must be a string or an object, got ${typeof options} instead.`);\n\t}\n}\n\nexport function nop() {\n\t// do nothing\n}\n\n// credentials\nexport let cred: Cred;\nexport function setCred(val: Cred): void {\n\tcred = val;\n}\n\n// descriptors\nexport const fdMap: Map<number, File> = new Map();\nlet nextFd = 100;\nexport function getFdForFile(file: File): number {\n\tconst fd = nextFd++;\n\tfdMap.set(fd, file);\n\treturn fd;\n}\nexport function fd2file(fd: number): File {\n\tif (!fdMap.has(fd)) {\n\t\tthrow new ApiError(ErrorCode.EBADF, 'Invalid file descriptor.');\n\t}\n\treturn fdMap.get(fd);\n}\n\n// mounting\nexport interface MountMapping {\n\t[point: string]: InstanceType<BackendConstructor>;\n}\n\nexport const mounts: Map<string, FileSystem> = new Map();\n\n/*\nSet a default root.\nThere is a very small but not 0 change that initialize() will try to unmount the default before it is mounted.\nThis can be fixed by using a top-level await, which is not done to maintain ES6 compatibility.\n*/\nInMemoryFileSystem.Create().then(fs => mount('/', fs));\n\n/**\n * Gets the file system mounted at `mountPoint`\n */\nexport function getMount(mountPoint: string): FileSystem {\n\treturn mounts.get(mountPoint);\n}\n\n/**\n * Gets an object of mount points (keys) and filesystems (values)\n */\nexport function getMounts(): MountMapping {\n\treturn Object.fromEntries(mounts.entries());\n}\n\n/**\n * Mounts the file system at the given mount point.\n */\nexport function mount(mountPoint: string, fs: FileSystem): void {\n\tif (mountPoint[0] !== '/') {\n\t\tmountPoint = '/' + mountPoint;\n\t}\n\tmountPoint = path.resolve(mountPoint);\n\tif (mounts.has(mountPoint)) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Mount point ' + mountPoint + ' is already in use.');\n\t}\n\tmounts.set(mountPoint, fs);\n}\n\n/**\n * Unmounts the file system at the given mount point.\n */\nexport function umount(mountPoint: string): void {\n\tif (mountPoint[0] !== '/') {\n\t\tmountPoint = `/${mountPoint}`;\n\t}\n\tmountPoint = path.resolve(mountPoint);\n\tif (!mounts.has(mountPoint)) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Mount point ' + mountPoint + ' is already unmounted.');\n\t}\n\tmounts.delete(mountPoint);\n}\n\n/**\n * Gets the internal FileSystem for the path, then returns it along with the path relative to the FS' root\n */\nexport function resolveFS(path: string): { fs: FileSystem; path: string; mountPoint: string } {\n\tconst sortedMounts = [...mounts].sort((a, b) => (a[0].length > b[0].length ? -1 : 1)); // decending order of the string length\n\tfor (const [mountPoint, fs] of sortedMounts) {\n\t\t// We know path is normalized, so it would be a substring of the mount point.\n\t\tif (mountPoint.length <= path.length && path.startsWith(mountPoint)) {\n\t\t\tpath = path.slice(mountPoint.length > 1 ? mountPoint.length : 0); // Resolve the path relative to the mount point\n\t\t\tif (path === '') {\n\t\t\t\tpath = '/';\n\t\t\t}\n\t\t\treturn { fs, path, mountPoint };\n\t\t}\n\t}\n\n\tthrow new ApiError(ErrorCode.EIO, 'ZenFS not initialized with a file system');\n}\n\n/**\n * Reverse maps the paths in text from the mounted FileSystem to the global path\n */\nexport function fixPaths(text: string, paths: { [from: string]: string }): string {\n\tfor (const [from, to] of Object.entries(paths)) {\n\t\ttext = text.replaceAll(from, to);\n\t}\n\treturn text;\n}\n\nexport function fixError<E extends Error>(e: E, paths: { [from: string]: string }): E {\n\te.stack = fixPaths(e.stack, paths);\n\te.message = fixPaths(e.message, paths);\n\treturn e;\n}\n\nexport function initialize(mountMapping: MountMapping): void {\n\tif (mountMapping['/']) {\n\t\tumount('/');\n\t}\n\tfor (const [point, fs] of Object.entries(mountMapping)) {\n\t\tconst FS = fs.constructor as unknown as BackendConstructor;\n\t\tif (!FS.isAvailable()) {\n\t\t\tthrow new ApiError(ErrorCode.EINVAL, `Can not mount \"${point}\" since the filesystem is unavailable.`);\n\t\t}\n\n\t\tmount(point, fs);\n\t}\n}\n", "import type { ReadStream, WriteStream, FSWatcher, symlink as _symlink } from 'node:fs';\nimport { ApiError, ErrorCode } from '../ApiError';\n\nimport * as constants from './constants';\nexport { constants };\n\nimport { File, FileFlag } from '../file';\nimport { normalizePath, normalizeMode, getFdForFile, normalizeOptions, fd2file, fdMap, normalizeTime, cred, nop, resolveFS, fixError, mounts } from './shared';\nimport { FileContents, FileSystem } from '../filesystem';\nimport { Stats } from '../stats';\n\ntype FileSystemMethod = {\n\t[K in keyof FileSystem]: FileSystem[K] extends (...args: any) => any\n\t\t? (name: K, resolveSymlinks: boolean, ...args: Parameters<FileSystem[K]>) => ReturnType<FileSystem[K]>\n\t\t: never;\n}[keyof FileSystem]; // https://stackoverflow.com/a/76335220/17637456\n\n/**\n * Utility for FS ops. It handles\n * - path normalization (for the first parameter to the FS op)\n * - path translation for errors\n * - FS/mount point resolution\n *\n * It can't be used for functions which may operate on multiple mounted FSs or paths (e.g. `rename`)\n * @param name the function name\n * @param resolveSymlinks whether to resolve symlinks\n * @param args the rest of the parameters are passed to the FS function. Note that the first parameter is required to be a path\n * @returns\n */\nasync function doOp<M extends FileSystemMethod, RT extends ReturnType<M>>(...[name, resolveSymlinks, path, ...args]: Parameters<M>): Promise<RT> {\n\tpath = normalizePath(path);\n\tconst { fs, path: resolvedPath } = resolveFS(resolveSymlinks && (await exists(path)) ? await realpath(path) : path);\n\ttry {\n\t\t// @ts-expect-error 2556 (since ...args is not correctly picked up as being a tuple)\n\t\treturn fs[name](resolvedPath, ...args) as Promise<RT>;\n\t} catch (e) {\n\t\tthrow fixError(e, { [resolvedPath]: path });\n\t}\n}\n\n// fs.promises\n\n/**\n * Renames a file\n * @param oldPath\n * @param newPath\n */\nexport async function rename(oldPath: string, newPath: string): Promise<void> {\n\toldPath = normalizePath(oldPath);\n\tnewPath = normalizePath(newPath);\n\tconst _old = resolveFS(oldPath);\n\tconst _new = resolveFS(newPath);\n\tconst paths = { [_old.path]: oldPath, [_new.path]: newPath };\n\ttry {\n\t\tif (_old === _new) {\n\t\t\treturn _old.fs.rename(_old.path, _new.path, cred);\n\t\t}\n\n\t\tconst data = await readFile(oldPath);\n\t\tawait writeFile(newPath, data);\n\t\tawait unlink(oldPath);\n\t} catch (e) {\n\t\tthrow fixError(e, paths);\n\t}\n}\n\n/**\n * Test whether or not the given path exists by checking with the file system.\n * @param path\n */\nexport async function exists(path: string): Promise<boolean> {\n\tpath = normalizePath(path);\n\ttry {\n\t\tconst { fs, path: resolvedPath } = resolveFS(path);\n\t\treturn fs.exists(resolvedPath, cred);\n\t} catch (e) {\n\t\tif ((e as ApiError).errno == ErrorCode.ENOENT) {\n\t\t\treturn false;\n\t\t}\n\n\t\tthrow e;\n\t}\n}\n\n/**\n * `stat`.\n * @param path\n * @returns Stats\n */\nexport async function stat(path: string): Promise<Stats> {\n\treturn doOp('stat', true, path, cred);\n}\n\n/**\n * `lstat`.\n * `lstat()` is identical to `stat()`, except that if path is a symbolic link,\n * then the link itself is stat-ed, not the file that it refers to.\n * @param path\n * @return [ZenFS.node.fs.Stats]\n */\nexport async function lstat(path: string): Promise<Stats> {\n\treturn doOp('stat', false, path, cred);\n}\n\n// FILE-ONLY METHODS\n\n/**\n * `truncate`.\n * @param path\n * @param len\n */\nexport async function truncate(path: string, len: number = 0): Promise<void> {\n\tif (len < 0) {\n\t\tthrow new ApiError(ErrorCode.EINVAL);\n\t}\n\treturn doOp('truncate', true, path, len, cred);\n}\n\n/**\n * `unlink`.\n * @param path\n */\nexport async function unlink(path: string): Promise<void> {\n\treturn doOp('unlink', false, path, cred);\n}\n\n/**\n * file open.\n * @see http://www.manpagez.com/man/2/open/\n * @param path\n * @param flags\n * @param mode defaults to `0644`\n */\nexport async function open(path: string, flag: string, mode: number | string = 0o644): Promise<number> {\n\tconst file: File = await doOp('open', true, path, FileFlag.getFileFlag(flag), normalizeMode(mode, 0o644), cred);\n\treturn getFdForFile(file);\n}\n\n/**\n * Synchronously reads the entire contents of a file.\n * @param filename\n * @param options\n * @option options [String] encoding The string encoding for the file contents. Defaults to `null`.\n * @option options [String] flag Defaults to `'r'`.\n * @return [String | ZenFS.node.Buffer]\n */\nexport async function readFile(filename: string, options?: { flag?: string }): Promise<Buffer>;\nexport async function readFile(filename: string, options: { encoding: string; flag?: string }): Promise<string>;\nexport async function readFile(filename: string, encoding: string): Promise<string>;\nexport async function readFile(filename: string, arg2: any = {}): Promise<Buffer | string> {\n\tconst options = normalizeOptions(arg2, null, 'r', null);\n\tconst flag = FileFlag.getFileFlag(options.flag);\n\tif (!flag.isReadable()) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Flag passed to readFile must allow for reading.');\n\t}\n\treturn doOp('readFile', true, filename, options.encoding, flag, cred);\n}\n\n/**\n * Synchronously writes data to a file, replacing the file if it already\n * exists.\n *\n * The encoding option is ignored if data is a buffer.\n * @param filename\n * @param data\n * @param options\n * @option options [String] encoding Defaults to `'utf8'`.\n * @option options [Number] mode Defaults to `0644`.\n * @option options [String] flag Defaults to `'w'`.\n */\nexport async function writeFile(filename: string, data: FileContents, options?: { encoding?: string; mode?: number | string; flag?: string }): Promise<void>;\nexport async function writeFile(filename: string, data: FileContents, encoding?: string): Promise<void>;\nexport async function writeFile(filename: string, data: FileContents, options?: { encoding?: string; mode?: number | string; flag?: string } | string): Promise<void>;\nexport async function writeFile(filename: string, data: FileContents, arg3?: { encoding?: string; mode?: number | string; flag?: string } | string): Promise<void> {\n\tconst options = normalizeOptions(arg3, 'utf8', 'w', 0o644);\n\tconst flag = FileFlag.getFileFlag(options.flag);\n\tif (!flag.isWriteable()) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Flag passed to writeFile must allow for writing.');\n\t}\n\treturn doOp('writeFile', true, filename, data, options.encoding, flag, options.mode, cred);\n}\n\n/**\n * Asynchronously append data to a file, creating the file if it not yet\n * exists.\n *\n * @example Usage example\n * fs.appendFile('message.txt', 'data to append', function (err) {\n * if (err) throw err;\n * console.log('The \"data to append\" was appended to file!');\n * });\n * @param filename\n * @param data\n * @param options\n * @option options [String] encoding Defaults to `'utf8'`.\n * @option options [Number] mode Defaults to `0644`.\n * @option options [String] flag Defaults to `'a'`.\n */\nexport async function appendFile(filename: string, data: FileContents, options?: { encoding?: string; mode?: number | string; flag?: string }): Promise<void>;\nexport async function appendFile(filename: string, data: FileContents, encoding?: string): Promise<void>;\nexport async function appendFile(filename: string, data: FileContents, arg3?: any): Promise<void> {\n\tconst options = normalizeOptions(arg3, 'utf8', 'a', 0o644);\n\tconst flag = FileFlag.getFileFlag(options.flag);\n\tif (!flag.isAppendable()) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Flag passed to appendFile must allow for appending.');\n\t}\n\treturn doOp('appendFile', true, filename, data, options.encoding, flag, options.mode, cred);\n}\n\n// FILE DESCRIPTOR METHODS\n\n/**\n * `fstat`.\n * `fstat()` is identical to `stat()`, except that the file to be stat-ed is\n * specified by the file descriptor `fd`.\n * @param fd\n * @return [ZenFS.node.fs.Stats]\n */\nexport async function fstat(fd: number): Promise<Stats> {\n\treturn fd2file(fd).stat();\n}\n\n/**\n * close.\n * @param fd\n */\nexport async function close(fd: number): Promise<void> {\n\tawait fd2file(fd).close();\n\tfdMap.delete(fd);\n\treturn;\n}\n\n/**\n * ftruncate.\n * @param fd\n * @param len\n */\nexport async function ftruncate(fd: number, len: number = 0): Promise<void> {\n\tconst file = fd2file(fd);\n\tif (len < 0) {\n\t\tthrow new ApiError(ErrorCode.EINVAL);\n\t}\n\treturn file.truncate(len);\n}\n\n/**\n * fsync.\n * @param fd\n */\nexport async function fsync(fd: number): Promise<void> {\n\treturn fd2file(fd).sync();\n}\n\n/**\n * fdatasync.\n * @param fd\n */\nexport async function fdatasync(fd: number): Promise<void> {\n\treturn fd2file(fd).datasync();\n}\n\n/**\n * Write buffer to the file specified by `fd`.\n * Note that it is unsafe to use fs.write multiple times on the same file\n * without waiting for it to return.\n * @param fd\n * @param buffer Buffer containing the data to write to\n * the file.\n * @param offset Offset in the buffer to start reading data from.\n * @param length The amount of bytes to write to the file.\n * @param position Offset from the beginning of the file where this\n * data should be written. If position is null, the data will be written at\n * the current position.\n */\nexport async function write(fd: number, buffer: Buffer, offset: number, length: number, position?: number): Promise<number>;\nexport async function write(fd: number, data: string, position?: number | null, encoding?: BufferEncoding): Promise<number>;\nexport async function write(fd: number, arg2: Buffer | string, arg3?: number, arg4?: BufferEncoding | number, arg5?: number): Promise<number> {\n\tlet buffer: Buffer,\n\t\toffset: number = 0,\n\t\tlength: number,\n\t\tposition: number | null;\n\tif (typeof arg2 === 'string') {\n\t\t// Signature 1: (fd, string, [position?, [encoding?]])\n\t\tposition = typeof arg3 === 'number' ? arg3 : null;\n\t\tconst encoding = (typeof arg4 === 'string' ? arg4 : 'utf8') as BufferEncoding;\n\t\toffset = 0;\n\t\tbuffer = Buffer.from(arg2, encoding);\n\t\tlength = buffer.length;\n\t} else {\n\t\t// Signature 2: (fd, buffer, offset, length, position?)\n\t\tbuffer = arg2;\n\t\toffset = arg3;\n\t\tlength = arg4 as number;\n\t\tposition = typeof arg5 === 'number' ? arg5 : null;\n\t}\n\n\tconst file = fd2file(fd);\n\tif (position === undefined || position === null) {\n\t\tposition = file.getPos()!;\n\t}\n\treturn file.write(buffer, offset, length, position);\n}\n\n/**\n * Read data from the file specified by `fd`.\n * @param fd\n * @param buffer The buffer that the data will be\n * written to.\n * @param offset The offset within the buffer where writing will\n * start.\n * @param length An integer specifying the number of bytes to read.\n * @param position An integer specifying where to begin reading from\n * in the file. If position is null, data will be read from the current file\n * position.\n */\nexport async function read(fd: number, buffer: Buffer, offset: number, length: number, position?: number): Promise<{ bytesRead: number; buffer: Buffer }> {\n\tconst file = fd2file(fd);\n\tif (isNaN(+position)) {\n\t\tposition = file.getPos()!;\n\t}\n\n\treturn file.read(buffer, offset, length, position);\n}\n\n/**\n * `fchown`.\n * @param fd\n * @param uid\n * @param gid\n */\nexport async function fchown(fd: number, uid: number, gid: number): Promise<void> {\n\treturn fd2file(fd).chown(uid, gid);\n}\n\n/**\n * `fchmod`.\n * @param fd\n * @param mode\n */\nexport async function fchmod(fd: number, mode: number | string): Promise<void> {\n\tconst numMode = typeof mode === 'string' ? parseInt(mode, 8) : mode;\n\treturn fd2file(fd).chmod(numMode);\n}\n\n/**\n * Change the file timestamps of a file referenced by the supplied file\n * descriptor.\n * @param fd\n * @param atime\n * @param mtime\n */\nexport async function futimes(fd: number, atime: number | Date, mtime: number | Date): Promise<void> {\n\treturn fd2file(fd).utimes(normalizeTime(atime), normalizeTime(mtime));\n}\n\n// DIRECTORY-ONLY METHODS\n\n/**\n * `rmdir`.\n * @param path\n */\nexport async function rmdir(path: string): Promise<void> {\n\treturn doOp('rmdir', true, path, cred);\n}\n\n/**\n * `mkdir`.\n * @param path\n * @param mode defaults to `0777`\n */\nexport async function mkdir(path: string, mode?: number | string): Promise<void> {\n\treturn doOp('mkdir', true, path, normalizeMode(mode, 0o777), cred);\n}\n\n/**\n * `readdir`. Reads the contents of a directory.\n * @param path\n * @return [String[]]\n */\nexport async function readdir(path: string): Promise<string[]> {\n\tpath = normalizePath(path);\n\tconst entries: string[] = await doOp('readdir', true, path, cred);\n\tconst points = [...mounts.keys()];\n\tfor (const point of points) {\n\t\tif (point.startsWith(path)) {\n\t\t\tconst entry = point.slice(path.length);\n\t\t\tif (entry.includes('/') || entry.length == 0) {\n\t\t\t\t// ignore FSs mounted in subdirectories and any FS mounted to `path`.\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tentries.push(entry);\n\t\t}\n\t}\n\treturn entries;\n}\n\n// SYMLINK METHODS\n\n/**\n * `link`.\n * @param srcpath\n * @param dstpath\n */\nexport async function link(srcpath: string, dstpath: string): Promise<void> {\n\tdstpath = normalizePath(dstpath);\n\treturn doOp('link', false, srcpath, dstpath, cred);\n}\n\n/**\n * `symlink`.\n * @param srcpath\n * @param dstpath\n * @param type can be either `'dir'` or `'file'` (default is `'file'`)\n */\nexport async function symlink(srcpath: string, dstpath: string, type: _symlink.Type = 'file'): Promise<void> {\n\tif (!['file', 'dir', 'junction'].includes(type)) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Invalid type: ' + type);\n\t}\n\tdstpath = normalizePath(dstpath);\n\treturn doOp('symlink', false, srcpath, dstpath, type, cred);\n}\n\n/**\n * readlink.\n * @param path\n * @return [String]\n */\nexport async function readlink(path: string): Promise<string> {\n\treturn doOp('readlink', false, path, cred);\n}\n\n// PROPERTY OPERATIONS\n\n/**\n * `chown`.\n * @param path\n * @param uid\n * @param gid\n */\nexport async function chown(path: string, uid: number, gid: number): Promise<void> {\n\treturn doOp('chown', true, path, uid, gid, cred);\n}\n\n/**\n * `lchown`.\n * @param path\n * @param uid\n * @param gid\n */\nexport async function lchown(path: string, uid: number, gid: number): Promise<void> {\n\treturn doOp('chown', false, path, uid, gid, cred);\n}\n\n/**\n * `chmod`.\n * @param path\n * @param mode\n */\nexport async function chmod(path: string, mode: string | number): Promise<void> {\n\tconst numMode = normalizeMode(mode, -1);\n\tif (numMode < 0) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, `Invalid mode.`);\n\t}\n\treturn doOp('chmod', true, path, numMode, cred);\n}\n\n/**\n * `lchmod`.\n * @param path\n * @param mode\n */\nexport async function lchmod(path: string, mode: number | string): Promise<void> {\n\tconst numMode = normalizeMode(mode, -1);\n\tif (numMode < 1) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, `Invalid mode.`);\n\t}\n\treturn doOp('chmod', false, normalizePath(path), numMode, cred);\n}\n\n/**\n * Change file timestamps of the file referenced by the supplied path.\n * @param path\n * @param atime\n * @param mtime\n */\nexport async function utimes(path: string, atime: number | Date, mtime: number | Date): Promise<void> {\n\treturn doOp('utimes', true, path, normalizeTime(atime), normalizeTime(mtime), cred);\n}\n\n/**\n * Change file timestamps of the file referenced by the supplied path.\n * @param path\n * @param atime\n * @param mtime\n */\nexport async function lutimes(path: string, atime: number | Date, mtime: number | Date): Promise<void> {\n\treturn doOp('utimes', false, path, normalizeTime(atime), normalizeTime(mtime), cred);\n}\n\n/**\n * `realpath`.\n * @param path\n * @param cache An object literal of mapped paths that can be used to\n * force a specific path resolution or avoid additional `fs.stat` calls for\n * known real paths.\n * @return [String]\n */\nexport async function realpath(path: string, cache: { [path: string]: string } = {}): Promise<string> {\n\tpath = normalizePath(path);\n\tconst { fs, path: resolvedPath, mountPoint } = resolveFS(path);\n\ttry {\n\t\tconst stats = await fs.stat(resolvedPath, cred);\n\t\tif (!stats.isSymbolicLink()) {\n\t\t\treturn path;\n\t\t}\n\t\tconst dst = mountPoint + normalizePath(await fs.readlink(resolvedPath, cred));\n\t\treturn realpath(dst);\n\t} catch (e) {\n\t\tthrow fixError(e, { [resolvedPath]: path });\n\t}\n}\n\nexport async function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): Promise<void>;\nexport async function watchFile(filename: string, options: { persistent?: boolean; interval?: number }, listener: (curr: Stats, prev: Stats) => void): Promise<void>;\nexport async function watchFile(filename: string, arg2: any, listener: (curr: Stats, prev: Stats) => void = nop): Promise<void> {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n\nexport async function unwatchFile(filename: string, listener: (curr: Stats, prev: Stats) => void = nop): Promise<void> {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n\nexport async function watch(filename: string, listener?: (event: string, filename: string) => any): Promise<FSWatcher>;\nexport async function watch(filename: string, options: { persistent?: boolean }, listener?: (event: string, filename: string) => any): Promise<FSWatcher>;\nexport async function watch(filename: string, arg2: any, listener: (event: string, filename: string) => any = nop): Promise<FSWatcher> {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n\n/**\n * `access`.\n * @param path\n * @param mode\n */\nexport async function access(path: string, mode: number = 0o600): Promise<void> {\n\treturn doOp('access', true, path, mode, cred);\n}\n\nexport async function createReadStream(\n\tpath: string,\n\toptions?: {\n\t\tflags?: string;\n\t\tencoding?: string;\n\t\tfd?: number;\n\t\tmode?: number;\n\t\tautoClose?: boolean;\n\t}\n): Promise<ReadStream> {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n\nexport async function createWriteStream(\n\tpath: string,\n\toptions?: {\n\t\tflags?: string;\n\t\tencoding?: string;\n\t\tfd?: number;\n\t\tmode?: number;\n\t}\n): Promise<WriteStream> {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n", "import type { FSWatcher, ReadStream, WriteStream, symlink as _symlink } from 'fs';\nimport { ApiError, ErrorCode } from '../ApiError';\nimport { BFSCallback, BFSOneArgCallback, BFSThreeArgCallback, FileContents } from '../filesystem';\nimport { Stats } from '../stats';\nimport { nop, normalizeMode } from './shared';\nimport * as promises from './promises';\nimport { R_OK } from './constants';\n\n/**\n * Asynchronous rename. No arguments other than a possible exception are given\n * to the completion callback.\n * @param oldPath\n * @param newPath\n * @param callback\n */\nexport function rename(oldPath: string, newPath: string, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.rename(oldPath, newPath)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Test whether or not the given path exists by checking with the file system.\n * Then call the callback argument with either true or false.\n * @example Sample invocation\n * fs.exists('/etc/passwd', function (exists) {\n * util.debug(exists ? \"it's there\" : \"no passwd!\");\n * });\n * @param path\n * @param callback\n */\nexport function exists(path: string, cb: (exists: boolean) => unknown = nop): void {\n\tpromises\n\t\t.exists(path)\n\t\t.then(cb)\n\t\t.catch(() => cb(false));\n}\n\n/**\n * Asynchronous `stat`.\n * @param path\n * @param callback\n */\nexport function stat(path: string, cb: BFSCallback<Stats> = nop): void {\n\tpromises\n\t\t.stat(path)\n\t\t.then(stats => cb(null, stats))\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `lstat`.\n * `lstat()` is identical to `stat()`, except that if path is a symbolic link,\n * then the link itself is stat-ed, not the file that it refers to.\n * @param path\n * @param callback\n */\nexport function lstat(path: string, cb: BFSCallback<Stats> = nop): void {\n\tpromises\n\t\t.lstat(path)\n\t\t.then(stats => cb(null, stats))\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `truncate`.\n * @param path\n * @param len\n * @param callback\n */\nexport function truncate(path: string, cb?: BFSOneArgCallback): void;\nexport function truncate(path: string, len: number, cb?: BFSOneArgCallback): void;\nexport function truncate(path: string, arg2: number | BFSOneArgCallback = 0, cb: BFSOneArgCallback = nop): void {\n\tcb = typeof arg2 === 'function' ? arg2 : cb;\n\tconst len = typeof arg2 === 'number' ? arg2 : 0;\n\tpromises\n\t\t.truncate(path, len)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `unlink`.\n * @param path\n * @param callback\n */\nexport function unlink(path: string, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.unlink(path)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous file open.\n * Exclusive mode ensures that path is newly created.\n *\n * `flags` can be:\n *\n * * `'r'` - Open file for reading. An exception occurs if the file does not exist.\n * * `'r+'` - Open file for reading and writing. An exception occurs if the file does not exist.\n * * `'rs'` - Open file for reading in synchronous mode. Instructs the filesystem to not cache writes.\n * * `'rs+'` - Open file for reading and writing, and opens the file in synchronous mode.\n * * `'w'` - Open file for writing. The file is created (if it does not exist) or truncated (if it exists).\n * * `'wx'` - Like 'w' but opens the file in exclusive mode.\n * * `'w+'` - Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).\n * * `'wx+'` - Like 'w+' but opens the file in exclusive mode.\n * * `'a'` - Open file for appending. The file is created if it does not exist.\n * * `'ax'` - Like 'a' but opens the file in exclusive mode.\n * * `'a+'` - Open file for reading and appending. The file is created if it does not exist.\n * * `'ax+'` - Like 'a+' but opens the file in exclusive mode.\n *\n * @see http://www.manpagez.com/man/2/open/\n * @param path\n * @param flags\n * @param mode defaults to `0644`\n * @param callback\n */\nexport function open(path: string, flag: string, cb?: BFSCallback<number>): void;\nexport function open(path: string, flag: string, mode: number | string, cb?: BFSCallback<number>): void;\nexport function open(path: string, flag: string, arg2?: number | string | BFSCallback<number>, cb: BFSCallback<number> = nop): void {\n\tconst mode = normalizeMode(arg2, 0o644);\n\tcb = typeof arg2 === 'function' ? arg2 : cb;\n\tpromises\n\t\t.open(path, flag, mode)\n\t\t.then(fd => cb(null, fd))\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronously reads the entire contents of a file.\n * @example Usage example\n * fs.readFile('/etc/passwd', function (err, data) {\n * if (err) throw err;\n * console.log(data);\n * });\n * @param filename\n * @param options\n * @option options [String] encoding The string encoding for the file contents. Defaults to `null`.\n * @option options [String] flag Defaults to `'r'`.\n * @param callback If no encoding is specified, then the raw buffer is returned.\n */\nexport function readFile(filename: string, cb: BFSCallback<Buffer>): void;\nexport function readFile(filename: string, options: { flag?: string }, callback?: BFSCallback<Buffer>): void;\nexport function readFile(filename: string, options: { encoding: string; flag?: string }, callback?: BFSCallback<string>): void;\nexport function readFile(filename: string, encoding: string, cb: BFSCallback<string>): void;\nexport function readFile(filename: string, arg2: any = {}, cb: BFSCallback<string> | BFSCallback<Buffer> = nop) {\n\tcb = typeof arg2 === 'function' ? arg2 : cb;\n\n\tpromises.readFile(filename, typeof arg2 === 'function' ? null : arg2);\n}\n\n/**\n * Asynchronously writes data to a file, replacing the file if it already\n * exists.\n *\n * The encoding option is ignored if data is a buffer.\n *\n * @example Usage example\n * fs.writeFile('message.txt', 'Hello Node', function (err) {\n * if (err) throw err;\n * console.log('It\\'s saved!');\n * });\n * @param filename\n * @param data\n * @param options\n * @option options [String] encoding Defaults to `'utf8'`.\n * @option options [Number] mode Defaults to `0644`.\n * @option options [String] flag Defaults to `'w'`.\n * @param callback\n */\nexport function writeFile(filename: string, data: FileContents, cb?: BFSOneArgCallback): void;\nexport function writeFile(filename: string, data: FileContents, encoding?: string, cb?: BFSOneArgCallback): void;\nexport function writeFile(filename: string, data: FileContents, options?: { encoding?: string; mode?: string | number; flag?: string }, cb?: BFSOneArgCallback): void;\nexport function writeFile(\n\tfilename: string,\n\tdata: FileContents,\n\targ3: { encoding?: string; mode?: string | number; flag?: string } | string | BFSOneArgCallback = {},\n\tcb: BFSOneArgCallback = nop\n): void {\n\tcb = typeof arg3 === 'function' ? arg3 : cb;\n\tpromises.writeFile(filename, data, typeof arg3 === 'function' ? undefined : arg3);\n}\n\n/**\n * Asynchronously append data to a file, creating the file if it not yet\n * exists.\n *\n * @example Usage example\n * fs.appendFile('message.txt', 'data to append', function (err) {\n * if (err) throw err;\n * console.log('The \"data to append\" was appended to file!');\n * });\n * @param filename\n * @param data\n * @param options\n * @option options [String] encoding Defaults to `'utf8'`.\n * @option options [Number] mode Defaults to `0644`.\n * @option options [String] flag Defaults to `'a'`.\n * @param callback\n */\nexport function appendFile(filename: string, data: FileContents, cb?: BFSOneArgCallback): void;\nexport function appendFile(filename: string, data: FileContents, options?: { encoding?: string; mode?: number | string; flag?: string }, cb?: BFSOneArgCallback): void;\nexport function appendFile(filename: string, data: FileContents, encoding?: string, cb?: BFSOneArgCallback): void;\nexport function appendFile(filename: string, data: FileContents, arg3?: any, cb: BFSOneArgCallback = nop): void {\n\tcb = typeof arg3 === 'function' ? arg3 : cb;\n\tpromises.appendFile(filename, data, typeof arg3 === 'function' ? null : arg3);\n}\n\n/**\n * Asynchronous `fstat`.\n * `fstat()` is identical to `stat()`, except that the file to be stat-ed is\n * specified by the file descriptor `fd`.\n * @param fd\n * @param callback\n */\nexport function fstat(fd: number, cb: BFSCallback<Stats> = nop): void {\n\tpromises\n\t\t.fstat(fd)\n\t\t.then(stats => cb(null, stats))\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous close.\n * @param fd\n * @param callback\n */\nexport function close(fd: number, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.close(fd)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous ftruncate.\n * @param fd\n * @param len\n * @param callback\n */\nexport function ftruncate(fd: number, cb?: BFSOneArgCallback): void;\nexport function ftruncate(fd: number, len?: number, cb?: BFSOneArgCallback): void;\nexport function ftruncate(fd: number, arg2?: any, cb: BFSOneArgCallback = nop): void {\n\tconst length = typeof arg2 === 'number' ? arg2 : 0;\n\tcb = typeof arg2 === 'function' ? arg2 : cb;\n\tpromises.ftruncate(fd, length);\n}\n\n/**\n * Asynchronous fsync.\n * @param fd\n * @param callback\n */\nexport function fsync(fd: number, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.fsync(fd)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous fdatasync.\n * @param fd\n * @param callback\n */\nexport function fdatasync(fd: number, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.fdatasync(fd)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Write buffer to the file specified by `fd`.\n * Note that it is unsafe to use fs.write multiple times on the same file\n * without waiting for the callback.\n * @param fd\n * @param buffer Buffer containing the data to write to\n * the file.\n * @param offset Offset in the buffer to start reading data from.\n * @param length The amount of bytes to write to the file.\n * @param position Offset from the beginning of the file where this\n * data should be written. If position is null, the data will be written at\n * the current position.\n * @param callback The number specifies the number of bytes written into the file.\n */\nexport function write(fd: number, buffer: Buffer, offset: number, length: number, cb?: BFSThreeArgCallback<number, Buffer>): void;\nexport function write(fd: number, buffer: Buffer, offset: number, length: number, position: number | null, cb?: BFSThreeArgCallback<number, Buffer>): void;\nexport function write(fd: number, data: FileContents, cb?: BFSThreeArgCallback<number, string>): void;\nexport function write(fd: number, data: FileContents, position: number | null, cb?: BFSThreeArgCallback<number, string>): void;\nexport function write(fd: number, data: FileContents, position: number | null, encoding: BufferEncoding, cb?: BFSThreeArgCallback<number, string>): void;\nexport function write(\n\tfd: number,\n\targ2: FileContents,\n\targ3?: any,\n\targ4?: any,\n\targ5?: any,\n\tcb: BFSThreeArgCallback<number, Buffer> | BFSThreeArgCallback<number, string> = nop\n): void {\n\tlet buffer: Buffer,\n\t\toffset: number,\n\t\tlength: number,\n\t\tposition: number | null = null,\n\t\tencoding: BufferEncoding;\n\tif (typeof arg2 === 'string') {\n\t\t// Signature 1: (fd, string, [position?, [encoding?]], cb?)\n\t\tencoding = 'utf8';\n\t\tswitch (typeof arg3) {\n\t\t\tcase 'function':\n\t\t\t\t// (fd, string, cb)\n\t\t\t\tcb = arg3;\n\t\t\t\tbreak;\n\t\t\tcase 'number':\n\t\t\t\t// (fd, string, position, encoding?, cb?)\n\t\t\t\tposition = arg3;\n\t\t\t\tencoding = (typeof arg4 === 'string' ? arg4 : 'utf8') as BufferEncoding;\n\t\t\t\tcb = typeof arg5 === 'function' ? arg5 : cb;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\t// ...try to find the callback and get out of here!\n\t\t\t\tcb = typeof arg4 === 'function' ? arg4 : typeof arg5 === 'function' ? arg5 : cb;\n\t\t\t\tcb(new ApiError(ErrorCode.EINVAL, 'Invalid arguments.'));\n\t\t\t\treturn;\n\t\t}\n\t\tbuffer = Buffer.from(arg2, encoding);\n\t\toffset = 0;\n\t\tlength = buffer.length;\n\t\tconst _cb = cb as BFSThreeArgCallback<number, string>;\n\t\tpromises\n\t\t\t.write(fd, buffer, offset, length, position)\n\t\t\t.then(bytesWritten => _cb(null, bytesWritten, buffer.toString(encoding)))\n\t\t\t.catch(_cb);\n\t} else {\n\t\t// Signature 2: (fd, buffer, offset, length, position?, cb?)\n\t\tbuffer = arg2;\n\t\toffset = arg3;\n\t\tlength = arg4;\n\t\tposition = typeof arg5 === 'number' ? arg5 : null;\n\t\tconst _cb = (typeof arg5 === 'function' ? arg5 : cb) as BFSThreeArgCallback<number, Buffer>;\n\t\tpromises\n\t\t\t.write(fd, buffer, offset, length, position)\n\t\t\t.then(bytesWritten => _cb(null, bytesWritten, buffer))\n\t\t\t.catch(_cb);\n\t}\n}\n\n/**\n * Read data from the file specified by `fd`.\n * @param buffer The buffer that the data will be\n * written to.\n * @param offset The offset within the buffer where writing will\n * start.\n * @param length An integer specifying the number of bytes to read.\n * @param position An integer specifying where to begin reading from\n * in the file. If position is null, data will be read from the current file\n * position.\n * @param callback The number is the number of bytes read\n */\nexport function read(fd: number, buffer: Buffer, offset: number, length: number, position?: number, cb: BFSThreeArgCallback<number, Buffer> = nop): void {\n\tpromises\n\t\t.read(fd, buffer, offset, length, position)\n\t\t.then(({ bytesRead, buffer }) => cb(null, bytesRead, buffer))\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `fchown`.\n * @param fd\n * @param uid\n * @param gid\n * @param callback\n */\nexport function fchown(fd: number, uid: number, gid: number, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.fchown(fd, uid, gid)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `fchmod`.\n * @param fd\n * @param mode\n * @param callback\n */\nexport function fchmod(fd: number, mode: string | number, cb: BFSOneArgCallback): void {\n\tpromises\n\t\t.fchmod(fd, mode)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Change the file timestamps of a file referenced by the supplied file\n * descriptor.\n * @param fd\n * @param atime\n * @param mtime\n * @param callback\n */\nexport function futimes(fd: number, atime: number | Date, mtime: number | Date, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.futimes(fd, atime, mtime)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `rmdir`.\n * @param path\n * @param callback\n */\nexport function rmdir(path: string, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.rmdir(path)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `mkdir`.\n * @param path\n * @param mode defaults to `0777`\n * @param callback\n */\nexport function mkdir(path: string, mode?: any, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.mkdir(path, mode)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `readdir`. Reads the contents of a directory.\n * The callback gets two arguments `(err, files)` where `files` is an array of\n * the names of the files in the directory excluding `'.'` and `'..'`.\n * @param path\n * @param callback\n */\nexport function readdir(path: string, cb: BFSCallback<string[]> = nop): void {\n\tpromises\n\t\t.readdir(path)\n\t\t.then(entries => cb(null, entries))\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `link`.\n * @param srcpath\n * @param dstpath\n * @param callback\n */\nexport function link(srcpath: string, dstpath: string, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.link(srcpath, dstpath)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `symlink`.\n * @param srcpath\n * @param dstpath\n * @param type can be either `'dir'` or `'file'` (default is `'file'`)\n * @param callback\n */\nexport function symlink(srcpath: string, dstpath: string, cb?: BFSOneArgCallback): void;\nexport function symlink(srcpath: string, dstpath: string, type?: _symlink.Type, cb?: BFSOneArgCallback): void;\nexport function symlink(srcpath: string, dstpath: string, arg3?: _symlink.Type | BFSOneArgCallback, cb: BFSOneArgCallback = nop): void {\n\tconst type = typeof arg3 === 'string' ? arg3 : 'file';\n\tcb = typeof arg3 === 'function' ? arg3 : cb;\n\tpromises\n\t\t.symlink(srcpath, dstpath, typeof arg3 === 'function' ? null : arg3)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous readlink.\n * @param path\n * @param callback\n */\nexport function readlink(path: string, cb: BFSCallback<string> = nop): void {\n\tpromises\n\t\t.readlink(path)\n\t\t.then(result => cb(null, result))\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `chown`.\n * @param path\n * @param uid\n * @param gid\n * @param callback\n */\nexport function chown(path: string, uid: number, gid: number, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.chown(path, uid, gid)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `lchown`.\n * @param path\n * @param uid\n * @param gid\n * @param callback\n */\nexport function lchown(path: string, uid: number, gid: number, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.lchown(path, uid, gid)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `chmod`.\n * @param path\n * @param mode\n * @param callback\n */\nexport function chmod(path: string, mode: number | string, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.chmod(path, mode)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `lchmod`.\n * @param path\n * @param mode\n * @param callback\n */\nexport function lchmod(path: string, mode: number | string, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.lchmod(path, mode)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Change file timestamps of the file referenced by the supplied path.\n * @param path\n * @param atime\n * @param mtime\n * @param callback\n */\nexport function utimes(path: string, atime: number | Date, mtime: number | Date, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.utimes(path, atime, mtime)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Change file timestamps of the file referenced by the supplied path.\n * @param path\n * @param atime\n * @param mtime\n * @param callback\n */\nexport function lutimes(path: string, atime: number | Date, mtime: number | Date, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.lutimes(path, atime, mtime)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `realpath`. The callback gets two arguments\n * `(err, resolvedPath)`. May use `process.cwd` to resolve relative paths.\n *\n * @example Usage example\n * let cache = {'/etc':'/private/etc'};\n * fs.realpath('/etc/passwd', cache, function (err, resolvedPath) {\n * if (err) throw err;\n * console.log(resolvedPath);\n * });\n *\n * @param path\n * @param cache An object literal of mapped paths that can be used to\n * force a specific path resolution or avoid additional `fs.stat` calls for\n * known real paths.\n * @param callback\n */\nexport function realpath(path: string, cb?: BFSCallback<string>): void;\nexport function realpath(path: string, cache: { [path: string]: string }, cb: BFSCallback<string>): void;\nexport function realpath(path: string, arg2?: any, cb: BFSCallback<string> = nop): void {\n\tconst cache = typeof arg2 === 'object' ? arg2 : {};\n\tcb = typeof arg2 === 'function' ? arg2 : cb;\n\tpromises\n\t\t.realpath(path, typeof arg2 === 'function' ? null : arg2)\n\t\t.then(result => cb(null, result))\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `access`.\n * @param path\n * @param mode\n * @param callback\n */\nexport function access(path: string, cb: BFSOneArgCallback): void;\nexport function access(path: string, mode: number, cb: BFSOneArgCallback): void;\nexport function access(path: string, arg2: any, cb: BFSOneArgCallback = nop): void {\n\tconst mode = typeof arg2 === 'number' ? arg2 : R_OK;\n\tcb = typeof arg2 === 'function' ? arg2 : cb;\n\tpromises\n\t\t.access(path, typeof arg2 === 'function' ? null : arg2)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\nexport function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): void;\nexport function watchFile(filename: string, options: { persistent?: boolean; interval?: number }, listener: (curr: Stats, prev: Stats) => void): void;\nexport function watchFile(filename: string, arg2: any, listener: (curr: Stats, prev: Stats) => void = nop): void {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n\nexport function unwatchFile(filename: string, listener: (curr: Stats, prev: Stats) => void = nop): void {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n\nexport function watch(filename: string, listener?: (event: string, filename: string) => any): FSWatcher;\nexport function watch(filename: string, options: { persistent?: boolean }, listener?: (event: string, filename: string) => any): FSWatcher;\nexport function watch(filename: string, arg2: any, listener: (event: string, filename: string) => any = nop): FSWatcher {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n\nexport function createReadStream(\n\tpath: string,\n\toptions?: {\n\t\tflags?: string;\n\t\tencoding?: string;\n\t\tfd?: number;\n\t\tmode?: number;\n\t\tautoClose?: boolean;\n\t}\n): ReadStream {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n\nexport function createWriteStream(\n\tpath: string,\n\toptions?: {\n\t\tflags?: string;\n\t\tencoding?: string;\n\t\tfd?: number;\n\t\tmode?: number;\n\t}\n): WriteStream {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n", "import { ApiError, ErrorCode } from '../ApiError';\nimport { File, FileFlag } from '../file';\nimport { FileContents, FileSystem } from '../filesystem';\nimport { Stats } from '../stats';\nimport type { symlink, ReadSyncOptions } from 'fs';\nimport { normalizePath, cred, getFdForFile, normalizeMode, normalizeOptions, fdMap, fd2file, normalizeTime, resolveFS, fixError, mounts } from './shared';\n\ntype FileSystemMethod = {\n\t[K in keyof FileSystem]: FileSystem[K] extends (...args: any) => any\n\t\t? (name: K, resolveSymlinks: boolean, ...args: Parameters<FileSystem[K]>) => ReturnType<FileSystem[K]>\n\t\t: never;\n}[keyof FileSystem]; // https://stackoverflow.com/a/76335220/17637456\n\nfunction doOp<M extends FileSystemMethod, RT extends ReturnType<M>>(...[name, resolveSymlinks, path, ...args]: Parameters<M>): RT {\n\tpath = normalizePath(path);\n\tconst { fs, path: resolvedPath } = resolveFS(resolveSymlinks && existsSync(path) ? realpathSync(path) : path);\n\ttry {\n\t\t// @ts-expect-error 2556 (since ...args is not correctly picked up as being a tuple)\n\t\treturn fs[name](resolvedPath, ...args) as RT;\n\t} catch (e) {\n\t\tthrow fixError(e, { [resolvedPath]: path });\n\t}\n}\n\n/**\n * Synchronous rename.\n * @param oldPath\n * @param newPath\n */\nexport function renameSync(oldPath: string, newPath: string): void {\n\toldPath = normalizePath(oldPath);\n\tnewPath = normalizePath(newPath);\n\tconst _old = resolveFS(oldPath);\n\tconst _new = resolveFS(newPath);\n\tconst paths = { [_old.path]: oldPath, [_new.path]: newPath };\n\ttry {\n\t\tif (_old === _new) {\n\t\t\treturn _old.fs.renameSync(_old.path, _new.path, cred);\n\t\t}\n\n\t\tconst data = readFileSync(oldPath);\n\t\twriteFileSync(newPath, data);\n\t\tunlinkSync(oldPath);\n\t} catch (e) {\n\t\tthrow fixError(e, paths);\n\t}\n}\n\n/**\n * Test whether or not the given path exists by checking with the file system.\n * @param path\n */\nexport function existsSync(path: string): boolean {\n\tpath = normalizePath(path);\n\ttry {\n\t\tconst { fs, path: resolvedPath } = resolveFS(path);\n\t\treturn fs.existsSync(resolvedPath, cred);\n\t} catch (e) {\n\t\tif ((e as ApiError).errno == ErrorCode.ENOENT) {\n\t\t\treturn false;\n\t\t}\n\n\t\tthrow e;\n\t}\n}\n\n/**\n * Synchronous `stat`.\n * @param path\n * @returns Stats\n */\nexport function statSync(path: string): Stats {\n\treturn doOp('statSync', true, path, cred);\n}\n\n/**\n * Synchronous `lstat`.\n * `lstat()` is identical to `stat()`, except that if path is a symbolic link,\n * then the link itself is stat-ed, not the file that it refers to.\n * @param path\n * @return [ZenFS.node.fs.Stats]\n */\nexport function lstatSync(path: string): Stats {\n\treturn doOp('statSync', false, path, cred);\n}\n\n/**\n * Synchronous `truncate`.\n * @param path\n * @param len\n */\nexport function truncateSync(path: string, len: number = 0): void {\n\tif (len < 0) {\n\t\tthrow new ApiError(ErrorCode.EINVAL);\n\t}\n\treturn doOp('truncateSync', true, path, len, cred);\n}\n\n/**\n * Synchronous `unlink`.\n * @param path\n */\nexport function unlinkSync(path: string): void {\n\treturn doOp('unlinkSync', false, path, cred);\n}\n\n/**\n * Synchronous file open.\n * @see http://www.manpagez.com/man/2/open/\n * @param path\n * @param flags\n * @param mode defaults to `0644`\n * @return [ZenFS.File]\n */\nexport function openSync(path: string, flag: string, mode: number | string = 0o644): number {\n\tconst file: File = doOp('openSync', true, path, FileFlag.getFileFlag(flag), normalizeMode(mode, 0o644), cred);\n\treturn getFdForFile(file);\n}\n\n/**\n * Synchronously reads the entire contents of a file.\n * @param filename\n * @param options\n * @option options [String] encoding The string encoding for the file contents. Defaults to `null`.\n * @option options [String] flag Defaults to `'r'`.\n * @return [String | ZenFS.node.Buffer]\n */\nexport function readFileSync(filename: string, options?: { flag?: string }): Buffer;\nexport function readFileSync(filename: string, options: { encoding: string; flag?: string }): string;\nexport function readFileSync(filename: string, encoding: string): string;\nexport function readFileSync(filename: string, arg2: { encoding: string; flag?: string } | { flag?: string } | string = {}): FileContents {\n\tconst options = normalizeOptions(arg2, null, 'r', null);\n\tconst flag = FileFlag.getFileFlag(options.flag);\n\tif (!flag.isReadable()) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Flag passed to readFile must allow for reading.');\n\t}\n\treturn doOp('readFileSync', true, filename, options.encoding, flag, cred);\n}\n\n/**\n * Synchronously writes data to a file, replacing the file if it already\n * exists.\n *\n * The encoding option is ignored if data is a buffer.\n * @param filename\n * @param data\n * @param options\n * @option options [String] encoding Defaults to `'utf8'`.\n * @option options [Number] mode Defaults to `0644`.\n * @option options [String] flag Defaults to `'w'`.\n */\nexport function writeFileSync(filename: string, data: FileContents, options?: { encoding?: string; mode?: number | string; flag?: string }): void;\nexport function writeFileSync(filename: string, data: FileContents, encoding?: string): void;\nexport function writeFileSync(filename: string, data: FileContents, arg3?: { encoding?: string; mode?: number | string; flag?: string } | string): void {\n\tconst options = normalizeOptions(arg3, 'utf8', 'w', 0o644);\n\tconst flag = FileFlag.getFileFlag(options.flag);\n\tif (!flag.isWriteable()) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Flag passed to writeFile must allow for writing.');\n\t}\n\treturn doOp('writeFileSync', true, filename, data, options.encoding, flag, options.mode, cred);\n}\n\n/**\n * Asynchronously append data to a file, creating the file if it not yet\n * exists.\n *\n * @example Usage example\n * fs.appendFile('message.txt', 'data to append', function (err) {\n * if (err) throw err;\n * console.log('The \"data to append\" was appended to file!');\n * });\n * @param filename\n * @param data\n * @param options\n * @option options [String] encoding Defaults to `'utf8'`.\n * @option options [Number] mode Defaults to `0644`.\n * @option options [String] flag Defaults to `'a'`.\n */\nexport function appendFileSync(filename: string, data: FileContents, options?: { encoding?: string; mode?: number | string; flag?: string }): void;\nexport function appendFileSync(filename: string, data: FileContents, encoding?: string): void;\nexport function appendFileSync(filename: string, data: FileContents, arg3?: { encoding?: string; mode?: number | string; flag?: string } | string): void {\n\tconst options = normalizeOptions(arg3, 'utf8', 'a', 0o644);\n\tconst flag = FileFlag.getFileFlag(options.flag);\n\tif (!flag.isAppendable()) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Flag passed to appendFile must allow for appending.');\n\t}\n\treturn doOp('appendFileSync', true, filename, data, options.encoding, flag, options.mode, cred);\n}\n\n/**\n * Synchronous `fstat`.\n * `fstat()` is identical to `stat()`, except that the file to be stat-ed is\n * specified by the file descriptor `fd`.\n * @param fd\n * @return [ZenFS.node.fs.Stats]\n */\nexport function fstatSync(fd: number): Stats {\n\treturn fd2file(fd).statSync();\n}\n\n/**\n * Synchronous close.\n * @param fd\n */\nexport function closeSync(fd: number): void {\n\tfd2file(fd).closeSync();\n\tfdMap.delete(fd);\n}\n\n/**\n * Synchronous ftruncate.\n * @param fd\n * @param len\n */\nexport function ftruncateSync(fd: number, len: number = 0): void {\n\tconst file = fd2file(fd);\n\tif (len < 0) {\n\t\tthrow new ApiError(ErrorCode.EINVAL);\n\t}\n\tfile.truncateSync(len);\n}\n\n/**\n * Synchronous fsync.\n * @param fd\n */\nexport function fsyncSync(fd: number): void {\n\tfd2file(fd).syncSync();\n}\n\n/**\n * Synchronous fdatasync.\n * @param fd\n */\nexport function fdatasyncSync(fd: number): void {\n\tfd2file(fd).datasyncSync();\n}\n\n/**\n * Write buffer to the file specified by `fd`.\n * Note that it is unsafe to use fs.write multiple times on the same file\n * without waiting for it to return.\n * @param fd\n * @param buffer Buffer containing the data to write to\n * the file.\n * @param offset Offset in the buffer to start reading data from.\n * @param length The amount of bytes to write to the file.\n * @param position Offset from the beginning of the file where this\n * data should be written. If position is null, the data will be written at\n * the current position.\n */\nexport function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position?: number | null): number;\nexport function writeSync(fd: number, data: string, position?: number | null, encoding?: BufferEncoding): number;\nexport function writeSync(fd: number, arg2: Buffer | string, arg3?: number, arg4?: BufferEncoding | number, arg5?: number): number {\n\tlet buffer: Buffer,\n\t\toffset: number = 0,\n\t\tlength: number,\n\t\tposition: number | null;\n\tif (typeof arg2 === 'string') {\n\t\t// Signature 1: (fd, string, [position?, [encoding?]])\n\t\tposition = typeof arg3 === 'number' ? arg3 : null;\n\t\tconst encoding = (typeof arg4 === 'string' ? arg4 : 'utf8') as BufferEncoding;\n\t\toffset = 0;\n\t\tbuffer = Buffer.from(arg2, encoding);\n\t\tlength = buffer.length;\n\t} else {\n\t\t// Signature 2: (fd, buffer, offset, length, position?)\n\t\tbuffer = arg2;\n\t\toffset = arg3;\n\t\tlength = arg4 as number;\n\t\tposition = typeof arg5 === 'number' ? arg5 : null;\n\t}\n\n\tconst file = fd2file(fd);\n\tif (position === undefined || position === null) {\n\t\tposition = file.getPos()!;\n\t}\n\treturn file.writeSync(buffer, offset, length, position);\n}\n\n/**\n * Read data from the file specified by `fd`.\n * @param fd\n * @param buffer The buffer that the data will be\n * written to.\n * @param offset The offset within the buffer where writing will\n * start.\n * @param length An integer specifying the number of bytes to read.\n * @param position An integer specifying where to begin reading from\n * in the file. If position is null, data will be read from the current file\n * position.\n */\nexport function readSync(fd: number, buffer: Buffer, opts?: ReadSyncOptions): number;\nexport function readSync(fd: number, buffer: Buffer, offset: number, length: number, position?: number): number;\nexport function readSync(fd: number, buffer: Buffer, opts?: ReadSyncOptions | number, length?: number, position?: number): number {\n\tconst file = fd2file(fd);\n\tlet offset = opts as number;\n\tif (typeof opts == 'object') {\n\t\t({ offset, length, position } = opts);\n\t}\n\n\tif (isNaN(+position)) {\n\t\tposition = file.getPos()!;\n\t}\n\n\treturn file.readSync(buffer, offset, length, position);\n}\n\n/**\n * Synchronous `fchown`.\n * @param fd\n * @param uid\n * @param gid\n */\nexport function fchownSync(fd: number, uid: number, gid: number): void {\n\tfd2file(fd).chownSync(uid, gid);\n}\n\n/**\n * Synchronous `fchmod`.\n * @param fd\n * @param mode\n */\nexport function fchmodSync(fd: number, mode: number | string): void {\n\tconst numMode = typeof mode === 'string' ? parseInt(mode, 8) : mode;\n\tfd2file(fd).chmodSync(numMode);\n}\n\n/**\n * Change the file timestamps of a file referenced by the supplied file\n * descriptor.\n * @param fd\n * @param atime\n * @param mtime\n */\nexport function futimesSync(fd: number, atime: number | Date, mtime: number | Date): void {\n\tfd2file(fd).utimesSync(normalizeTime(atime), normalizeTime(mtime));\n}\n\n// DIRECTORY-ONLY METHODS\n\n/**\n * Synchronous `rmdir`.\n * @param path\n */\nexport function rmdirSync(path: string): void {\n\treturn doOp('rmdirSync', true, path, cred);\n}\n\n/**\n * Synchronous `mkdir`.\n * @param path\n * @param mode defaults to `0777`\n */\nexport function mkdirSync(path: string, mode?: number | string): void {\n\tdoOp('mkdirSync', true, path, normalizeMode(mode, 0o777), cred);\n}\n\n/**\n * Synchronous `readdir`. Reads the contents of a directory.\n * @param path\n * @return [String[]]\n */\nexport function readdirSync(path: string): string[] {\n\tpath = normalizePath(path);\n\tconst entries: string[] = doOp('readdirSync', true, path, cred);\n\tconst points = [...mounts.keys()];\n\tfor (const point of points) {\n\t\tif (point.startsWith(path)) {\n\t\t\tconst entry = point.slice(path.length);\n\t\t\tif (entry.includes('/') || entry.length == 0) {\n\t\t\t\t// ignore FSs mounted in subdirectories and any FS mounted to `path`.\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tentries.push(entry);\n\t\t}\n\t}\n\treturn entries;\n}\n\n// SYMLINK METHODS\n\n/**\n * Synchronous `link`.\n * @param srcpath\n * @param dstpath\n */\nexport function linkSync(srcpath: string, dstpath: string): void {\n\tdstpath = normalizePath(dstpath);\n\treturn doOp('linkSync', false, srcpath, dstpath, cred);\n}\n\n/**\n * Synchronous `symlink`.\n * @param srcpath\n * @param dstpath\n * @param type can be either `'dir'` or `'file'` (default is `'file'`)\n */\nexport function symlinkSync(srcpath: string, dstpath: string, type?: symlink.Type): void {\n\tif (!['file', 'dir', 'junction'].includes(type)) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Invalid type: ' + type);\n\t}\n\tdstpath = normalizePath(dstpath);\n\treturn doOp('symlinkSync', false, srcpath, dstpath, type, cred);\n}\n\n/**\n * Synchronous readlink.\n * @param path\n * @return [String]\n */\nexport function readlinkSync(path: string): string {\n\treturn doOp('readlinkSync', false, path, cred);\n}\n\n// PROPERTY OPERATIONS\n\n/**\n * Synchronous `chown`.\n * @param path\n * @param uid\n * @param gid\n */\nexport function chownSync(path: string, uid: number, gid: number): void {\n\tdoOp('chownSync', true, path, uid, gid, cred);\n}\n\n/**\n * Synchronous `lchown`.\n * @param path\n * @param uid\n * @param gid\n */\nexport function lchownSync(path: string, uid: number, gid: number): void {\n\tdoOp('chownSync', false, path, uid, gid, cred);\n}\n\n/**\n * Synchronous `chmod`.\n * @param path\n * @param mode\n */\nexport function chmodSync(path: string, mode: string | number): void {\n\tconst numMode = normalizeMode(mode, -1);\n\tif (numMode < 0) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, `Invalid mode.`);\n\t}\n\tdoOp('chmodSync', true, path, numMode, cred);\n}\n\n/**\n * Synchronous `lchmod`.\n * @param path\n * @param mode\n */\nexport function lchmodSync(path: string, mode: number | string): void {\n\tconst numMode = normalizeMode(mode, -1);\n\tif (numMode < 1) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, `Invalid mode.`);\n\t}\n\tdoOp('chmodSync', false, path, numMode, cred);\n}\n\n/**\n * Change file timestamps of the file referenced by the supplied path.\n * @param path\n * @param atime\n * @param mtime\n */\nexport function utimesSync(path: string, atime: number | Date, mtime: number | Date): void {\n\tdoOp('utimesSync', true, path, normalizeTime(atime), normalizeTime(mtime), cred);\n}\n\n/**\n * Change file timestamps of the file referenced by the supplied path.\n * @param path\n * @param atime\n * @param mtime\n */\nexport function lutimesSync(path: string, atime: number | Date, mtime: number | Date): void {\n\tdoOp('utimesSync', false, path, normalizeTime(atime), normalizeTime(mtime), cred);\n}\n\n/**\n * Synchronous `realpath`.\n * @param path\n * @param cache An object literal of mapped paths that can be used to\n * force a specific path resolution or avoid additional `fs.stat` calls for\n * known real paths.\n * @return [String]\n */\nexport function realpathSync(path: string, cache: { [path: string]: string } = {}): string {\n\tpath = normalizePath(path);\n\tconst { fs, path: resolvedPath, mountPoint } = resolveFS(path);\n\ttry {\n\t\tconst stats = fs.statSync(resolvedPath, cred);\n\t\tif (!stats.isSymbolicLink()) {\n\t\t\treturn path;\n\t\t}\n\t\tconst dst = normalizePath(mountPoint + fs.readlinkSync(resolvedPath, cred));\n\t\treturn realpathSync(dst);\n\t} catch (e) {\n\t\tthrow fixError(e, { [resolvedPath]: path });\n\t}\n}\n\n/**\n * Synchronous `access`.\n * @param path\n * @param mode\n */\nexport function accessSync(path: string, mode: number = 0o600): void {\n\treturn doOp('accessSync', true, path, mode, cred);\n}\n", "import * as fs_mock from './index';\nimport type * as fs_node from 'node:fs';\n\ntype ZenFSModule = typeof fs_node & typeof fs_mock;\n// @ts-expect-error 2322\nconst fs: ZenFSModule = fs_mock;\n\nexport * from './index';\nexport default fs;\n", "import { type FileSystem, SynchronousFileSystem, FileSystemMetadata } from '../filesystem';\nimport { ApiError, ErrorCode } from '../ApiError';\nimport { File, FileFlag, PreloadFile } from '../file';\nimport { Stats } from '../stats';\nimport * as path from 'path';\nimport { Cred } from '../cred';\nimport { CreateBackend, type BackendOptions } from './backend';\n\n/**\n * @internal\n */\ninterface AsyncOperation {\n\tapiMethod: string;\n\targuments: any[];\n}\n\n/**\n * We define our own file to interpose on syncSync() for mirroring purposes.\n */\nclass MirrorFile extends PreloadFile<AsyncMirror> implements File {\n\tconstructor(fs: AsyncMirror, path: string, flag: FileFlag, stat: Stats, data: Buffer) {\n\t\tsuper(fs, path, flag, stat, data);\n\t}\n\n\tpublic syncSync(): void {\n\t\tif (this.isDirty()) {\n\t\t\tthis._fs._syncSync(this);\n\t\t\tthis.resetDirty();\n\t\t}\n\t}\n\n\tpublic closeSync(): void {\n\t\tthis.syncSync();\n\t}\n}\n\nexport namespace AsyncMirror {\n\t/**\n\t * Configuration options for the AsyncMirror file system.\n\t */\n\texport interface Options {\n\t\t/**\n\t\t * The synchronous file system to mirror the asynchronous file system to.\n\t\t */\n\t\tsync: FileSystem;\n\t\t/**\n\t\t * The asynchronous file system to mirror.\n\t\t */\n\t\tasync: FileSystem;\n\t}\n}\n\n/**\n * AsyncMirrorFS mirrors a synchronous filesystem into an asynchronous filesystem\n * by:\n *\n * * Performing operations over the in-memory copy, while asynchronously pipelining them\n * to the backing store.\n * * During application loading, the contents of the async file system can be reloaded into\n * the synchronous store, if desired.\n *\n * The two stores will be kept in sync. The most common use-case is to pair a synchronous\n * in-memory filesystem with an asynchronous backing store.\n *\n * Example: Mirroring an IndexedDB file system to an in memory file system. Now, you can use\n * IndexedDB synchronously.\n *\n * ```javascript\n * ZenFS.configure({\n * fs: \"AsyncMirror\",\n * options: {\n * sync: { fs: \"InMemory\" },\n * async: { fs: \"IndexedDB\" }\n * }\n * }, function(e) {\n * // ZenFS is initialized and ready-to-use!\n * });\n * ```\n *\n * Or, alternatively:\n *\n * ```javascript\n * ZenFS.Backend.IndexedDB.Create(function(e, idbfs) {\n * ZenFS.Backend.InMemory.Create(function(e, inMemory) {\n * ZenFS.Backend.AsyncMirror({\n * sync: inMemory, async: idbfs\n * }, function(e, mirrored) {\n * ZenFS.initialize(mirrored);\n * });\n * });\n * });\n * ```\n */\nexport class AsyncMirror extends SynchronousFileSystem {\n\tpublic static readonly Name = 'AsyncMirror';\n\n\tpublic static Create = CreateBackend.bind(this);\n\n\tpublic static readonly Options: BackendOptions = {\n\t\tsync: {\n\t\t\ttype: 'object',\n\t\t\tdescription: 'The synchronous file system to mirror the asynchronous file system to.',\n\t\t\tvalidator: async (v: FileSystem): Promise<void> => {\n\t\t\t\tif (!v?.metadata.synchronous) {\n\t\t\t\t\tthrow new ApiError(ErrorCode.EINVAL, `'sync' option must be a file system that supports synchronous operations`);\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\tasync: {\n\t\t\ttype: 'object',\n\t\t\tdescription: 'The asynchronous file system to mirror.',\n\t\t},\n\t};\n\n\tpublic static isAvailable(): boolean {\n\t\treturn true;\n\t}\n\n\t/**\n\t * Queue of pending asynchronous operations.\n\t */\n\tprivate _queue: AsyncOperation[] = [];\n\tprivate _queueRunning: boolean = false;\n\tprivate _sync: FileSystem;\n\tprivate _async: FileSystem;\n\tprivate _isInitialized: boolean = false;\n\tprivate _initializeCallbacks: ((e?: ApiError) => void)[] = [];\n\n\t/**\n\t *\n\t * Mirrors the synchronous file system into the asynchronous file system.\n\t *\n\t * @param sync The synchronous file system to mirror the asynchronous file system to.\n\t * @param async The asynchronous file system to mirror.\n\t */\n\tconstructor({ sync, async }: AsyncMirror.Options) {\n\t\tsuper();\n\t\tthis._sync = sync;\n\t\tthis._async = async;\n\t\tthis._ready = this._initialize();\n\t}\n\n\tpublic get metadata(): FileSystemMetadata {\n\t\treturn {\n\t\t\t...super.metadata,\n\t\t\tname: AsyncMirror.Name,\n\t\t\tsynchronous: true,\n\t\t\tsupportsProperties: this._sync.metadata.supportsProperties && this._async.metadata.supportsProperties,\n\t\t};\n\t}\n\n\tpublic _syncSync(fd: PreloadFile<AsyncMirror>) {\n\t\tconst stats = fd.getStats();\n\t\tthis._sync.writeFileSync(fd.getPath(), fd.getBuffer(), null, FileFlag.getFileFlag('w'), stats.mode, stats.getCred(0, 0));\n\t\tthis.enqueueOp({\n\t\t\tapiMethod: 'writeFile',\n\t\t\targuments: [fd.getPath(), fd.getBuffer(), null, fd.getFlag(), stats.mode, stats.getCred(0, 0)],\n\t\t});\n\t}\n\n\tpublic renameSync(oldPath: string, newPath: string, cred: Cred): void {\n\t\tthis._sync.renameSync(oldPath, newPath, cred);\n\t\tthis.enqueueOp({\n\t\t\tapiMethod: 'rename',\n\t\t\targuments: [oldPath, newPath, cred],\n\t\t});\n\t}\n\n\tpublic statSync(p: string, cred: Cred): Stats {\n\t\treturn this._sync.statSync(p, cred);\n\t}\n\n\tpublic openSync(p: string, flag: FileFlag, mode: number, cred: Cred): File {\n\t\t// Sanity check: Is this open/close permitted?\n\t\tconst fd = this._sync.openSync(p, flag, mode, cred);\n\t\tfd.closeSync();\n\t\treturn new MirrorFile(this, p, flag, this._sync.statSync(p, cred), <Buffer>this._sync.readFileSync(p, null, FileFlag.getFileFlag('r'), cred));\n\t}\n\n\tpublic unlinkSync(p: string, cred: Cred): void {\n\t\tthis._sync.unlinkSync(p, cred);\n\t\tthis.enqueueOp({\n\t\t\tapiMethod: 'unlink',\n\t\t\targuments: [p, cred],\n\t\t});\n\t}\n\n\tpublic rmdirSync(p: string, cred: Cred): void {\n\t\tthis._sync.rmdirSync(p, cred);\n\t\tthis.enqueueOp({\n\t\t\tapiMethod: 'rmdir',\n\t\t\targuments: [p, cred],\n\t\t});\n\t}\n\n\tpublic mkdirSync(p: string, mode: number, cred: Cred): void {\n\t\tthis._sync.mkdirSync(p, mode, cred);\n\t\tthis.enqueueOp({\n\t\t\tapiMethod: 'mkdir',\n\t\t\targuments: [p, mode, cred],\n\t\t});\n\t}\n\n\tpublic readdirSync(p: string, cred: Cred): string[] {\n\t\treturn this._sync.readdirSync(p, cred);\n\t}\n\n\tpublic existsSync(p: string, cred: Cred): boolean {\n\t\treturn this._sync.existsSync(p, cred);\n\t}\n\n\tpublic chmodSync(p: string, mode: number, cred: Cred): void {\n\t\tthis._sync.chmodSync(p, mode, cred);\n\t\tthis.enqueueOp({\n\t\t\tapiMethod: 'chmod',\n\t\t\targuments: [p, mode, cred],\n\t\t});\n\t}\n\n\tpublic chownSync(p: string, new_uid: number, new_gid: number, cred: Cred): void {\n\t\tthis._sync.chownSync(p, new_uid, new_gid, cred);\n\t\tthis.enqueueOp({\n\t\t\tapiMethod: 'chown',\n\t\t\targuments: [p, new_uid, new_gid, cred],\n\t\t});\n\t}\n\n\tpublic utimesSync(p: string, atime: Date, mtime: Date, cred: Cred): void {\n\t\tthis._sync.utimesSync(p, atime, mtime, cred);\n\t\tthis.enqueueOp({\n\t\t\tapiMethod: 'utimes',\n\t\t\targuments: [p, atime, mtime, cred],\n\t\t});\n\t}\n\n\t/**\n\t * Called once to load up files from async storage into sync storage.\n\t */\n\tprivate async _initialize(): Promise<this> {\n\t\tif (!this._isInitialized) {\n\t\t\t// First call triggers initialization, the rest wait.\n\t\t\tconst copyDirectory = async (p: string, mode: number): Promise<void> => {\n\t\t\t\t\tif (p !== '/') {\n\t\t\t\t\t\tconst stats = await this._async.stat(p, Cred.Root);\n\t\t\t\t\t\tthis._sync.mkdirSync(p, mode, stats.getCred());\n\t\t\t\t\t}\n\t\t\t\t\tconst files = await this._async.readdir(p, Cred.Root);\n\t\t\t\t\tfor (const file of files) {\n\t\t\t\t\t\tawait copyItem(path.join(p, file));\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tcopyFile = async (p: string, mode: number): Promise<void> => {\n\t\t\t\t\tconst data = await this._async.readFile(p, null, FileFlag.getFileFlag('r'), Cred.Root);\n\t\t\t\t\tthis._sync.writeFileSync(p, data, null, FileFlag.getFileFlag('w'), mode, Cred.Root);\n\t\t\t\t},\n\t\t\t\tcopyItem = async (p: string): Promise<void> => {\n\t\t\t\t\tconst stats = await this._async.stat(p, Cred.Root);\n\t\t\t\t\tif (stats.isDirectory()) {\n\t\t\t\t\t\tawait copyDirectory(p, stats.mode);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tawait copyFile(p, stats.mode);\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\ttry {\n\t\t\t\tawait copyDirectory('/', 0);\n\t\t\t\tthis._isInitialized = true;\n\t\t\t} catch (e) {\n\t\t\t\tthis._isInitialized = false;\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\tprivate enqueueOp(op: AsyncOperation) {\n\t\tthis._queue.push(op);\n\t\tif (!this._queueRunning) {\n\t\t\tthis._queueRunning = true;\n\t\t\tconst doNextOp = (err?: ApiError) => {\n\t\t\t\tif (err) {\n\t\t\t\t\tthrow new Error(`WARNING: File system has desynchronized. Received following error: ${err}\\n$`);\n\t\t\t\t}\n\t\t\t\tif (this._queue.length > 0) {\n\t\t\t\t\tconst op = this._queue.shift()!;\n\t\t\t\t\top.arguments.push(doNextOp);\n\t\t\t\t\t(<Function>this._async[op.apiMethod]).apply(this._async, op.arguments);\n\t\t\t\t} else {\n\t\t\t\t\tthis._queueRunning = false;\n\t\t\t\t}\n\t\t\t};\n\t\t\tdoNextOp();\n\t\t}\n\t}\n}\n", "import { BaseFileSystem, type FileSystem } from '../filesystem';\nimport * as path from 'path';\nimport { ApiError } from '../ApiError';\nimport { Cred } from '../cred';\nimport { CreateBackend, type BackendOptions } from './backend';\n\nexport namespace FolderAdapter {\n\t/**\n\t * Configuration options for a FolderAdapter file system.\n\t */\n\texport interface Options {\n\t\t// The folder to use as the root directory.\n\t\tfolder: string;\n\t\t// The file system to wrap.\n\t\twrapped: FileSystem;\n\t}\n}\n\n/**\n * The FolderAdapter file system wraps a file system, and scopes all interactions to a subfolder of that file system.\n *\n * Example: Given a file system `foo` with folder `bar` and file `bar/baz`...\n *\n * ```javascript\n * ZenFS.configure({\n * fs: \"FolderAdapter\",\n * options: {\n * folder: \"bar\",\n * wrapped: foo\n * }\n * }, function(e) {\n * var fs = ZenFS.BFSRequire('fs');\n * fs.readdirSync('/'); // ['baz']\n * });\n * ```\n */\nexport class FolderAdapter extends BaseFileSystem {\n\tpublic static readonly Name = 'FolderAdapter';\n\n\tpublic static Create = CreateBackend.bind(this);\n\n\tpublic static readonly Options: BackendOptions = {\n\t\tfolder: {\n\t\t\ttype: 'string',\n\t\t\tdescription: 'The folder to use as the root directory',\n\t\t},\n\t\twrapped: {\n\t\t\ttype: 'object',\n\t\t\tdescription: 'The file system to wrap',\n\t\t},\n\t};\n\n\tpublic static isAvailable(): boolean {\n\t\treturn true;\n\t}\n\n\tpublic _wrapped: FileSystem;\n\tpublic _folder: string;\n\n\tpublic constructor({ folder, wrapped }: FolderAdapter.Options) {\n\t\tsuper();\n\t\tthis._folder = folder;\n\t\tthis._wrapped = wrapped;\n\t\tthis._ready = this._initialize();\n\t}\n\n\tpublic get metadata() {\n\t\treturn { ...super.metadata, ...this._wrapped.metadata, supportsLinks: false };\n\t}\n\n\t/**\n\t * Initialize the file system. Ensures that the wrapped file system\n\t * has the given folder.\n\t */\n\tprivate async _initialize(): Promise<this> {\n\t\tconst exists = await this._wrapped.exists(this._folder, Cred.Root);\n\t\tif (!exists && this._wrapped.metadata.readonly) {\n\t\t\tthrow ApiError.ENOENT(this._folder);\n\t\t}\n\t\tawait this._wrapped.mkdir(this._folder, 0o777, Cred.Root);\n\t\treturn this;\n\t}\n}\n\n/**\n * @internal\n */\nfunction translateError(folder: string, e: any): any {\n\tif (e !== null && typeof e === 'object') {\n\t\tconst err = <ApiError>e;\n\t\tlet p = err.path;\n\t\tif (p) {\n\t\t\tp = '/' + path.relative(folder, p);\n\t\t\terr.message = err.message.replace(err.path!, p);\n\t\t\terr.path = p;\n\t\t}\n\t}\n\treturn e;\n}\n\n/**\n * @internal\n */\nfunction wrapCallback(folder: string, cb: any): any {\n\tif (typeof cb === 'function') {\n\t\treturn function (err: ApiError) {\n\t\t\tif (arguments.length > 0) {\n\t\t\t\targuments[0] = translateError(folder, err);\n\t\t\t}\n\t\t\t(<Function>cb).apply(null, arguments);\n\t\t};\n\t} else {\n\t\treturn cb;\n\t}\n}\n\n/**\n * @internal\n */\nfunction wrapFunction(name: string, wrapFirst: boolean, wrapSecond: boolean): Function {\n\tif (name.slice(name.length - 4) !== 'Sync') {\n\t\t// Async function. Translate error in callback.\n\t\treturn function (this: FolderAdapter) {\n\t\t\tif (arguments.length > 0) {\n\t\t\t\tif (wrapFirst) {\n\t\t\t\t\targuments[0] = path.join(this._folder, arguments[0]);\n\t\t\t\t}\n\t\t\t\tif (wrapSecond) {\n\t\t\t\t\targuments[1] = path.join(this._folder, arguments[1]);\n\t\t\t\t}\n\t\t\t\targuments[arguments.length - 1] = wrapCallback(this._folder, arguments[arguments.length - 1]);\n\t\t\t}\n\t\t\treturn (<any>this._wrapped)[name].apply(this._wrapped, arguments);\n\t\t};\n\t} else {\n\t\t// Sync function. Translate error in catch.\n\t\treturn function (this: FolderAdapter) {\n\t\t\ttry {\n\t\t\t\tif (wrapFirst) {\n\t\t\t\t\targuments[0] = path.join(this._folder, arguments[0]);\n\t\t\t\t}\n\t\t\t\tif (wrapSecond) {\n\t\t\t\t\targuments[1] = path.join(this._folder, arguments[1]);\n\t\t\t\t}\n\t\t\t\treturn (<any>this._wrapped)[name].apply(this._wrapped, arguments);\n\t\t\t} catch (e) {\n\t\t\t\tthrow translateError(this._folder, e);\n\t\t\t}\n\t\t};\n\t}\n}\n\n// First argument is a path.\n[\n\t'diskSpace',\n\t'stat',\n\t'statSync',\n\t'open',\n\t'openSync',\n\t'unlink',\n\t'unlinkSync',\n\t'rmdir',\n\t'rmdirSync',\n\t'mkdir',\n\t'mkdirSync',\n\t'readdir',\n\t'readdirSync',\n\t'exists',\n\t'existsSync',\n\t'realpath',\n\t'realpathSync',\n\t'truncate',\n\t'truncateSync',\n\t'readFile',\n\t'readFileSync',\n\t'writeFile',\n\t'writeFileSync',\n\t'appendFile',\n\t'appendFileSync',\n\t'chmod',\n\t'chmodSync',\n\t'chown',\n\t'chownSync',\n\t'utimes',\n\t'utimesSync',\n\t'readlink',\n\t'readlinkSync',\n].forEach((name: string) => {\n\t(<any>FolderAdapter.prototype)[name] = wrapFunction(name, true, false);\n});\n\n// First and second arguments are paths.\n['rename', 'renameSync', 'link', 'linkSync', 'symlink', 'symlinkSync'].forEach((name: string) => {\n\t(<any>FolderAdapter.prototype)[name] = wrapFunction(name, true, true);\n});\n", "export type MutexCallback = () => void;\n\n/**\n * Non-recursive mutex\n * @internal\n */\nexport default class Mutex {\n\tprivate _locks: Map<string, MutexCallback[]> = new Map();\n\n\tpublic lock(path: string): Promise<void> {\n\t\treturn new Promise(resolve => {\n\t\t\tif (this._locks.has(path)) {\n\t\t\t\tthis._locks.get(path).push(resolve);\n\t\t\t} else {\n\t\t\t\tthis._locks.set(path, []);\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic unlock(path: string): void {\n\t\tif (!this._locks.has(path)) {\n\t\t\tthrow new Error('unlock of a non-locked mutex');\n\t\t}\n\n\t\tconst next = this._locks.get(path).shift();\n\t\t/* \n\t\t\tdon't unlock - we want to queue up next for the\n\t\t\tend of the current task execution, but we don't\n\t\t\twant it to be called inline with whatever the\n\t\t\tcurrent stack is. This way we still get the nice\n\t\t\tbehavior that an unlock immediately followed by a\n\t\t\tlock won't cause starvation.\n\t\t*/\n\t\tif (next) {\n\t\t\tsetTimeout(next, 0);\n\t\t\treturn;\n\t\t}\n\n\t\tthis._locks.delete(path);\n\t}\n\n\tpublic tryLock(path: string): boolean {\n\t\tif (this._locks.has(path)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tthis._locks.set(path, []);\n\t\treturn true;\n\t}\n\n\tpublic isLocked(path: string): boolean {\n\t\treturn this._locks.has(path);\n\t}\n}\n", "import Mutex from '../mutex';\nimport { FileContents, FileSystem, FileSystemMetadata } from '../filesystem';\nimport { FileFlag } from '../file';\nimport { Stats } from '../stats';\nimport { File } from '../file';\nimport { Cred } from '../cred';\n\n/**\n * This class serializes access to an underlying async filesystem.\n * For example, on an OverlayFS instance with an async lower\n * directory operations like rename and rmdir may involve multiple\n * requests involving both the upper and lower filesystems -- they\n * are not executed in a single atomic step. OverlayFS uses this\n * LockedFS to avoid having to reason about the correctness of\n * multiple requests interleaving.\n */\nexport default class LockedFS<T extends FileSystem> implements FileSystem {\n\tprivate _fs: T;\n\tprivate _mu: Mutex;\n\n\tprotected _ready: Promise<this> = Promise.resolve(this);\n\n\tconstructor(fs: T) {\n\t\tthis._fs = fs;\n\t\tthis._mu = new Mutex();\n\t}\n\n\twhenReady(): Promise<this> {\n\t\treturn this._ready;\n\t}\n\n\tpublic get metadata(): FileSystemMetadata {\n\t\treturn {\n\t\t\t...this._fs.metadata,\n\t\t\tname: 'LockedFS<' + this._fs.metadata.name + '>',\n\t\t};\n\t}\n\n\tpublic get fs(): T {\n\t\treturn this._fs;\n\t}\n\n\tpublic async rename(oldPath: string, newPath: string, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(oldPath);\n\t\tawait this._fs.rename(oldPath, newPath, cred);\n\t\tthis._mu.unlock(oldPath);\n\t}\n\n\tpublic renameSync(oldPath: string, newPath: string, cred: Cred): void {\n\t\tif (this._mu.isLocked(oldPath)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.renameSync(oldPath, newPath, cred);\n\t}\n\n\tpublic async stat(p: string, cred: Cred): Promise<Stats> {\n\t\tawait this._mu.lock(p);\n\t\tconst stats = await this._fs.stat(p, cred);\n\t\tthis._mu.unlock(p);\n\t\treturn stats;\n\t}\n\n\tpublic statSync(p: string, cred: Cred): Stats {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.statSync(p, cred);\n\t}\n\n\tpublic async access(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(p);\n\t\tawait this._fs.access(p, mode, cred);\n\t\tthis._mu.unlock(p);\n\t}\n\n\tpublic accessSync(p: string, mode: number, cred: Cred): void {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.accessSync(p, mode, cred);\n\t}\n\n\tpublic async open(p: string, flag: FileFlag, mode: number, cred: Cred): Promise<File> {\n\t\tawait this._mu.lock(p);\n\t\tconst fd = await this._fs.open(p, flag, mode, cred);\n\t\tthis._mu.unlock(p);\n\t\treturn fd;\n\t}\n\n\tpublic openSync(p: string, flag: FileFlag, mode: number, cred: Cred): File {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.openSync(p, flag, mode, cred);\n\t}\n\n\tpublic async unlink(p: string, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(p);\n\t\tawait this._fs.unlink(p, cred);\n\t\tthis._mu.unlock(p);\n\t}\n\n\tpublic unlinkSync(p: string, cred: Cred): void {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.unlinkSync(p, cred);\n\t}\n\n\tpublic async rmdir(p: string, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(p);\n\t\tawait this._fs.rmdir(p, cred);\n\t\tthis._mu.unlock(p);\n\t}\n\n\tpublic rmdirSync(p: string, cred: Cred): void {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.rmdirSync(p, cred);\n\t}\n\n\tpublic async mkdir(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(p);\n\t\tawait this._fs.mkdir(p, mode, cred);\n\t\tthis._mu.unlock(p);\n\t}\n\n\tpublic mkdirSync(p: string, mode: number, cred: Cred): void {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.mkdirSync(p, mode, cred);\n\t}\n\n\tpublic async readdir(p: string, cred: Cred): Promise<string[]> {\n\t\tawait this._mu.lock(p);\n\t\tconst files = await this._fs.readdir(p, cred);\n\t\tthis._mu.unlock(p);\n\t\treturn files;\n\t}\n\n\tpublic readdirSync(p: string, cred: Cred): string[] {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.readdirSync(p, cred);\n\t}\n\n\tpublic async exists(p: string, cred: Cred): Promise<boolean> {\n\t\tawait this._mu.lock(p);\n\t\tconst exists = await this._fs.exists(p, cred);\n\t\tthis._mu.unlock(p);\n\t\treturn exists;\n\t}\n\n\tpublic existsSync(p: string, cred: Cred): boolean {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.existsSync(p, cred);\n\t}\n\n\tpublic async realpath(p: string, cred: Cred): Promise<string> {\n\t\tawait this._mu.lock(p);\n\t\tconst resolvedPath = await this._fs.realpath(p, cred);\n\t\tthis._mu.unlock(p);\n\t\treturn resolvedPath;\n\t}\n\n\tpublic realpathSync(p: string, cred: Cred): string {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.realpathSync(p, cred);\n\t}\n\n\tpublic async truncate(p: string, len: number, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(p);\n\t\tawait this._fs.truncate(p, len, cred);\n\t\tthis._mu.unlock(p);\n\t}\n\n\tpublic truncateSync(p: string, len: number, cred: Cred): void {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.truncateSync(p, len, cred);\n\t}\n\n\tpublic async readFile(fname: string, encoding: BufferEncoding, flag: FileFlag, cred: Cred): Promise<FileContents> {\n\t\tawait this._mu.lock(fname);\n\t\tconst data = await this._fs.readFile(fname, encoding, flag, cred);\n\t\tthis._mu.unlock(fname);\n\t\treturn data;\n\t}\n\n\tpublic readFileSync(fname: string, encoding: BufferEncoding, flag: FileFlag, cred: Cred): FileContents {\n\t\tif (this._mu.isLocked(fname)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.readFileSync(fname, encoding, flag, cred);\n\t}\n\n\tpublic async writeFile(fname: string, data: FileContents, encoding: BufferEncoding, flag: FileFlag, mode: number, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(fname);\n\t\tawait this._fs.writeFile(fname, data, encoding, flag, mode, cred);\n\t\tthis._mu.unlock(fname);\n\t}\n\n\tpublic writeFileSync(fname: string, data: FileContents, encoding: BufferEncoding, flag: FileFlag, mode: number, cred: Cred): void {\n\t\tif (this._mu.isLocked(fname)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.writeFileSync(fname, data, encoding, flag, mode, cred);\n\t}\n\n\tpublic async appendFile(fname: string, data: FileContents, encoding: BufferEncoding, flag: FileFlag, mode: number, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(fname);\n\t\tawait this._fs.appendFile(fname, data, encoding, flag, mode, cred);\n\t\tthis._mu.unlock(fname);\n\t}\n\n\tpublic appendFileSync(fname: string, data: FileContents, encoding: BufferEncoding, flag: FileFlag, mode: number, cred: Cred): void {\n\t\tif (this._mu.isLocked(fname)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.appendFileSync(fname, data, encoding, flag, mode, cred);\n\t}\n\n\tpublic async chmod(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(p);\n\t\tawait this._fs.chmod(p, mode, cred);\n\t\tthis._mu.unlock(p);\n\t}\n\n\tpublic chmodSync(p: string, mode: number, cred: Cred): void {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.chmodSync(p, mode, cred);\n\t}\n\n\tpublic async chown(p: string, new_uid: number, new_gid: number, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(p);\n\t\tawait this._fs.chown(p, new_uid, new_gid, cred);\n\t\tthis._mu.unlock(p);\n\t}\n\n\tpublic chownSync(p: string, new_uid: number, new_gid: number, cred: Cred): void {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.chownSync(p, new_uid, new_gid, cred);\n\t}\n\n\tpublic async utimes(p: string, atime: Date, mtime: Date, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(p);\n\t\tawait this._fs.utimes(p, atime, mtime, cred);\n\t\tthis._mu.unlock(p);\n\t}\n\n\tpublic utimesSync(p: string, atime: Date, mtime: Date, cred: Cred): void {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.utimesSync(p, atime, mtime, cred);\n\t}\n\n\tpublic async link(srcpath: string, dstpath: string, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(srcpath);\n\t\tawait this._fs.link(srcpath, dstpath, cred);\n\t\tthis._mu.unlock(srcpath);\n\t}\n\n\tpublic linkSync(srcpath: string, dstpath: string, cred: Cred): void {\n\t\tif (this._mu.isLocked(srcpath)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.linkSync(srcpath, dstpath, cred);\n\t}\n\n\tpublic async symlink(srcpath: string, dstpath: string, type: string, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(srcpath);\n\t\tawait this._fs.symlink(srcpath, dstpath, type, cred);\n\t\tthis._mu.unlock(srcpath);\n\t}\n\n\tpublic symlinkSync(srcpath: string, dstpath: string, type: string, cred: Cred): void {\n\t\tif (this._mu.isLocked(srcpath)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.symlinkSync(srcpath, dstpath, type, cred);\n\t}\n\n\tpublic async readlink(p: string, cred: Cred): Promise<string> {\n\t\tawait this._mu.lock(p);\n\t\tconst linkString = await this._fs.readlink(p, cred);\n\t\tthis._mu.unlock(p);\n\t\treturn linkString;\n\t}\n\n\tpublic readlinkSync(p: string, cred: Cred): string {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.readlinkSync(p, cred);\n\t}\n}\n", "import { type FileSystem, BaseFileSystem, FileSystemMetadata } from '../filesystem';\nimport { ApiError, ErrorCode } from '../ApiError';\nimport { File, FileFlag, ActionType, PreloadFile } from '../file';\nimport { Stats } from '../stats';\nimport LockedFS from './Locked';\nimport * as path from 'path';\nimport { Cred } from '../cred';\nimport type { Buffer } from 'buffer';\nimport { CreateBackend, type BackendOptions } from './backend';\n/**\n * @internal\n */\nconst deletionLogPath = '/.deletedFiles.log';\n\n/**\n * Given a read-only mode, makes it writable.\n * @internal\n */\nfunction makeModeWritable(mode: number): number {\n\treturn 0o222 | mode;\n}\n\n/**\n * @internal\n */\nfunction getFlag(f: string): FileFlag {\n\treturn FileFlag.getFileFlag(f);\n}\n\n/**\n * Overlays a RO file to make it writable.\n */\nclass OverlayFile extends PreloadFile<UnlockedOverlayFS> implements File {\n\tconstructor(fs: UnlockedOverlayFS, path: string, flag: FileFlag, stats: Stats, data: Buffer) {\n\t\tsuper(fs, path, flag, stats, data);\n\t}\n\n\tpublic async sync(): Promise<void> {\n\t\tif (!this.isDirty()) {\n\t\t\treturn;\n\t\t}\n\n\t\tawait this._fs._syncAsync(this);\n\t\tthis.resetDirty();\n\t}\n\n\tpublic syncSync(): void {\n\t\tif (this.isDirty()) {\n\t\t\tthis._fs._syncSync(this);\n\t\t\tthis.resetDirty();\n\t\t}\n\t}\n\n\tpublic async close(): Promise<void> {\n\t\tawait this.sync();\n\t}\n\n\tpublic closeSync(): void {\n\t\tthis.syncSync();\n\t}\n}\n\nexport namespace OverlayFS {\n\t/**\n\t * Configuration options for OverlayFS instances.\n\t */\n\texport interface Options {\n\t\t/**\n\t\t * The file system to write modified files to.\n\t\t */\n\t\twritable: FileSystem;\n\t\t/**\n\t\t * The file system that initially populates this file system.\n\t\t */\n\t\treadable: FileSystem;\n\t}\n}\n\n/**\n * *INTERNAL, DO NOT USE DIRECTLY!*\n *\n * Core OverlayFS class that contains no locking whatsoever. We wrap these objects\n * in a LockedFS to prevent races.\n */\nexport class UnlockedOverlayFS extends BaseFileSystem {\n\tpublic static isAvailable(): boolean {\n\t\treturn true;\n\t}\n\n\tprivate _writable: FileSystem;\n\tprivate _readable: FileSystem;\n\tprivate _isInitialized: boolean = false;\n\tprivate _deletedFiles: { [path: string]: boolean } = {};\n\tprivate _deleteLog: string = '';\n\t// If 'true', we have scheduled a delete log update.\n\tprivate _deleteLogUpdatePending: boolean = false;\n\t// If 'true', a delete log update is needed after the scheduled delete log\n\t// update finishes.\n\tprivate _deleteLogUpdateNeeded: boolean = false;\n\t// If there was an error updating the delete log...\n\tprivate _deleteLogError: ApiError | null = null;\n\n\tconstructor({ writable, readable }: OverlayFS.Options) {\n\t\tsuper();\n\t\tthis._writable = writable;\n\t\tthis._readable = readable;\n\t\tif (this._writable.metadata.readonly) {\n\t\t\tthrow new ApiError(ErrorCode.EINVAL, 'Writable file system must be writable.');\n\t\t}\n\t}\n\n\tpublic get metadata(): FileSystemMetadata {\n\t\treturn {\n\t\t\t...super.metadata,\n\t\t\tname: OverlayFS.Name,\n\t\t\tsynchronous: this._readable.metadata.synchronous && this._writable.metadata.synchronous,\n\t\t\tsupportsProperties: this._readable.metadata.supportsProperties && this._writable.metadata.supportsProperties,\n\t\t};\n\t}\n\n\tpublic getOverlayedFileSystems(): { readable: FileSystem; writable: FileSystem } {\n\t\treturn {\n\t\t\treadable: this._readable,\n\t\t\twritable: this._writable,\n\t\t};\n\t}\n\n\tpublic async _syncAsync(file: PreloadFile<UnlockedOverlayFS>): Promise<void> {\n\t\tconst stats = file.getStats();\n\t\tawait this.createParentDirectoriesAsync(file.getPath(), stats.getCred(0, 0));\n\t\treturn this._writable.writeFile(file.getPath(), file.getBuffer(), null, getFlag('w'), stats.mode, stats.getCred(0, 0));\n\t}\n\n\tpublic _syncSync(file: PreloadFile<UnlockedOverlayFS>): void {\n\t\tconst stats = file.getStats();\n\t\tthis.createParentDirectories(file.getPath(), stats.getCred(0, 0));\n\t\tthis._writable.writeFileSync(file.getPath(), file.getBuffer(), null, getFlag('w'), stats.mode, stats.getCred(0, 0));\n\t}\n\n\t/**\n\t * **INTERNAL METHOD**\n\t *\n\t * Called once to load up metadata stored on the writable file system.\n\t */\n\tpublic async _initialize(): Promise<void> {\n\t\t// if we're already initialized, immediately invoke the callback\n\t\tif (this._isInitialized) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Read deletion log, process into metadata.\n\t\ttry {\n\t\t\tconst data = (await this._writable.readFile(deletionLogPath, 'utf8', getFlag('r'), Cred.Root)) as string;\n\t\t\tthis._deleteLog = data;\n\t\t} catch (err) {\n\t\t\tif (err.errno !== ErrorCode.ENOENT) {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t}\n\t\tthis._isInitialized = true;\n\t\tthis._reparseDeletionLog();\n\t}\n\n\tpublic getDeletionLog(): string {\n\t\treturn this._deleteLog;\n\t}\n\n\tpublic restoreDeletionLog(log: string, cred: Cred): void {\n\t\tthis._deleteLog = log;\n\t\tthis._reparseDeletionLog();\n\t\tthis.updateLog('', cred);\n\t}\n\n\tpublic async rename(oldPath: string, newPath: string, cred: Cred): Promise<void> {\n\t\tthis.checkInitialized();\n\t\tthis.checkPath(oldPath);\n\t\tthis.checkPath(newPath);\n\t\tif (oldPath === deletionLogPath || newPath === deletionLogPath) {\n\t\t\tthrow ApiError.EPERM('Cannot rename deletion log.');\n\t\t}\n\t\t// Write newPath using oldPath's contents, delete oldPath.\n\t\tconst oldStats = await this.stat(oldPath, cred);\n\t\tif (oldStats.isDirectory()) {\n\t\t\t// Optimization: Don't bother moving if old === new.\n\t\t\tif (oldPath === newPath) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet mode = 0o777;\n\t\t\tif (await this.exists(newPath, cred)) {\n\t\t\t\tconst stats = await this.stat(newPath, cred);\n\t\t\t\tmode = stats.mode;\n\t\t\t\tif (stats.isDirectory()) {\n\t\t\t\t\tif ((await this.readdir(newPath, cred)).length > 0) {\n\t\t\t\t\t\tthrow ApiError.ENOTEMPTY(newPath);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tthrow ApiError.ENOTDIR(newPath);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Take care of writable first. Move any files there, or create an empty directory\n\t\t\t// if it doesn't exist.\n\t\t\tif (await this._writable.exists(oldPath, cred)) {\n\t\t\t\tawait this._writable.rename(oldPath, newPath, cred);\n\t\t\t} else if (!(await this._writable.exists(newPath, cred))) {\n\t\t\t\tawait this._writable.mkdir(newPath, mode, cred);\n\t\t\t}\n\n\t\t\t// Need to move *every file/folder* currently stored on readable to its new location\n\t\t\t// on writable.\n\t\t\tif (await this._readable.exists(oldPath, cred)) {\n\t\t\t\tfor (const name of await this._readable.readdir(oldPath, cred)) {\n\t\t\t\t\t// Recursion! Should work for any nested files / folders.\n\t\t\t\t\tawait this.rename(path.resolve(oldPath, name), path.resolve(newPath, name), cred);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ((await this.exists(newPath, cred)) && (await this.stat(newPath, cred)).isDirectory()) {\n\t\t\t\tthrow ApiError.EISDIR(newPath);\n\t\t\t}\n\n\t\t\tawait this.writeFile(newPath, await this.readFile(oldPath, null, getFlag('r'), cred), null, getFlag('w'), oldStats.mode, cred);\n\t\t}\n\n\t\tif (oldPath !== newPath && (await this.exists(oldPath, cred))) {\n\t\t\tawait this.unlink(oldPath, cred);\n\t\t}\n\t}\n\n\tpublic renameSync(oldPath: string, newPath: string, cred: Cred): void {\n\t\tthis.checkInitialized();\n\t\tthis.checkPath(oldPath);\n\t\tthis.checkPath(newPath);\n\t\tif (oldPath === deletionLogPath || newPath === deletionLogPath) {\n\t\t\tthrow ApiError.EPERM('Cannot rename deletion log.');\n\t\t}\n\t\t// Write newPath using oldPath's contents, delete oldPath.\n\t\tconst oldStats = this.statSync(oldPath, cred);\n\t\tif (oldStats.isDirectory()) {\n\t\t\t// Optimization: Don't bother moving if old === new.\n\t\t\tif (oldPath === newPath) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet mode = 0o777;\n\t\t\tif (this.existsSync(newPath, cred)) {\n\t\t\t\tconst stats = this.statSync(newPath, cred);\n\t\t\t\tmode = stats.mode;\n\t\t\t\tif (stats.isDirectory()) {\n\t\t\t\t\tif (this.readdirSync(newPath, cred).length > 0) {\n\t\t\t\t\t\tthrow ApiError.ENOTEMPTY(newPath);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tthrow ApiError.ENOTDIR(newPath);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Take care of writable first. Move any files there, or create an empty directory\n\t\t\t// if it doesn't exist.\n\t\t\tif (this._writable.existsSync(oldPath, cred)) {\n\t\t\t\tthis._writable.renameSync(oldPath, newPath, cred);\n\t\t\t} else if (!this._writable.existsSync(newPath, cred)) {\n\t\t\t\tthis._writable.mkdirSync(newPath, mode, cred);\n\t\t\t}\n\n\t\t\t// Need to move *every file/folder* currently stored on readable to its new location\n\t\t\t// on writable.\n\t\t\tif (this._readable.existsSync(oldPath, cred)) {\n\t\t\t\tthis._readable.readdirSync(oldPath, cred).forEach(name => {\n\t\t\t\t\t// Recursion! Should work for any nested files / folders.\n\t\t\t\t\tthis.renameSync(path.resolve(oldPath, name), path.resolve(newPath, name), cred);\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tif (this.existsSync(newPath, cred) && this.statSync(newPath, cred).isDirectory()) {\n\t\t\t\tthrow ApiError.EISDIR(newPath);\n\t\t\t}\n\n\t\t\tthis.writeFileSync(newPath, this.readFileSync(oldPath, null, getFlag('r'), cred), null, getFlag('w'), oldStats.mode, cred);\n\t\t}\n\n\t\tif (oldPath !== newPath && this.existsSync(oldPath, cred)) {\n\t\t\tthis.unlinkSync(oldPath, cred);\n\t\t}\n\t}\n\n\tpublic async stat(p: string, cred: Cred): Promise<Stats> {\n\t\tthis.checkInitialized();\n\t\ttry {\n\t\t\treturn this._writable.stat(p, cred);\n\t\t} catch (e) {\n\t\t\tif (this._deletedFiles[p]) {\n\t\t\t\tthrow ApiError.ENOENT(p);\n\t\t\t}\n\t\t\tconst oldStat = Stats.clone(await this._readable.stat(p, cred));\n\t\t\t// Make the oldStat's mode writable. Preserve the topmost part of the\n\t\t\t// mode, which specifies if it is a file or a directory.\n\t\t\toldStat.mode = makeModeWritable(oldStat.mode);\n\t\t\treturn oldStat;\n\t\t}\n\t}\n\n\tpublic statSync(p: string, cred: Cred): Stats {\n\t\tthis.checkInitialized();\n\t\ttry {\n\t\t\treturn this._writable.statSync(p, cred);\n\t\t} catch (e) {\n\t\t\tif (this._deletedFiles[p]) {\n\t\t\t\tthrow ApiError.ENOENT(p);\n\t\t\t}\n\t\t\tconst oldStat = Stats.clone(this._readable.statSync(p, cred));\n\t\t\t// Make the oldStat's mode writable. Preserve the topmost part of the\n\t\t\t// mode, which specifies if it is a file or a directory.\n\t\t\toldStat.mode = makeModeWritable(oldStat.mode);\n\t\t\treturn oldStat;\n\t\t}\n\t}\n\n\tpublic async open(p: string, flag: FileFlag, mode: number, cred: Cred): Promise<File> {\n\t\tthis.checkInitialized();\n\t\tthis.checkPath(p);\n\t\tif (p === deletionLogPath) {\n\t\t\tthrow ApiError.EPERM('Cannot open deletion log.');\n\t\t}\n\t\tif (await this.exists(p, cred)) {\n\t\t\tswitch (flag.pathExistsAction()) {\n\t\t\t\tcase ActionType.TRUNCATE_FILE:\n\t\t\t\t\tawait this.createParentDirectoriesAsync(p, cred);\n\t\t\t\t\treturn this._writable.open(p, flag, mode, cred);\n\t\t\t\tcase ActionType.NOP:\n\t\t\t\t\tif (await this._writable.exists(p, cred)) {\n\t\t\t\t\t\treturn this._writable.open(p, flag, mode, cred);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Create an OverlayFile.\n\t\t\t\t\t\tconst buf = await this._readable.readFile(p, null, getFlag('r'), cred);\n\t\t\t\t\t\tconst stats = Stats.clone(await this._readable.stat(p, cred));\n\t\t\t\t\t\tstats.mode = mode;\n\t\t\t\t\t\treturn new OverlayFile(this, p, flag, stats, buf as Buffer);\n\t\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tthrow ApiError.EEXIST(p);\n\t\t\t}\n\t\t} else {\n\t\t\tswitch (flag.pathNotExistsAction()) {\n\t\t\t\tcase ActionType.CREATE_FILE:\n\t\t\t\t\tawait this.createParentDirectoriesAsync(p, cred);\n\t\t\t\t\treturn this._writable.open(p, flag, mode, cred);\n\t\t\t\tdefault:\n\t\t\t\t\tthrow ApiError.ENOENT(p);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic openSync(p: string, flag: FileFlag, mode: number, cred: Cred): File {\n\t\tthis.checkInitialized();\n\t\tthis.checkPath(p);\n\t\tif (p === deletionLogPath) {\n\t\t\tthrow ApiError.EPERM('Cannot open deletion log.');\n\t\t}\n\t\tif (this.existsSync(p, cred)) {\n\t\t\tswitch (flag.pathExistsAction()) {\n\t\t\t\tcase ActionType.TRUNCATE_FILE:\n\t\t\t\t\tthis.createParentDirectories(p, cred);\n\t\t\t\t\treturn this._writable.openSync(p, flag, mode, cred);\n\t\t\t\tcase ActionType.NOP:\n\t\t\t\t\tif (this._writable.existsSync(p, cred)) {\n\t\t\t\t\t\treturn this._writable.openSync(p, flag, mode, cred);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Create an OverlayFile.\n\t\t\t\t\t\tconst buf = <Buffer>this._readable.readFileSync(p, null, getFlag('r'), cred);\n\t\t\t\t\t\tconst stats = Stats.clone(this._readable.statSync(p, cred));\n\t\t\t\t\t\tstats.mode = mode;\n\t\t\t\t\t\treturn new OverlayFile(this, p, flag, stats, buf);\n\t\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tthrow ApiError.EEXIST(p);\n\t\t\t}\n\t\t} else {\n\t\t\tswitch (flag.pathNotExistsAction()) {\n\t\t\t\tcase ActionType.CREATE_FILE:\n\t\t\t\t\tthis.createParentDirectories(p, cred);\n\t\t\t\t\treturn this._writable.openSync(p, flag, mode, cred);\n\t\t\t\tdefault:\n\t\t\t\t\tthrow ApiError.ENOENT(p);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async unlink(p: string, cred: Cred): Promise<void> {\n\t\tthis.checkInitialized();\n\t\tthis.checkPath(p);\n\t\tif (await this.exists(p, cred)) {\n\t\t\tif (await this._writable.exists(p, cred)) {\n\t\t\t\tawait this._writable.unlink(p, cred);\n\t\t\t}\n\n\t\t\t// if it still exists add to the delete log\n\t\t\tif (await this.exists(p, cred)) {\n\t\t\t\tthis.deletePath(p, cred);\n\t\t\t}\n\t\t} else {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t}\n\n\tpublic unlinkSync(p: string, cred: Cred): void {\n\t\tthis.checkInitialized();\n\t\tthis.checkPath(p);\n\t\tif (this.existsSync(p, cred)) {\n\t\t\tif (this._writable.existsSync(p, cred)) {\n\t\t\t\tthis._writable.unlinkSync(p, cred);\n\t\t\t}\n\n\t\t\t// if it still exists add to the delete log\n\t\t\tif (this.existsSync(p, cred)) {\n\t\t\t\tthis.deletePath(p, cred);\n\t\t\t}\n\t\t} else {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t}\n\n\tpublic async rmdir(p: string, cred: Cred): Promise<void> {\n\t\tthis.checkInitialized();\n\t\tif (await this.exists(p, cred)) {\n\t\t\tif (await this._writable.exists(p, cred)) {\n\t\t\t\tawait this._writable.rmdir(p, cred);\n\t\t\t}\n\t\t\tif (await this.exists(p, cred)) {\n\t\t\t\t// Check if directory is empty.\n\t\t\t\tif ((await this.readdir(p, cred)).length > 0) {\n\t\t\t\t\tthrow ApiError.ENOTEMPTY(p);\n\t\t\t\t} else {\n\t\t\t\t\tthis.deletePath(p, cred);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t}\n\n\tpublic rmdirSync(p: string, cred: Cred): void {\n\t\tthis.checkInitialized();\n\t\tif (this.existsSync(p, cred)) {\n\t\t\tif (this._writable.existsSync(p, cred)) {\n\t\t\t\tthis._writable.rmdirSync(p, cred);\n\t\t\t}\n\t\t\tif (this.existsSync(p, cred)) {\n\t\t\t\t// Check if directory is empty.\n\t\t\t\tif (this.readdirSync(p, cred).length > 0) {\n\t\t\t\t\tthrow ApiError.ENOTEMPTY(p);\n\t\t\t\t} else {\n\t\t\t\t\tthis.deletePath(p, cred);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t}\n\n\tpublic async mkdir(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tthis.checkInitialized();\n\t\tif (await this.exists(p, cred)) {\n\t\t\tthrow ApiError.EEXIST(p);\n\t\t} else {\n\t\t\t// The below will throw should any of the parent directories fail to exist\n\t\t\t// on _writable.\n\t\t\tawait this.createParentDirectoriesAsync(p, cred);\n\t\t\tawait this._writable.mkdir(p, mode, cred);\n\t\t}\n\t}\n\n\tpublic mkdirSync(p: string, mode: number, cred: Cred): void {\n\t\tthis.checkInitialized();\n\t\tif (this.existsSync(p, cred)) {\n\t\t\tthrow ApiError.EEXIST(p);\n\t\t} else {\n\t\t\t// The below will throw should any of the parent directories fail to exist\n\t\t\t// on _writable.\n\t\t\tthis.createParentDirectories(p, cred);\n\t\t\tthis._writable.mkdirSync(p, mode, cred);\n\t\t}\n\t}\n\n\tpublic async readdir(p: string, cred: Cred): Promise<string[]> {\n\t\tthis.checkInitialized();\n\t\tconst dirStats = await this.stat(p, cred);\n\t\tif (!dirStats.isDirectory()) {\n\t\t\tthrow ApiError.ENOTDIR(p);\n\t\t}\n\n\t\t// Readdir in both, check delete log on RO file system's listing, merge, return.\n\t\tlet contents: string[] = [];\n\t\ttry {\n\t\t\tcontents = contents.concat(await this._writable.readdir(p, cred));\n\t\t} catch (e) {\n\t\t\t// NOP.\n\t\t}\n\t\ttry {\n\t\t\tcontents = contents.concat((await this._readable.readdir(p, cred)).filter((fPath: string) => !this._deletedFiles[`${p}/${fPath}`]));\n\t\t} catch (e) {\n\t\t\t// NOP.\n\t\t}\n\t\tconst seenMap: { [name: string]: boolean } = {};\n\t\treturn contents.filter((fileP: string) => {\n\t\t\tconst result = !seenMap[fileP];\n\t\t\tseenMap[fileP] = true;\n\t\t\treturn result;\n\t\t});\n\t}\n\n\tpublic readdirSync(p: string, cred: Cred): string[] {\n\t\tthis.checkInitialized();\n\t\tconst dirStats = this.statSync(p, cred);\n\t\tif (!dirStats.isDirectory()) {\n\t\t\tthrow ApiError.ENOTDIR(p);\n\t\t}\n\n\t\t// Readdir in both, check delete log on RO file system's listing, merge, return.\n\t\tlet contents: string[] = [];\n\t\ttry {\n\t\t\tcontents = contents.concat(this._writable.readdirSync(p, cred));\n\t\t} catch (e) {\n\t\t\t// NOP.\n\t\t}\n\t\ttry {\n\t\t\tcontents = contents.concat(this._readable.readdirSync(p, cred).filter((fPath: string) => !this._deletedFiles[`${p}/${fPath}`]));\n\t\t} catch (e) {\n\t\t\t// NOP.\n\t\t}\n\t\tconst seenMap: { [name: string]: boolean } = {};\n\t\treturn contents.filter((fileP: string) => {\n\t\t\tconst result = !seenMap[fileP];\n\t\t\tseenMap[fileP] = true;\n\t\t\treturn result;\n\t\t});\n\t}\n\n\tpublic async exists(p: string, cred: Cred): Promise<boolean> {\n\t\tthis.checkInitialized();\n\t\treturn (await this._writable.exists(p, cred)) || ((await this._readable.exists(p, cred)) && this._deletedFiles[p] !== true);\n\t}\n\n\tpublic existsSync(p: string, cred: Cred): boolean {\n\t\tthis.checkInitialized();\n\t\treturn this._writable.existsSync(p, cred) || (this._readable.existsSync(p, cred) && this._deletedFiles[p] !== true);\n\t}\n\n\tpublic async chmod(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tthis.checkInitialized();\n\t\tawait this.operateOnWritableAsync(p, cred);\n\t\tawait this._writable.chmod(p, mode, cred);\n\t}\n\n\tpublic chmodSync(p: string, mode: number, cred: Cred): void {\n\t\tthis.checkInitialized();\n\t\tthis.operateOnWritable(p, cred);\n\t\tthis._writable.chmodSync(p, mode, cred);\n\t}\n\n\tpublic async chown(p: string, new_uid: number, new_gid: number, cred: Cred): Promise<void> {\n\t\tthis.checkInitialized();\n\t\tawait this.operateOnWritableAsync(p, cred);\n\t\tawait this._writable.chown(p, new_uid, new_gid, cred);\n\t}\n\n\tpublic chownSync(p: string, new_uid: number, new_gid: number, cred: Cred): void {\n\t\tthis.checkInitialized();\n\t\tthis.operateOnWritable(p, cred);\n\t\tthis._writable.chownSync(p, new_uid, new_gid, cred);\n\t}\n\n\tpublic async utimes(p: string, atime: Date, mtime: Date, cred: Cred): Promise<void> {\n\t\tthis.checkInitialized();\n\t\tawait this.operateOnWritableAsync(p, cred);\n\t\tawait this._writable.utimes(p, atime, mtime, cred);\n\t}\n\n\tpublic utimesSync(p: string, atime: Date, mtime: Date, cred: Cred): void {\n\t\tthis.checkInitialized();\n\t\tthis.operateOnWritable(p, cred);\n\t\tthis._writable.utimesSync(p, atime, mtime, cred);\n\t}\n\n\tprivate deletePath(p: string, cred: Cred): void {\n\t\tthis._deletedFiles[p] = true;\n\t\tthis.updateLog(`d${p}\\n`, cred);\n\t}\n\n\tprivate updateLog(addition: string, cred: Cred) {\n\t\tthis._deleteLog += addition;\n\t\tif (this._deleteLogUpdatePending) {\n\t\t\tthis._deleteLogUpdateNeeded = true;\n\t\t} else {\n\t\t\tthis._deleteLogUpdatePending = true;\n\t\t\tthis._writable\n\t\t\t\t.writeFile(deletionLogPath, this._deleteLog, 'utf8', FileFlag.getFileFlag('w'), 0o644, cred)\n\t\t\t\t.then(() => {\n\t\t\t\t\tif (this._deleteLogUpdateNeeded) {\n\t\t\t\t\t\tthis._deleteLogUpdateNeeded = false;\n\t\t\t\t\t\tthis.updateLog('', cred);\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(e => {\n\t\t\t\t\tthis._deleteLogError = e;\n\t\t\t\t})\n\t\t\t\t.finally(() => {\n\t\t\t\t\tthis._deleteLogUpdatePending = false;\n\t\t\t\t});\n\t\t}\n\t}\n\n\tprivate _reparseDeletionLog(): void {\n\t\tthis._deletedFiles = {};\n\t\tthis._deleteLog.split('\\n').forEach((path: string) => {\n\t\t\t// If the log entry begins w/ 'd', it's a deletion.\n\t\t\tthis._deletedFiles[path.slice(1)] = path.slice(0, 1) === 'd';\n\t\t});\n\t}\n\n\tprivate checkInitialized(): void {\n\t\tif (!this._isInitialized) {\n\t\t\tthrow new ApiError(ErrorCode.EPERM, 'OverlayFS is not initialized. Please initialize OverlayFS using its initialize() method before using it.');\n\t\t} else if (this._deleteLogError !== null) {\n\t\t\tconst e = this._deleteLogError;\n\t\t\tthis._deleteLogError = null;\n\t\t\tthrow e;\n\t\t}\n\t}\n\n\tprivate checkPath(p: string): void {\n\t\tif (p === deletionLogPath) {\n\t\t\tthrow ApiError.EPERM(p);\n\t\t}\n\t}\n\n\t/**\n\t * With the given path, create the needed parent directories on the writable storage\n\t * should they not exist. Use modes from the read-only storage.\n\t */\n\tprivate createParentDirectories(p: string, cred: Cred): void {\n\t\tlet parent = path.dirname(p),\n\t\t\ttoCreate: string[] = [];\n\t\twhile (!this._writable.existsSync(parent, cred)) {\n\t\t\ttoCreate.push(parent);\n\t\t\tparent = path.dirname(parent);\n\t\t}\n\t\ttoCreate = toCreate.reverse();\n\n\t\tfor (const p of toCreate) {\n\t\t\tthis._writable.mkdirSync(p, this.statSync(p, cred).mode, cred);\n\t\t}\n\t}\n\n\tprivate async createParentDirectoriesAsync(p: string, cred: Cred): Promise<void> {\n\t\tlet parent = path.dirname(p),\n\t\t\ttoCreate: string[] = [];\n\t\twhile (!(await this._writable.exists(parent, cred))) {\n\t\t\ttoCreate.push(parent);\n\t\t\tparent = path.dirname(parent);\n\t\t}\n\t\ttoCreate = toCreate.reverse();\n\n\t\tfor (const p of toCreate) {\n\t\t\tconst stats = await this.stat(p, cred);\n\t\t\tawait this._writable.mkdir(p, stats.mode, cred);\n\t\t}\n\t}\n\n\t/**\n\t * Helper function:\n\t * - Ensures p is on writable before proceeding. Throws an error if it doesn't exist.\n\t * - Calls f to perform operation on writable.\n\t */\n\tprivate operateOnWritable(p: string, cred: Cred): void {\n\t\tif (!this.existsSync(p, cred)) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t\tif (!this._writable.existsSync(p, cred)) {\n\t\t\t// File is on readable storage. Copy to writable storage before\n\t\t\t// changing its mode.\n\t\t\tthis.copyToWritable(p, cred);\n\t\t}\n\t}\n\n\tprivate async operateOnWritableAsync(p: string, cred: Cred): Promise<void> {\n\t\tif (!(await this.exists(p, cred))) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\n\t\tif (!(await this._writable.exists(p, cred))) {\n\t\t\treturn this.copyToWritableAsync(p, cred);\n\t\t}\n\t}\n\n\t/**\n\t * Copy from readable to writable storage.\n\t * PRECONDITION: File does not exist on writable storage.\n\t */\n\tprivate copyToWritable(p: string, cred: Cred): void {\n\t\tconst pStats = this.statSync(p, cred);\n\t\tif (pStats.isDirectory()) {\n\t\t\tthis._writable.mkdirSync(p, pStats.mode, cred);\n\t\t} else {\n\t\t\tthis.writeFileSync(p, this._readable.readFileSync(p, null, getFlag('r'), cred), null, getFlag('w'), pStats.mode, cred);\n\t\t}\n\t}\n\n\tprivate async copyToWritableAsync(p: string, cred: Cred): Promise<void> {\n\t\tconst pStats = await this.stat(p, cred);\n\t\tif (pStats.isDirectory()) {\n\t\t\tawait this._writable.mkdir(p, pStats.mode, cred);\n\t\t} else {\n\t\t\tawait this.writeFile(p, await this._readable.readFile(p, null, getFlag('r'), cred), null, getFlag('w'), pStats.mode, cred);\n\t\t}\n\t}\n}\n\n/**\n * OverlayFS makes a read-only filesystem writable by storing writes on a second,\n * writable file system. Deletes are persisted via metadata stored on the writable\n * file system.\n */\nexport class OverlayFS extends LockedFS<UnlockedOverlayFS> {\n\tpublic static readonly Name = 'OverlayFS';\n\n\tpublic static Create = CreateBackend.bind(this);\n\n\tpublic static readonly Options: BackendOptions = {\n\t\twritable: {\n\t\t\ttype: 'object',\n\t\t\tdescription: 'The file system to write modified files to.',\n\t\t},\n\t\treadable: {\n\t\t\ttype: 'object',\n\t\t\tdescription: 'The file system that initially populates this file system.',\n\t\t},\n\t};\n\n\tpublic static isAvailable(): boolean {\n\t\treturn UnlockedOverlayFS.isAvailable();\n\t}\n\n\t/**\n\t * @param options The options to initialize the OverlayFS with\n\t */\n\tconstructor(options: OverlayFS.Options) {\n\t\tsuper(new UnlockedOverlayFS(options));\n\t\tthis._ready = this._initialize();\n\t}\n\n\tpublic getOverlayedFileSystems(): OverlayFS.Options {\n\t\treturn super.fs.getOverlayedFileSystems();\n\t}\n\n\tpublic getDeletionLog(): string {\n\t\treturn super.fs.getDeletionLog();\n\t}\n\n\tpublic resDeletionLog(): string {\n\t\treturn super.fs.getDeletionLog();\n\t}\n\n\tpublic unwrap(): UnlockedOverlayFS {\n\t\treturn super.fs;\n\t}\n\n\tprivate async _initialize(): Promise<this> {\n\t\tawait super.fs._initialize();\n\t\treturn this;\n\t}\n}\n", "import { AsyncMirror } from './AsyncMirror';\nimport { FolderAdapter } from './FolderAdapter';\nimport { InMemoryFileSystem as InMemory } from './InMemory';\nimport { OverlayFS } from './OverlayFS';\nimport { BackendConstructor } from './backend';\n\nexport const backends: { [backend: string]: BackendConstructor } = {};\nexport default backends;\nexport { AsyncMirror, FolderAdapter, InMemory, OverlayFS };\n\nexport function registerBackend(..._backends: BackendConstructor[]) {\n\tfor (const backend of _backends) {\n\t\tbackends[backend.Name] = backend;\n\t}\n}\n\nregisterBackend(AsyncMirror, FolderAdapter, InMemory, OverlayFS);\n", "import * as path from 'path';\nimport { ApiError, ErrorCode } from '../ApiError';\nimport { Cred } from '../cred';\nimport { W_OK, R_OK } from '../emulation/constants';\nimport { PreloadFile, File, FileFlag } from '../file';\nimport { BaseFileSystem } from '../filesystem';\nimport Inode from '../inode';\nimport { Stats, FileType } from '../stats';\nimport { ROOT_NODE_ID, randomUUID, getEmptyDirNode } from '../utils';\n\nclass LRUNode {\n\tpublic prev: LRUNode | null = null;\n\tpublic next: LRUNode | null = null;\n\tconstructor(public key: string, public value: string) {}\n}\n\n// Adapted from https://chrisrng.svbtle.com/lru-cache-in-javascript\nclass LRUCache {\n\tprivate size = 0;\n\tprivate map: { [id: string]: LRUNode } = {};\n\tprivate head: LRUNode | null = null;\n\tprivate tail: LRUNode | null = null;\n\tconstructor(public readonly limit: number) {}\n\n\t/**\n\t * Change or add a new value in the cache\n\t * We overwrite the entry if it already exists\n\t */\n\tpublic set(key: string, value: string): void {\n\t\tconst node = new LRUNode(key, value);\n\t\tif (this.map[key]) {\n\t\t\tthis.map[key].value = node.value;\n\t\t\tthis.remove(node.key);\n\t\t} else {\n\t\t\tif (this.size >= this.limit) {\n\t\t\t\tdelete this.map[this.tail!.key];\n\t\t\t\tthis.size--;\n\t\t\t\tthis.tail = this.tail!.prev;\n\t\t\t\tthis.tail!.next = null;\n\t\t\t}\n\t\t}\n\t\tthis.setHead(node);\n\t}\n\n\t/* Retrieve a single entry from the cache */\n\tpublic get(key: string): string | null {\n\t\tif (this.map[key]) {\n\t\t\tconst value = this.map[key].value;\n\t\t\tconst node = new LRUNode(key, value);\n\t\t\tthis.remove(key);\n\t\t\tthis.setHead(node);\n\t\t\treturn value;\n\t\t} else {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/* Remove a single entry from the cache */\n\tpublic remove(key: string): void {\n\t\tconst node = this.map[key];\n\t\tif (!node) {\n\t\t\treturn;\n\t\t}\n\t\tif (node.prev !== null) {\n\t\t\tnode.prev.next = node.next;\n\t\t} else {\n\t\t\tthis.head = node.next;\n\t\t}\n\t\tif (node.next !== null) {\n\t\t\tnode.next.prev = node.prev;\n\t\t} else {\n\t\t\tthis.tail = node.prev;\n\t\t}\n\t\tdelete this.map[key];\n\t\tthis.size--;\n\t}\n\n\t/* Resets the entire cache - Argument limit is optional to be reset */\n\tpublic removeAll() {\n\t\tthis.size = 0;\n\t\tthis.map = {};\n\t\tthis.head = null;\n\t\tthis.tail = null;\n\t}\n\n\tprivate setHead(node: LRUNode): void {\n\t\tnode.next = this.head;\n\t\tnode.prev = null;\n\t\tif (this.head !== null) {\n\t\t\tthis.head.prev = node;\n\t\t}\n\t\tthis.head = node;\n\t\tif (this.tail === null) {\n\t\t\tthis.tail = node;\n\t\t}\n\t\tthis.size++;\n\t\tthis.map[node.key] = node;\n\t}\n}\n\n/**\n * Represents an *asynchronous* key-value store.\n */\nexport interface AsyncKeyValueStore {\n\t/**\n\t * The name of the key-value store.\n\t */\n\tname(): string;\n\t/**\n\t * Empties the key-value store completely.\n\t */\n\tclear(): Promise<void>;\n\t/**\n\t * Begins a read-write transaction.\n\t */\n\tbeginTransaction(type: 'readwrite'): AsyncKeyValueRWTransaction;\n\t/**\n\t * Begins a read-only transaction.\n\t */\n\tbeginTransaction(type: 'readonly'): AsyncKeyValueROTransaction;\n\tbeginTransaction(type: string): AsyncKeyValueROTransaction;\n}\n\n/**\n * Represents an asynchronous read-only transaction.\n */\nexport interface AsyncKeyValueROTransaction {\n\t/**\n\t * Retrieves the data at the given key.\n\t * @param key The key to look under for data.\n\t */\n\tget(key: string): Promise<Buffer>;\n}\n\n/**\n * Represents an asynchronous read-write transaction.\n */\nexport interface AsyncKeyValueRWTransaction extends AsyncKeyValueROTransaction {\n\t/**\n\t * Adds the data to the store under the given key. Overwrites any existing\n\t * data.\n\t * @param key The key to add the data under.\n\t * @param data The data to add to the store.\n\t * @param overwrite If 'true', overwrite any existing data. If 'false',\n\t * avoids writing the data if the key exists.\n\t */\n\tput(key: string, data: Buffer, overwrite: boolean): Promise<boolean>;\n\t/**\n\t * Deletes the data at the given key.\n\t * @param key The key to delete from the store.\n\t */\n\tdel(key: string): Promise<void>;\n\t/**\n\t * Commits the transaction.\n\t */\n\tcommit(): Promise<void>;\n\t/**\n\t * Aborts and rolls back the transaction.\n\t */\n\tabort(): Promise<void>;\n}\n\nexport class AsyncKeyValueFile extends PreloadFile<AsyncKeyValueFileSystem> implements File {\n\tconstructor(_fs: AsyncKeyValueFileSystem, _path: string, _flag: FileFlag, _stat: Stats, contents?: Buffer) {\n\t\tsuper(_fs, _path, _flag, _stat, contents);\n\t}\n\n\tpublic async sync(): Promise<void> {\n\t\tif (!this.isDirty()) {\n\t\t\treturn;\n\t\t}\n\n\t\tawait this._fs._sync(this.getPath(), this.getBuffer(), this.getStats());\n\n\t\tthis.resetDirty();\n\t}\n\n\tpublic async close(): Promise<void> {\n\t\tthis.sync();\n\t}\n}\n\n/**\n * An \"Asynchronous key-value file system\". Stores data to/retrieves data from\n * an underlying asynchronous key-value store.\n */\nexport class AsyncKeyValueFileSystem extends BaseFileSystem {\n\tpublic static isAvailable(): boolean {\n\t\treturn true;\n\t}\n\n\tprotected store: AsyncKeyValueStore;\n\tprivate _cache: LRUCache | null = null;\n\n\tconstructor(cacheSize: number) {\n\t\tsuper();\n\t\tif (cacheSize > 0) {\n\t\t\tthis._cache = new LRUCache(cacheSize);\n\t\t}\n\t}\n\n\t/**\n\t * Initializes the file system. Typically called by subclasses' async\n\t * constructors.\n\t */\n\tpublic async init(store: AsyncKeyValueStore) {\n\t\tthis.store = store;\n\t\t// INVARIANT: Ensure that the root exists.\n\t\tawait this.makeRootDirectory();\n\t}\n\tpublic getName(): string {\n\t\treturn this.store.name();\n\t}\n\tpublic isReadOnly(): boolean {\n\t\treturn false;\n\t}\n\tpublic supportsSymlinks(): boolean {\n\t\treturn false;\n\t}\n\tpublic supportsProps(): boolean {\n\t\treturn true;\n\t}\n\tpublic supportsSynch(): boolean {\n\t\treturn false;\n\t}\n\n\t/**\n\t * Delete all contents stored in the file system.\n\t */\n\tpublic async empty(): Promise<void> {\n\t\tif (this._cache) {\n\t\t\tthis._cache.removeAll();\n\t\t}\n\t\tawait this.store.clear();\n\t\t// INVARIANT: Root always exists.\n\t\tawait this.makeRootDirectory();\n\t}\n\n\tpublic async access(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tconst tx = this.store.beginTransaction('readonly');\n\t\tconst inode = await this.findINode(tx, p);\n\t\tif (!inode) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t\tif (!inode.toStats().hasAccess(mode, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\t}\n\n\t/**\n\t * @todo Make rename compatible with the cache.\n\t */\n\tpublic async rename(oldPath: string, newPath: string, cred: Cred): Promise<void> {\n\t\tconst c = this._cache;\n\t\tif (this._cache) {\n\t\t\t// Clear and disable cache during renaming process.\n\t\t\tthis._cache = null;\n\t\t\tc.removeAll();\n\t\t}\n\n\t\ttry {\n\t\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\t\toldParent = path.dirname(oldPath),\n\t\t\t\toldName = path.basename(oldPath),\n\t\t\t\tnewParent = path.dirname(newPath),\n\t\t\t\tnewName = path.basename(newPath),\n\t\t\t\t// Remove oldPath from parent's directory listing.\n\t\t\t\toldDirNode = await this.findINode(tx, oldParent),\n\t\t\t\toldDirList = await this.getDirListing(tx, oldParent, oldDirNode);\n\n\t\t\tif (!oldDirNode.toStats().hasAccess(W_OK, cred)) {\n\t\t\t\tthrow ApiError.EACCES(oldPath);\n\t\t\t}\n\n\t\t\tif (!oldDirList[oldName]) {\n\t\t\t\tthrow ApiError.ENOENT(oldPath);\n\t\t\t}\n\t\t\tconst nodeId: string = oldDirList[oldName];\n\t\t\tdelete oldDirList[oldName];\n\n\t\t\t// Invariant: Can't move a folder inside itself.\n\t\t\t// This funny little hack ensures that the check passes only if oldPath\n\t\t\t// is a subpath of newParent. We append '/' to avoid matching folders that\n\t\t\t// are a substring of the bottom-most folder in the path.\n\t\t\tif ((newParent + '/').indexOf(oldPath + '/') === 0) {\n\t\t\t\tthrow new ApiError(ErrorCode.EBUSY, oldParent);\n\t\t\t}\n\n\t\t\t// Add newPath to parent's directory listing.\n\t\t\tlet newDirNode: Inode, newDirList: typeof oldDirList;\n\t\t\tif (newParent === oldParent) {\n\t\t\t\t// Prevent us from re-grabbing the same directory listing, which still\n\t\t\t\t// contains oldName.\n\t\t\t\tnewDirNode = oldDirNode;\n\t\t\t\tnewDirList = oldDirList;\n\t\t\t} else {\n\t\t\t\tnewDirNode = await this.findINode(tx, newParent);\n\t\t\t\tnewDirList = await this.getDirListing(tx, newParent, newDirNode);\n\t\t\t}\n\n\t\t\tif (newDirList[newName]) {\n\t\t\t\t// If it's a file, delete it.\n\t\t\t\tconst newNameNode = await this.getINode(tx, newPath, newDirList[newName]);\n\t\t\t\tif (newNameNode.isFile()) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait tx.del(newNameNode.id);\n\t\t\t\t\t\tawait tx.del(newDirList[newName]);\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tawait tx.abort();\n\t\t\t\t\t\tthrow e;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// If it's a directory, throw a permissions error.\n\t\t\t\t\tthrow ApiError.EPERM(newPath);\n\t\t\t\t}\n\t\t\t}\n\t\t\tnewDirList[newName] = nodeId;\n\n\t\t\t// Commit the two changed directory listings.\n\t\t\ttry {\n\t\t\t\tawait tx.put(oldDirNode.id, Buffer.from(JSON.stringify(oldDirList)), true);\n\t\t\t\tawait tx.put(newDirNode.id, Buffer.from(JSON.stringify(newDirList)), true);\n\t\t\t} catch (e) {\n\t\t\t\tawait tx.abort();\n\t\t\t\tthrow e;\n\t\t\t}\n\n\t\t\tawait tx.commit();\n\t\t} finally {\n\t\t\tif (c) {\n\t\t\t\tthis._cache = c;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async stat(p: string, cred: Cred): Promise<Stats> {\n\t\tconst tx = this.store.beginTransaction('readonly');\n\t\tconst inode = await this.findINode(tx, p);\n\t\tconst stats = inode!.toStats();\n\t\tif (!stats.hasAccess(R_OK, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\t\treturn stats;\n\t}\n\n\tpublic async createFile(p: string, flag: FileFlag, mode: number, cred: Cred): Promise<File> {\n\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\tdata = Buffer.alloc(0),\n\t\t\tnewFile = await this.commitNewFile(tx, p, FileType.FILE, mode, cred, data);\n\t\t// Open the file.\n\t\treturn new AsyncKeyValueFile(this, p, flag, newFile.toStats(), data);\n\t}\n\n\tpublic async openFile(p: string, flag: FileFlag, cred: Cred): Promise<File> {\n\t\tconst tx = this.store.beginTransaction('readonly'),\n\t\t\tnode = await this.findINode(tx, p),\n\t\t\tdata = await tx.get(node.id);\n\t\tif (!node.toStats().hasAccess(flag.getMode(), cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\t\tif (data === undefined) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t\treturn new AsyncKeyValueFile(this, p, flag, node.toStats(), data);\n\t}\n\n\tpublic async unlink(p: string, cred: Cred): Promise<void> {\n\t\treturn this.removeEntry(p, false, cred);\n\t}\n\n\tpublic async rmdir(p: string, cred: Cred): Promise<void> {\n\t\t// Check first if directory is empty.\n\t\tconst list = await this.readdir(p, cred);\n\t\tif (list.length > 0) {\n\t\t\tthrow ApiError.ENOTEMPTY(p);\n\t\t}\n\t\tawait this.removeEntry(p, true, cred);\n\t}\n\n\tpublic async mkdir(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\tdata = Buffer.from('{}');\n\t\tawait this.commitNewFile(tx, p, FileType.DIRECTORY, mode, cred, data);\n\t}\n\n\tpublic async readdir(p: string, cred: Cred): Promise<string[]> {\n\t\tconst tx = this.store.beginTransaction('readonly');\n\t\tconst node = await this.findINode(tx, p);\n\t\tif (!node.toStats().hasAccess(R_OK, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\t\treturn Object.keys(await this.getDirListing(tx, p, node));\n\t}\n\n\tpublic async chmod(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tconst fd = await this.openFile(p, FileFlag.getFileFlag('r+'), cred);\n\t\tawait fd.chmod(mode);\n\t}\n\n\tpublic async chown(p: string, new_uid: number, new_gid: number, cred: Cred): Promise<void> {\n\t\tconst fd = await this.openFile(p, FileFlag.getFileFlag('r+'), cred);\n\t\tawait fd.chown(new_uid, new_gid);\n\t}\n\n\tpublic async _sync(p: string, data: Buffer, stats: Stats): Promise<void> {\n\t\t// @todo Ensure mtime updates properly, and use that to determine if a data\n\t\t// update is required.\n\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\t// We use the _findInode helper because we actually need the INode id.\n\t\t\tfileInodeId = await this._findINode(tx, path.dirname(p), path.basename(p)),\n\t\t\tfileInode = await this.getINode(tx, p, fileInodeId),\n\t\t\tinodeChanged = fileInode.update(stats);\n\n\t\ttry {\n\t\t\t// Sync data.\n\t\t\tawait tx.put(fileInode.id, data, true);\n\t\t\t// Sync metadata.\n\t\t\tif (inodeChanged) {\n\t\t\t\tawait tx.put(fileInodeId, fileInode.toBuffer(), true);\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tawait tx.abort();\n\t\t\tthrow e;\n\t\t}\n\t\tawait tx.commit();\n\t}\n\n\t/**\n\t * Checks if the root directory exists. Creates it if it doesn't.\n\t */\n\tprivate async makeRootDirectory(): Promise<void> {\n\t\tconst tx = this.store.beginTransaction('readwrite');\n\t\tif ((await tx.get(ROOT_NODE_ID)) === undefined) {\n\t\t\t// Create new inode.\n\t\t\tconst currTime = new Date().getTime(),\n\t\t\t\t// Mode 0666, owned by root:root\n\t\t\t\tdirInode = new Inode(randomUUID(), 4096, 511 | FileType.DIRECTORY, currTime, currTime, currTime, 0, 0);\n\t\t\t// If the root doesn't exist, the first random ID shouldn't exist,\n\t\t\t// either.\n\t\t\tawait tx.put(dirInode.id, getEmptyDirNode(), false);\n\t\t\tawait tx.put(ROOT_NODE_ID, dirInode.toBuffer(), false);\n\t\t\tawait tx.commit();\n\t\t}\n\t}\n\n\t/**\n\t * Helper function for findINode.\n\t * @param parent The parent directory of the file we are attempting to find.\n\t * @param filename The filename of the inode we are attempting to find, minus\n\t * the parent.\n\t */\n\tprivate async _findINode(tx: AsyncKeyValueROTransaction, parent: string, filename: string, visited: Set<string> = new Set<string>()): Promise<string> {\n\t\tconst currentPath = path.posix.join(parent, filename);\n\t\tif (visited.has(currentPath)) {\n\t\t\tthrow new ApiError(ErrorCode.EIO, 'Infinite loop detected while finding inode', currentPath);\n\t\t}\n\n\t\tvisited.add(currentPath);\n\t\tif (this._cache) {\n\t\t\tconst id = this._cache.get(currentPath);\n\t\t\tif (id) {\n\t\t\t\treturn id;\n\t\t\t}\n\t\t}\n\n\t\tif (parent === '/') {\n\t\t\tif (filename === '') {\n\t\t\t\t// BASE CASE #1: Return the root's ID.\n\t\t\t\tif (this._cache) {\n\t\t\t\t\tthis._cache.set(currentPath, ROOT_NODE_ID);\n\t\t\t\t}\n\t\t\t\treturn ROOT_NODE_ID;\n\t\t\t} else {\n\t\t\t\t// BASE CASE #2: Find the item in the root node.\n\t\t\t\tconst inode = await this.getINode(tx, parent, ROOT_NODE_ID);\n\t\t\t\tconst dirList = await this.getDirListing(tx, parent, inode!);\n\t\t\t\tif (dirList![filename]) {\n\t\t\t\t\tconst id = dirList![filename];\n\t\t\t\t\tif (this._cache) {\n\t\t\t\t\t\tthis._cache.set(currentPath, id);\n\t\t\t\t\t}\n\t\t\t\t\treturn id;\n\t\t\t\t} else {\n\t\t\t\t\tthrow ApiError.ENOENT(path.resolve(parent, filename));\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Get the parent directory's INode, and find the file in its directory\n\t\t\t// listing.\n\t\t\tconst inode = await this.findINode(tx, parent, visited);\n\t\t\tconst dirList = await this.getDirListing(tx, parent, inode!);\n\t\t\tif (dirList![filename]) {\n\t\t\t\tconst id = dirList![filename];\n\t\t\t\tif (this._cache) {\n\t\t\t\t\tthis._cache.set(currentPath, id);\n\t\t\t\t}\n\t\t\t\treturn id;\n\t\t\t} else {\n\t\t\t\tthrow ApiError.ENOENT(path.resolve(parent, filename));\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Finds the Inode of the given path.\n\t * @param p The path to look up.\n\t * @todo memoize/cache\n\t */\n\tprivate async findINode(tx: AsyncKeyValueROTransaction, p: string, visited: Set<string> = new Set<string>()): Promise<Inode> {\n\t\tconst id = await this._findINode(tx, path.dirname(p), path.basename(p), visited);\n\t\treturn this.getINode(tx, p, id!);\n\t}\n\n\t/**\n\t * Given the ID of a node, retrieves the corresponding Inode.\n\t * @param tx The transaction to use.\n\t * @param p The corresponding path to the file (used for error messages).\n\t * @param id The ID to look up.\n\t */\n\tprivate async getINode(tx: AsyncKeyValueROTransaction, p: string, id: string): Promise<Inode> {\n\t\tconst data = await tx.get(id);\n\t\tif (!data) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t\treturn Inode.fromBuffer(data);\n\t}\n\n\t/**\n\t * Given the Inode of a directory, retrieves the corresponding directory\n\t * listing.\n\t */\n\tprivate async getDirListing(tx: AsyncKeyValueROTransaction, p: string, inode: Inode): Promise<{ [fileName: string]: string }> {\n\t\tif (!inode.isDirectory()) {\n\t\t\tthrow ApiError.ENOTDIR(p);\n\t\t}\n\t\tconst data = await tx.get(inode.id);\n\t\ttry {\n\t\t\treturn JSON.parse(data!.toString());\n\t\t} catch (e) {\n\t\t\t// Occurs when data is undefined, or corresponds to something other\n\t\t\t// than a directory listing. The latter should never occur unless\n\t\t\t// the file system is corrupted.\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t}\n\n\t/**\n\t * Adds a new node under a random ID. Retries 5 times before giving up in\n\t * the exceedingly unlikely chance that we try to reuse a random GUID.\n\t */\n\tprivate async addNewNode(tx: AsyncKeyValueRWTransaction, data: Buffer): Promise<string> {\n\t\tlet retries = 0;\n\t\tconst reroll = async () => {\n\t\t\tif (++retries === 5) {\n\t\t\t\t// Max retries hit. Return with an error.\n\t\t\t\tthrow new ApiError(ErrorCode.EIO, 'Unable to commit data to key-value store.');\n\t\t\t} else {\n\t\t\t\t// Try again.\n\t\t\t\tconst currId = randomUUID();\n\t\t\t\tconst committed = await tx.put(currId, data, false);\n\t\t\t\tif (!committed) {\n\t\t\t\t\treturn reroll();\n\t\t\t\t} else {\n\t\t\t\t\treturn currId;\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\treturn reroll();\n\t}\n\n\t/**\n\t * Commits a new file (well, a FILE or a DIRECTORY) to the file system with\n\t * the given mode.\n\t * Note: This will commit the transaction.\n\t * @param p The path to the new file.\n\t * @param type The type of the new file.\n\t * @param mode The mode to create the new file with.\n\t * @param cred The UID/GID to create the file with\n\t * @param data The data to store at the file's data node.\n\t */\n\tprivate async commitNewFile(tx: AsyncKeyValueRWTransaction, p: string, type: FileType, mode: number, cred: Cred, data: Buffer): Promise<Inode> {\n\t\tconst parentDir = path.dirname(p),\n\t\t\tfname = path.basename(p),\n\t\t\tparentNode = await this.findINode(tx, parentDir),\n\t\t\tdirListing = await this.getDirListing(tx, parentDir, parentNode),\n\t\t\tcurrTime = new Date().getTime();\n\n\t\t//Check that the creater has correct access\n\t\tif (!parentNode.toStats().hasAccess(W_OK, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\n\t\t// Invariant: The root always exists.\n\t\t// If we don't check this prior to taking steps below, we will create a\n\t\t// file with name '' in root should p == '/'.\n\t\tif (p === '/') {\n\t\t\tthrow ApiError.EEXIST(p);\n\t\t}\n\n\t\t// Check if file already exists.\n\t\tif (dirListing[fname]) {\n\t\t\tawait tx.abort();\n\t\t\tthrow ApiError.EEXIST(p);\n\t\t}\n\t\ttry {\n\t\t\t// Commit data.\n\t\t\tconst dataId = await this.addNewNode(tx, data);\n\t\t\tconst fileNode = new Inode(dataId, data.length, mode | type, currTime, currTime, currTime, cred.uid, cred.gid);\n\t\t\t// Commit file node.\n\t\t\tconst fileNodeId = await this.addNewNode(tx, fileNode.toBuffer());\n\t\t\t// Update and commit parent directory listing.\n\t\t\tdirListing[fname] = fileNodeId;\n\t\t\tawait tx.put(parentNode.id, Buffer.from(JSON.stringify(dirListing)), true);\n\t\t\tawait tx.commit();\n\t\t\treturn fileNode;\n\t\t} catch (e) {\n\t\t\ttx.abort();\n\t\t\tthrow e;\n\t\t}\n\t}\n\n\t/**\n\t * Remove all traces of the given path from the file system.\n\t * @param p The path to remove from the file system.\n\t * @param isDir Does the path belong to a directory, or a file?\n\t * @todo Update mtime.\n\t */\n\t/**\n\t * Remove all traces of the given path from the file system.\n\t * @param p The path to remove from the file system.\n\t * @param isDir Does the path belong to a directory, or a file?\n\t * @todo Update mtime.\n\t */\n\tprivate async removeEntry(p: string, isDir: boolean, cred: Cred): Promise<void> {\n\t\tif (this._cache) {\n\t\t\tthis._cache.remove(p);\n\t\t}\n\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\tparent: string = path.dirname(p),\n\t\t\tparentNode = await this.findINode(tx, parent),\n\t\t\tparentListing = await this.getDirListing(tx, parent, parentNode),\n\t\t\tfileName: string = path.basename(p);\n\n\t\tif (!parentListing[fileName]) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\n\t\tconst fileNodeId = parentListing[fileName];\n\n\t\t// Get file inode.\n\t\tconst fileNode = await this.getINode(tx, p, fileNodeId);\n\n\t\tif (!fileNode.toStats().hasAccess(W_OK, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\n\t\t// Remove from directory listing of parent.\n\t\tdelete parentListing[fileName];\n\n\t\tif (!isDir && fileNode.isDirectory()) {\n\t\t\tthrow ApiError.EISDIR(p);\n\t\t} else if (isDir && !fileNode.isDirectory()) {\n\t\t\tthrow ApiError.ENOTDIR(p);\n\t\t}\n\n\t\ttry {\n\t\t\t// Delete data.\n\t\t\tawait tx.del(fileNode.id);\n\t\t\t// Delete node.\n\t\t\tawait tx.del(fileNodeId);\n\t\t\t// Update directory listing.\n\t\t\tawait tx.put(parentNode.id, Buffer.from(JSON.stringify(parentListing)), true);\n\t\t} catch (e) {\n\t\t\tawait tx.abort();\n\t\t\tthrow e;\n\t\t}\n\t\t// Success.\n\t\tawait tx.commit();\n\t}\n}\n"],
4
+ "sourcesContent": ["/**\n * ZenFS's main module. This is exposed in the browser via the ZenFS global.\n */\n\nimport fs from './emulation/fs.js';\nimport { FileSystem, type BFSOneArgCallback, type BFSCallback } from './filesystem.js';\nimport { backends } from './backends/index.js';\nimport { ErrorCode, ApiError } from './ApiError.js';\nimport { Cred } from './cred.js';\nimport * as process from 'process';\nimport type { BackendConstructor } from './backends/backend.js';\nimport { type MountMapping, setCred } from './emulation/shared.js';\n\nif (process && (<any>process)['initializeTTYs']) {\n\t(<any>process)['initializeTTYs']();\n}\n\n/**\n * Initializes ZenFS with the given file systems.\n */\nexport function initialize(mounts: { [point: string]: FileSystem }, uid: number = 0, gid: number = 0) {\n\tsetCred(new Cred(uid, gid, uid, gid, uid, gid));\n\treturn fs.initialize(mounts);\n}\n\n/**\n * Defines a mapping of mount points to their configurations\n */\nexport interface ConfigMapping {\n\t[mountPoint: string]: FileSystem | FileSystemConfiguration | keyof typeof backends;\n}\n\n/**\n * A configuration for ZenFS\n */\nexport type Configuration = FileSystem | FileSystemConfiguration | ConfigMapping;\n\nasync function _configure(config: Configuration): Promise<void> {\n\tif ('fs' in config || config instanceof FileSystem) {\n\t\t// single FS\n\t\tconfig = { '/': config } as ConfigMapping;\n\t}\n\tfor (let [point, value] of Object.entries(config)) {\n\t\tif (typeof value == 'number') {\n\t\t\t//should never happen\n\t\t\tcontinue;\n\t\t}\n\t\tpoint = point.toString(); // so linting stops complaining that point should be declared with const, which can't be done since value is assigned to\n\n\t\tif (value instanceof FileSystem) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (typeof value == 'string') {\n\t\t\tvalue = { fs: value };\n\t\t}\n\n\t\tconfig[point] = await getFileSystem(value);\n\t}\n\treturn initialize(config as MountMapping);\n}\n\n/**\n * Creates a file system with the given configuration, and initializes ZenFS with it.\n * See the FileSystemConfiguration type for more info on the configuration object.\n */\nexport function configure(config: Configuration): Promise<void>;\nexport function configure(config: Configuration, cb: BFSOneArgCallback): void;\nexport function configure(config: Configuration, cb?: BFSOneArgCallback): Promise<void> | void {\n\t// Promise version\n\tif (typeof cb != 'function') {\n\t\treturn _configure(config);\n\t}\n\n\t// Callback version\n\t_configure(config)\n\t\t.then(() => cb())\n\t\t.catch(err => cb(err));\n\treturn;\n}\n\n/**\n * Asynchronously creates a file system with the given configuration, and initializes ZenFS with it.\n * See the FileSystemConfiguration type for more info on the configuration object.\n * Note: unlike configure, the .then is provided with the file system\n */\n\n/**\n * Specifies a file system backend type and its options.\n *\n * Individual options can recursively contain FileSystemConfiguration objects for\n * option values that require file systems.\n *\n * For example, to mirror Dropbox to Storage with AsyncMirror, use the following\n * object:\n *\n * ```javascript\n * var config = {\n * fs: \"AsyncMirror\",\n * options: {\n * sync: {fs: \"Storage\"},\n * async: {fs: \"Dropbox\", options: {client: anAuthenticatedDropboxSDKClient }}\n * }\n * };\n * ```\n *\n * The option object for each file system corresponds to that file system's option object passed to its `Create()` method.\n */\nexport interface FileSystemConfiguration {\n\tfs: string;\n\toptions?: object;\n}\n\nasync function _getFileSystem({ fs: fsName, options = {} }: FileSystemConfiguration): Promise<FileSystem> {\n\tif (!fsName) {\n\t\tthrow new ApiError(ErrorCode.EPERM, 'Missing \"fs\" property on configuration object.');\n\t}\n\n\tif (typeof options !== 'object' || options === null) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Invalid \"options\" property on configuration object.');\n\t}\n\n\tconst props = Object.keys(options).filter(k => k != 'fs');\n\n\tfor (const prop of props) {\n\t\tconst opt = options[prop];\n\t\tif (opt === null || typeof opt !== 'object' || !('fs' in opt)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst fs = await _getFileSystem(opt);\n\t\toptions[prop] = fs;\n\t}\n\n\tconst fsc = <BackendConstructor | undefined>(<any>backends)[fsName];\n\tif (!fsc) {\n\t\tthrow new ApiError(ErrorCode.EPERM, `File system ${fsName} is not available in ZenFS.`);\n\t} else {\n\t\treturn fsc.Create(options);\n\t}\n}\n\n/**\n * Retrieve a file system with the given configuration. Will return a promise if invoked without a callback\n * @param config A FileSystemConfiguration object. See FileSystemConfiguration for details.\n * @param cb Called when the file system is constructed, or when an error occurs.\n */\nexport function getFileSystem(config: FileSystemConfiguration): Promise<FileSystem>;\nexport function getFileSystem(config: FileSystemConfiguration, cb: BFSCallback<FileSystem>): void;\nexport function getFileSystem(config: FileSystemConfiguration, cb?: BFSCallback<FileSystem>): Promise<FileSystem> | void {\n\t// Promise version\n\tif (typeof cb != 'function') {\n\t\treturn _getFileSystem(config);\n\t}\n\n\t// Callback version\n\t_getFileSystem(config)\n\t\t.then(fs => cb(null, fs))\n\t\t.catch(err => cb(err));\n\treturn;\n}\n\nexport * from './backends/index.js';\nexport * from './backends/AsyncStore.js';\nexport * from './backends/SyncStore.js';\nexport * from './ApiError.js';\nexport * from './cred.js';\nexport * from './file.js';\nexport * from './filesystem.js';\nexport * from './inode.js';\nexport * from './mutex.js';\nexport * from './stats.js';\nexport * from './utils.js';\nexport { fs };\nexport default fs;\n", "function unimplemented(name) {\r\n throw new Error('Node.js process ' + name + ' is not supported by JSPM core outside of Node.js');\r\n}\r\n\r\nvar queue = [];\r\nvar draining = false;\r\nvar currentQueue;\r\nvar queueIndex = -1;\r\n\r\nfunction cleanUpNextTick() {\r\n if (!draining || !currentQueue)\r\n return;\r\n draining = false;\r\n if (currentQueue.length) {\r\n queue = currentQueue.concat(queue);\r\n }\r\n else {\r\n queueIndex = -1;\r\n }\r\n if (queue.length)\r\n drainQueue();\r\n}\r\n\r\nfunction drainQueue() {\r\n if (draining)\r\n return;\r\n var timeout = setTimeout(cleanUpNextTick, 0);\r\n draining = true;\r\n\r\n var len = queue.length;\r\n while(len) {\r\n currentQueue = queue;\r\n queue = [];\r\n while (++queueIndex < len) {\r\n if (currentQueue)\r\n currentQueue[queueIndex].run();\r\n }\r\n queueIndex = -1;\r\n len = queue.length;\r\n }\r\n currentQueue = null;\r\n draining = false;\r\n clearTimeout(timeout);\r\n}\r\n\r\nfunction nextTick (fun) {\r\n var args = new Array(arguments.length - 1);\r\n if (arguments.length > 1) {\r\n for (var i = 1; i < arguments.length; i++)\r\n args[i - 1] = arguments[i];\r\n }\r\n queue.push(new Item(fun, args));\r\n if (queue.length === 1 && !draining)\r\n setTimeout(drainQueue, 0);\r\n}\r\n// v8 likes predictible objects\r\nfunction Item(fun, array) {\r\n this.fun = fun;\r\n this.array = array;\r\n}\r\nItem.prototype.run = function () {\r\n this.fun.apply(null, this.array);\r\n};\r\n\r\nvar title = 'browser';\r\nvar arch = 'x64';\r\nvar platform = 'browser';\r\nvar env = {\r\n PATH: '/usr/bin',\r\n LANG: navigator.language + '.UTF-8',\r\n PWD: '/',\r\n HOME: '/home',\r\n TMP: '/tmp',\r\n};\r\nvar argv = ['/usr/bin/node'];\r\nvar execArgv = [];\r\nvar version = 'v16.8.0';\r\nvar versions = {};\r\n\r\nvar emitWarning = function(message, type) {\r\n console.warn((type ? (type + ': ') : '') + message);\r\n};\r\n\r\nvar binding = function(name) { unimplemented('binding'); };\r\n\r\nvar umask = function(mask) { return 0; };\r\n\r\nvar cwd = function() { return '/'; };\r\nvar chdir = function(dir) {};\r\n\r\nvar release = {\r\n name: 'node',\r\n sourceUrl: '',\r\n headersUrl: '',\r\n libUrl: '',\r\n};\r\n\r\nfunction noop() {}\r\n\r\nvar _rawDebug = noop;\r\nvar moduleLoadList = [];\r\nfunction _linkedBinding(name) { unimplemented('_linkedBinding'); }\r\nvar domain = {};\r\nvar _exiting = false;\r\nvar config = {};\r\nfunction dlopen(name) { unimplemented('dlopen'); }\r\nfunction _getActiveRequests() { return []; }\r\nfunction _getActiveHandles() { return []; }\r\nvar reallyExit = noop;\r\nvar _kill = noop;\r\nvar cpuUsage = function() { return {}; };\r\nvar resourceUsage = cpuUsage;\r\nvar memoryUsage = cpuUsage;\r\nvar kill = noop;\r\nvar exit = noop;\r\nvar openStdin = noop;\r\nvar allowedNodeEnvironmentFlags = {};\r\nfunction assert(condition, message) {\r\n if (!condition) throw new Error(message || 'assertion error');\r\n}\r\nvar features = {\r\n inspector: false,\r\n debug: false,\r\n uv: false,\r\n ipv6: false,\r\n tls_alpn: false,\r\n tls_sni: false,\r\n tls_ocsp: false,\r\n tls: false,\r\n cached_builtins: true,\r\n};\r\nvar _fatalExceptions = noop;\r\nvar setUncaughtExceptionCaptureCallback = noop;\r\nfunction hasUncaughtExceptionCaptureCallback() { return false; }var _tickCallback = noop;\r\nvar _debugProcess = noop;\r\nvar _debugEnd = noop;\r\nvar _startProfilerIdleNotifier = noop;\r\nvar _stopProfilerIdleNotifier = noop;\r\nvar stdout = undefined;\r\nvar stderr = undefined;\r\nvar stdin = undefined;\r\nvar abort = noop;\r\nvar pid = 2;\r\nvar ppid = 1;\r\nvar execPath = '/bin/usr/node';\r\nvar debugPort = 9229;\r\nvar argv0 = 'node';\r\nvar _preload_modules = [];\r\nvar setSourceMapsEnabled = noop;\r\n\r\nvar _performance = {\r\n now: typeof performance !== 'undefined' ? performance.now.bind(performance) : undefined,\r\n timing: typeof performance !== 'undefined' ? performance.timing : undefined,\r\n};\r\nif (_performance.now === undefined) {\r\n var nowOffset = Date.now();\r\n\r\n if (_performance.timing && _performance.timing.navigationStart) {\r\n nowOffset = _performance.timing.navigationStart;\r\n }\r\n _performance.now = () => Date.now() - nowOffset;\r\n}\r\n\r\nfunction uptime() {\r\n return _performance.now() / 1000;\r\n}\r\n\r\nvar nanoPerSec = 1000000000;\r\nfunction hrtime(previousTimestamp) {\r\n var baseNow = Math.floor((Date.now() - _performance.now()) * 1e-3);\r\n var clocktime = _performance.now() * 1e-3;\r\n var seconds = Math.floor(clocktime) + baseNow;\r\n var nanoseconds = Math.floor((clocktime % 1) * 1e9);\r\n if (previousTimestamp) {\r\n seconds = seconds - previousTimestamp[0];\r\n nanoseconds = nanoseconds - previousTimestamp[1];\r\n if (nanoseconds < 0) {\r\n seconds--;\r\n nanoseconds += nanoPerSec;\r\n }\r\n }\r\n return [seconds, nanoseconds];\r\n}hrtime.bigint = function(time) {\r\n var diff = hrtime(time);\r\n if (typeof BigInt === 'undefined') {\r\n return diff[0] * nanoPerSec + diff[1];\r\n }\r\n return BigInt(diff[0] * nanoPerSec) + BigInt(diff[1]);\r\n};\r\n\r\nvar _maxListeners = 10;\r\nvar _events = {};\r\nvar _eventsCount = 0;\r\nfunction on () { return process }var addListener = on;\r\nvar once = on;\r\nvar off = on;\r\nvar removeListener = on;\r\nvar removeAllListeners = on;\r\nvar emit = noop;\r\nvar prependListener = on;\r\nvar prependOnceListener = on;\r\nfunction listeners (name) { return []; }\r\nvar process = {\r\n version,\r\n versions,\r\n arch,\r\n platform,\r\n release,\r\n _rawDebug,\r\n moduleLoadList,\r\n binding,\r\n _linkedBinding,\r\n _events,\r\n _eventsCount,\r\n _maxListeners,\r\n on,\r\n addListener,\r\n once,\r\n off,\r\n removeListener,\r\n removeAllListeners,\r\n emit,\r\n prependListener,\r\n prependOnceListener,\r\n listeners,\r\n domain,\r\n _exiting,\r\n config,\r\n dlopen,\r\n uptime,\r\n _getActiveRequests,\r\n _getActiveHandles,\r\n reallyExit,\r\n _kill,\r\n cpuUsage,\r\n resourceUsage,\r\n memoryUsage,\r\n kill,\r\n exit,\r\n openStdin,\r\n allowedNodeEnvironmentFlags,\r\n assert,\r\n features,\r\n _fatalExceptions,\r\n setUncaughtExceptionCaptureCallback,\r\n hasUncaughtExceptionCaptureCallback,\r\n emitWarning,\r\n nextTick,\r\n _tickCallback,\r\n _debugProcess,\r\n _debugEnd,\r\n _startProfilerIdleNotifier,\r\n _stopProfilerIdleNotifier,\r\n stdout,\r\n stdin,\r\n stderr,\r\n abort,\r\n umask,\r\n chdir,\r\n cwd,\r\n env,\r\n title,\r\n argv,\r\n execArgv,\r\n pid,\r\n ppid,\r\n execPath,\r\n debugPort,\r\n hrtime,\r\n argv0,\r\n _preload_modules,\r\n setSourceMapsEnabled,\r\n};\n\nexport { _debugEnd, _debugProcess, _events, _eventsCount, _exiting, _fatalExceptions, _getActiveHandles, _getActiveRequests, _kill, _linkedBinding, _maxListeners, _preload_modules, _rawDebug, _startProfilerIdleNotifier, _stopProfilerIdleNotifier, _tickCallback, abort, addListener, allowedNodeEnvironmentFlags, arch, argv, argv0, assert, binding, chdir, config, cpuUsage, cwd, debugPort, process as default, dlopen, domain, emit, emitWarning, env, execArgv, execPath, exit, features, hasUncaughtExceptionCaptureCallback, hrtime, kill, listeners, memoryUsage, moduleLoadList, nextTick, off, on, once, openStdin, pid, platform, ppid, prependListener, prependOnceListener, reallyExit, release, removeAllListeners, removeListener, resourceUsage, setSourceMapsEnabled, setUncaughtExceptionCaptureCallback, stderr, stdin, stdout, title, umask, uptime, version, versions };\n", "var exports$3 = {},\n _dewExec$2 = false;\nfunction dew$2() {\n if (_dewExec$2) return exports$3;\n _dewExec$2 = true;\n exports$3.byteLength = byteLength;\n exports$3.toByteArray = toByteArray;\n exports$3.fromByteArray = fromByteArray;\n var lookup = [];\n var revLookup = [];\n var Arr = typeof Uint8Array !== \"undefined\" ? Uint8Array : Array;\n var code = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n\n for (var i = 0, len = code.length; i < len; ++i) {\n lookup[i] = code[i];\n revLookup[code.charCodeAt(i)] = i;\n } // Support decoding URL-safe base64 strings, as Node.js does.\n // See: https://en.wikipedia.org/wiki/Base64#URL_applications\n\n\n revLookup[\"-\".charCodeAt(0)] = 62;\n revLookup[\"_\".charCodeAt(0)] = 63;\n\n function getLens(b64) {\n var len = b64.length;\n\n if (len % 4 > 0) {\n throw new Error(\"Invalid string. Length must be a multiple of 4\");\n } // Trim off extra bytes after placeholder bytes are found\n // See: https://github.com/beatgammit/base64-js/issues/42\n\n\n var validLen = b64.indexOf(\"=\");\n if (validLen === -1) validLen = len;\n var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;\n return [validLen, placeHoldersLen];\n } // base64 is 4/3 + up to two characters of the original data\n\n\n function byteLength(b64) {\n var lens = getLens(b64);\n var validLen = lens[0];\n var placeHoldersLen = lens[1];\n return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;\n }\n\n function _byteLength(b64, validLen, placeHoldersLen) {\n return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;\n }\n\n function toByteArray(b64) {\n var tmp;\n var lens = getLens(b64);\n var validLen = lens[0];\n var placeHoldersLen = lens[1];\n var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));\n var curByte = 0; // if there are placeholders, only get up to the last complete 4 chars\n\n var len = placeHoldersLen > 0 ? validLen - 4 : validLen;\n var i;\n\n for (i = 0; i < len; i += 4) {\n tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];\n arr[curByte++] = tmp >> 16 & 255;\n arr[curByte++] = tmp >> 8 & 255;\n arr[curByte++] = tmp & 255;\n }\n\n if (placeHoldersLen === 2) {\n tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;\n arr[curByte++] = tmp & 255;\n }\n\n if (placeHoldersLen === 1) {\n tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;\n arr[curByte++] = tmp >> 8 & 255;\n arr[curByte++] = tmp & 255;\n }\n\n return arr;\n }\n\n function tripletToBase64(num) {\n return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];\n }\n\n function encodeChunk(uint8, start, end) {\n var tmp;\n var output = [];\n\n for (var i = start; i < end; i += 3) {\n tmp = (uint8[i] << 16 & 16711680) + (uint8[i + 1] << 8 & 65280) + (uint8[i + 2] & 255);\n output.push(tripletToBase64(tmp));\n }\n\n return output.join(\"\");\n }\n\n function fromByteArray(uint8) {\n var tmp;\n var len = uint8.length;\n var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes\n\n var parts = [];\n var maxChunkLength = 16383; // must be multiple of 3\n // go through the array every three bytes, we'll deal with trailing stuff later\n\n for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {\n parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength));\n } // pad the end with zeros, but make sure to not forget the extra bytes\n\n\n if (extraBytes === 1) {\n tmp = uint8[len - 1];\n parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + \"==\");\n } else if (extraBytes === 2) {\n tmp = (uint8[len - 2] << 8) + uint8[len - 1];\n parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + \"=\");\n }\n\n return parts.join(\"\");\n }\n\n return exports$3;\n}\n\nvar exports$2 = {},\n _dewExec$1 = false;\nfunction dew$1() {\n if (_dewExec$1) return exports$2;\n _dewExec$1 = true;\n\n /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */\n exports$2.read = function (buffer, offset, isLE, mLen, nBytes) {\n var e, m;\n var eLen = nBytes * 8 - mLen - 1;\n var eMax = (1 << eLen) - 1;\n var eBias = eMax >> 1;\n var nBits = -7;\n var i = isLE ? nBytes - 1 : 0;\n var d = isLE ? -1 : 1;\n var s = buffer[offset + i];\n i += d;\n e = s & (1 << -nBits) - 1;\n s >>= -nBits;\n nBits += eLen;\n\n for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}\n\n m = e & (1 << -nBits) - 1;\n e >>= -nBits;\n nBits += mLen;\n\n for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}\n\n if (e === 0) {\n e = 1 - eBias;\n } else if (e === eMax) {\n return m ? NaN : (s ? -1 : 1) * Infinity;\n } else {\n m = m + Math.pow(2, mLen);\n e = e - eBias;\n }\n\n return (s ? -1 : 1) * m * Math.pow(2, e - mLen);\n };\n\n exports$2.write = function (buffer, value, offset, isLE, mLen, nBytes) {\n var e, m, c;\n var eLen = nBytes * 8 - mLen - 1;\n var eMax = (1 << eLen) - 1;\n var eBias = eMax >> 1;\n var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;\n var i = isLE ? 0 : nBytes - 1;\n var d = isLE ? 1 : -1;\n var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;\n value = Math.abs(value);\n\n if (isNaN(value) || value === Infinity) {\n m = isNaN(value) ? 1 : 0;\n e = eMax;\n } else {\n e = Math.floor(Math.log(value) / Math.LN2);\n\n if (value * (c = Math.pow(2, -e)) < 1) {\n e--;\n c *= 2;\n }\n\n if (e + eBias >= 1) {\n value += rt / c;\n } else {\n value += rt * Math.pow(2, 1 - eBias);\n }\n\n if (value * c >= 2) {\n e++;\n c /= 2;\n }\n\n if (e + eBias >= eMax) {\n m = 0;\n e = eMax;\n } else if (e + eBias >= 1) {\n m = (value * c - 1) * Math.pow(2, mLen);\n e = e + eBias;\n } else {\n m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);\n e = 0;\n }\n }\n\n for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {}\n\n e = e << mLen | m;\n eLen += mLen;\n\n for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {}\n\n buffer[offset + i - d] |= s * 128;\n };\n\n return exports$2;\n}\n\nvar exports$1 = {},\n _dewExec = false;\nfunction dew() {\n if (_dewExec) return exports$1;\n _dewExec = true;\n\n const base64 = dew$2();\n\n const ieee754 = dew$1();\n\n const customInspectSymbol = typeof Symbol === \"function\" && typeof Symbol[\"for\"] === \"function\" ? Symbol[\"for\"](\"nodejs.util.inspect.custom\") // eslint-disable-line dot-notation\n : null;\n exports$1.Buffer = Buffer;\n exports$1.SlowBuffer = SlowBuffer;\n exports$1.INSPECT_MAX_BYTES = 50;\n const K_MAX_LENGTH = 2147483647;\n exports$1.kMaxLength = K_MAX_LENGTH;\n /**\n * If `Buffer.TYPED_ARRAY_SUPPORT`:\n * === true Use Uint8Array implementation (fastest)\n * === false Print warning and recommend using `buffer` v4.x which has an Object\n * implementation (most compatible, even IE6)\n *\n * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,\n * Opera 11.6+, iOS 4.2+.\n *\n * We report that the browser does not support typed arrays if the are not subclassable\n * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`\n * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support\n * for __proto__ and has a buggy typed array implementation.\n */\n\n Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();\n\n if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== \"undefined\" && typeof console.error === \"function\") {\n console.error(\"This browser lacks typed array (Uint8Array) support which is required by \" + \"`buffer` v5.x. Use `buffer` v4.x if you require old browser support.\");\n }\n\n function typedArraySupport() {\n // Can typed array instances can be augmented?\n try {\n const arr = new Uint8Array(1);\n const proto = {\n foo: function () {\n return 42;\n }\n };\n Object.setPrototypeOf(proto, Uint8Array.prototype);\n Object.setPrototypeOf(arr, proto);\n return arr.foo() === 42;\n } catch (e) {\n return false;\n }\n }\n\n Object.defineProperty(Buffer.prototype, \"parent\", {\n enumerable: true,\n get: function () {\n if (!Buffer.isBuffer(this)) return undefined;\n return this.buffer;\n }\n });\n Object.defineProperty(Buffer.prototype, \"offset\", {\n enumerable: true,\n get: function () {\n if (!Buffer.isBuffer(this)) return undefined;\n return this.byteOffset;\n }\n });\n\n function createBuffer(length) {\n if (length > K_MAX_LENGTH) {\n throw new RangeError(\"The value \\\"\" + length + \"\\\" is invalid for option \\\"size\\\"\");\n } // Return an augmented `Uint8Array` instance\n\n\n const buf = new Uint8Array(length);\n Object.setPrototypeOf(buf, Buffer.prototype);\n return buf;\n }\n /**\n * The Buffer constructor returns instances of `Uint8Array` that have their\n * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of\n * `Uint8Array`, so the returned instances will have all the node `Buffer` methods\n * and the `Uint8Array` methods. Square bracket notation works as expected -- it\n * returns a single octet.\n *\n * The `Uint8Array` prototype remains unmodified.\n */\n\n\n function Buffer(arg, encodingOrOffset, length) {\n // Common case.\n if (typeof arg === \"number\") {\n if (typeof encodingOrOffset === \"string\") {\n throw new TypeError(\"The \\\"string\\\" argument must be of type string. Received type number\");\n }\n\n return allocUnsafe(arg);\n }\n\n return from(arg, encodingOrOffset, length);\n }\n\n Buffer.poolSize = 8192; // not used by this implementation\n\n function from(value, encodingOrOffset, length) {\n if (typeof value === \"string\") {\n return fromString(value, encodingOrOffset);\n }\n\n if (ArrayBuffer.isView(value)) {\n return fromArrayView(value);\n }\n\n if (value == null) {\n throw new TypeError(\"The first argument must be one of type string, Buffer, ArrayBuffer, Array, \" + \"or Array-like Object. Received type \" + typeof value);\n }\n\n if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) {\n return fromArrayBuffer(value, encodingOrOffset, length);\n }\n\n if (typeof SharedArrayBuffer !== \"undefined\" && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) {\n return fromArrayBuffer(value, encodingOrOffset, length);\n }\n\n if (typeof value === \"number\") {\n throw new TypeError(\"The \\\"value\\\" argument must not be of type number. Received type number\");\n }\n\n const valueOf = value.valueOf && value.valueOf();\n\n if (valueOf != null && valueOf !== value) {\n return Buffer.from(valueOf, encodingOrOffset, length);\n }\n\n const b = fromObject(value);\n if (b) return b;\n\n if (typeof Symbol !== \"undefined\" && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === \"function\") {\n return Buffer.from(value[Symbol.toPrimitive](\"string\"), encodingOrOffset, length);\n }\n\n throw new TypeError(\"The first argument must be one of type string, Buffer, ArrayBuffer, Array, \" + \"or Array-like Object. Received type \" + typeof value);\n }\n /**\n * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError\n * if value is a number.\n * Buffer.from(str[, encoding])\n * Buffer.from(array)\n * Buffer.from(buffer)\n * Buffer.from(arrayBuffer[, byteOffset[, length]])\n **/\n\n\n Buffer.from = function (value, encodingOrOffset, length) {\n return from(value, encodingOrOffset, length);\n }; // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:\n // https://github.com/feross/buffer/pull/148\n\n\n Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);\n Object.setPrototypeOf(Buffer, Uint8Array);\n\n function assertSize(size) {\n if (typeof size !== \"number\") {\n throw new TypeError(\"\\\"size\\\" argument must be of type number\");\n } else if (size < 0) {\n throw new RangeError(\"The value \\\"\" + size + \"\\\" is invalid for option \\\"size\\\"\");\n }\n }\n\n function alloc(size, fill, encoding) {\n assertSize(size);\n\n if (size <= 0) {\n return createBuffer(size);\n }\n\n if (fill !== undefined) {\n // Only pay attention to encoding if it's a string. This\n // prevents accidentally sending in a number that would\n // be interpreted as a start offset.\n return typeof encoding === \"string\" ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);\n }\n\n return createBuffer(size);\n }\n /**\n * Creates a new filled Buffer instance.\n * alloc(size[, fill[, encoding]])\n **/\n\n\n Buffer.alloc = function (size, fill, encoding) {\n return alloc(size, fill, encoding);\n };\n\n function allocUnsafe(size) {\n assertSize(size);\n return createBuffer(size < 0 ? 0 : checked(size) | 0);\n }\n /**\n * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.\n * */\n\n\n Buffer.allocUnsafe = function (size) {\n return allocUnsafe(size);\n };\n /**\n * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.\n */\n\n\n Buffer.allocUnsafeSlow = function (size) {\n return allocUnsafe(size);\n };\n\n function fromString(string, encoding) {\n if (typeof encoding !== \"string\" || encoding === \"\") {\n encoding = \"utf8\";\n }\n\n if (!Buffer.isEncoding(encoding)) {\n throw new TypeError(\"Unknown encoding: \" + encoding);\n }\n\n const length = byteLength(string, encoding) | 0;\n let buf = createBuffer(length);\n const actual = buf.write(string, encoding);\n\n if (actual !== length) {\n // Writing a hex string, for example, that contains invalid characters will\n // cause everything after the first invalid character to be ignored. (e.g.\n // 'abxxcd' will be treated as 'ab')\n buf = buf.slice(0, actual);\n }\n\n return buf;\n }\n\n function fromArrayLike(array) {\n const length = array.length < 0 ? 0 : checked(array.length) | 0;\n const buf = createBuffer(length);\n\n for (let i = 0; i < length; i += 1) {\n buf[i] = array[i] & 255;\n }\n\n return buf;\n }\n\n function fromArrayView(arrayView) {\n if (isInstance(arrayView, Uint8Array)) {\n const copy = new Uint8Array(arrayView);\n return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength);\n }\n\n return fromArrayLike(arrayView);\n }\n\n function fromArrayBuffer(array, byteOffset, length) {\n if (byteOffset < 0 || array.byteLength < byteOffset) {\n throw new RangeError(\"\\\"offset\\\" is outside of buffer bounds\");\n }\n\n if (array.byteLength < byteOffset + (length || 0)) {\n throw new RangeError(\"\\\"length\\\" is outside of buffer bounds\");\n }\n\n let buf;\n\n if (byteOffset === undefined && length === undefined) {\n buf = new Uint8Array(array);\n } else if (length === undefined) {\n buf = new Uint8Array(array, byteOffset);\n } else {\n buf = new Uint8Array(array, byteOffset, length);\n } // Return an augmented `Uint8Array` instance\n\n\n Object.setPrototypeOf(buf, Buffer.prototype);\n return buf;\n }\n\n function fromObject(obj) {\n if (Buffer.isBuffer(obj)) {\n const len = checked(obj.length) | 0;\n const buf = createBuffer(len);\n\n if (buf.length === 0) {\n return buf;\n }\n\n obj.copy(buf, 0, 0, len);\n return buf;\n }\n\n if (obj.length !== undefined) {\n if (typeof obj.length !== \"number\" || numberIsNaN(obj.length)) {\n return createBuffer(0);\n }\n\n return fromArrayLike(obj);\n }\n\n if (obj.type === \"Buffer\" && Array.isArray(obj.data)) {\n return fromArrayLike(obj.data);\n }\n }\n\n function checked(length) {\n // Note: cannot use `length < K_MAX_LENGTH` here because that fails when\n // length is NaN (which is otherwise coerced to zero.)\n if (length >= K_MAX_LENGTH) {\n throw new RangeError(\"Attempt to allocate Buffer larger than maximum \" + \"size: 0x\" + K_MAX_LENGTH.toString(16) + \" bytes\");\n }\n\n return length | 0;\n }\n\n function SlowBuffer(length) {\n if (+length != length) {\n // eslint-disable-line eqeqeq\n length = 0;\n }\n\n return Buffer.alloc(+length);\n }\n\n Buffer.isBuffer = function isBuffer(b) {\n return b != null && b._isBuffer === true && b !== Buffer.prototype; // so Buffer.isBuffer(Buffer.prototype) will be false\n };\n\n Buffer.compare = function compare(a, b) {\n if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);\n if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);\n\n if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {\n throw new TypeError(\"The \\\"buf1\\\", \\\"buf2\\\" arguments must be one of type Buffer or Uint8Array\");\n }\n\n if (a === b) return 0;\n let x = a.length;\n let y = b.length;\n\n for (let i = 0, len = Math.min(x, y); i < len; ++i) {\n if (a[i] !== b[i]) {\n x = a[i];\n y = b[i];\n break;\n }\n }\n\n if (x < y) return -1;\n if (y < x) return 1;\n return 0;\n };\n\n Buffer.isEncoding = function isEncoding(encoding) {\n switch (String(encoding).toLowerCase()) {\n case \"hex\":\n case \"utf8\":\n case \"utf-8\":\n case \"ascii\":\n case \"latin1\":\n case \"binary\":\n case \"base64\":\n case \"ucs2\":\n case \"ucs-2\":\n case \"utf16le\":\n case \"utf-16le\":\n return true;\n\n default:\n return false;\n }\n };\n\n Buffer.concat = function concat(list, length) {\n if (!Array.isArray(list)) {\n throw new TypeError(\"\\\"list\\\" argument must be an Array of Buffers\");\n }\n\n if (list.length === 0) {\n return Buffer.alloc(0);\n }\n\n let i;\n\n if (length === undefined) {\n length = 0;\n\n for (i = 0; i < list.length; ++i) {\n length += list[i].length;\n }\n }\n\n const buffer = Buffer.allocUnsafe(length);\n let pos = 0;\n\n for (i = 0; i < list.length; ++i) {\n let buf = list[i];\n\n if (isInstance(buf, Uint8Array)) {\n if (pos + buf.length > buffer.length) {\n if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);\n buf.copy(buffer, pos);\n } else {\n Uint8Array.prototype.set.call(buffer, buf, pos);\n }\n } else if (!Buffer.isBuffer(buf)) {\n throw new TypeError(\"\\\"list\\\" argument must be an Array of Buffers\");\n } else {\n buf.copy(buffer, pos);\n }\n\n pos += buf.length;\n }\n\n return buffer;\n };\n\n function byteLength(string, encoding) {\n if (Buffer.isBuffer(string)) {\n return string.length;\n }\n\n if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {\n return string.byteLength;\n }\n\n if (typeof string !== \"string\") {\n throw new TypeError(\"The \\\"string\\\" argument must be one of type string, Buffer, or ArrayBuffer. \" + \"Received type \" + typeof string);\n }\n\n const len = string.length;\n const mustMatch = arguments.length > 2 && arguments[2] === true;\n if (!mustMatch && len === 0) return 0; // Use a for loop to avoid recursion\n\n let loweredCase = false;\n\n for (;;) {\n switch (encoding) {\n case \"ascii\":\n case \"latin1\":\n case \"binary\":\n return len;\n\n case \"utf8\":\n case \"utf-8\":\n return utf8ToBytes(string).length;\n\n case \"ucs2\":\n case \"ucs-2\":\n case \"utf16le\":\n case \"utf-16le\":\n return len * 2;\n\n case \"hex\":\n return len >>> 1;\n\n case \"base64\":\n return base64ToBytes(string).length;\n\n default:\n if (loweredCase) {\n return mustMatch ? -1 : utf8ToBytes(string).length; // assume utf8\n }\n\n encoding = (\"\" + encoding).toLowerCase();\n loweredCase = true;\n }\n }\n }\n\n Buffer.byteLength = byteLength;\n\n function slowToString(encoding, start, end) {\n let loweredCase = false; // No need to verify that \"this.length <= MAX_UINT32\" since it's a read-only\n // property of a typed array.\n // This behaves neither like String nor Uint8Array in that we set start/end\n // to their upper/lower bounds if the value passed is out of range.\n // undefined is handled specially as per ECMA-262 6th Edition,\n // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.\n\n if (start === undefined || start < 0) {\n start = 0;\n } // Return early if start > this.length. Done here to prevent potential uint32\n // coercion fail below.\n\n\n if (start > this.length) {\n return \"\";\n }\n\n if (end === undefined || end > this.length) {\n end = this.length;\n }\n\n if (end <= 0) {\n return \"\";\n } // Force coercion to uint32. This will also coerce falsey/NaN values to 0.\n\n\n end >>>= 0;\n start >>>= 0;\n\n if (end <= start) {\n return \"\";\n }\n\n if (!encoding) encoding = \"utf8\";\n\n while (true) {\n switch (encoding) {\n case \"hex\":\n return hexSlice(this, start, end);\n\n case \"utf8\":\n case \"utf-8\":\n return utf8Slice(this, start, end);\n\n case \"ascii\":\n return asciiSlice(this, start, end);\n\n case \"latin1\":\n case \"binary\":\n return latin1Slice(this, start, end);\n\n case \"base64\":\n return base64Slice(this, start, end);\n\n case \"ucs2\":\n case \"ucs-2\":\n case \"utf16le\":\n case \"utf-16le\":\n return utf16leSlice(this, start, end);\n\n default:\n if (loweredCase) throw new TypeError(\"Unknown encoding: \" + encoding);\n encoding = (encoding + \"\").toLowerCase();\n loweredCase = true;\n }\n }\n } // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)\n // to detect a Buffer instance. It's not possible to use `instanceof Buffer`\n // reliably in a browserify context because there could be multiple different\n // copies of the 'buffer' package in use. This method works even for Buffer\n // instances that were created from another copy of the `buffer` package.\n // See: https://github.com/feross/buffer/issues/154\n\n\n Buffer.prototype._isBuffer = true;\n\n function swap(b, n, m) {\n const i = b[n];\n b[n] = b[m];\n b[m] = i;\n }\n\n Buffer.prototype.swap16 = function swap16() {\n const len = this.length;\n\n if (len % 2 !== 0) {\n throw new RangeError(\"Buffer size must be a multiple of 16-bits\");\n }\n\n for (let i = 0; i < len; i += 2) {\n swap(this, i, i + 1);\n }\n\n return this;\n };\n\n Buffer.prototype.swap32 = function swap32() {\n const len = this.length;\n\n if (len % 4 !== 0) {\n throw new RangeError(\"Buffer size must be a multiple of 32-bits\");\n }\n\n for (let i = 0; i < len; i += 4) {\n swap(this, i, i + 3);\n swap(this, i + 1, i + 2);\n }\n\n return this;\n };\n\n Buffer.prototype.swap64 = function swap64() {\n const len = this.length;\n\n if (len % 8 !== 0) {\n throw new RangeError(\"Buffer size must be a multiple of 64-bits\");\n }\n\n for (let i = 0; i < len; i += 8) {\n swap(this, i, i + 7);\n swap(this, i + 1, i + 6);\n swap(this, i + 2, i + 5);\n swap(this, i + 3, i + 4);\n }\n\n return this;\n };\n\n Buffer.prototype.toString = function toString() {\n const length = this.length;\n if (length === 0) return \"\";\n if (arguments.length === 0) return utf8Slice(this, 0, length);\n return slowToString.apply(this, arguments);\n };\n\n Buffer.prototype.toLocaleString = Buffer.prototype.toString;\n\n Buffer.prototype.equals = function equals(b) {\n if (!Buffer.isBuffer(b)) throw new TypeError(\"Argument must be a Buffer\");\n if (this === b) return true;\n return Buffer.compare(this, b) === 0;\n };\n\n Buffer.prototype.inspect = function inspect() {\n let str = \"\";\n const max = exports$1.INSPECT_MAX_BYTES;\n str = this.toString(\"hex\", 0, max).replace(/(.{2})/g, \"$1 \").trim();\n if (this.length > max) str += \" ... \";\n return \"<Buffer \" + str + \">\";\n };\n\n if (customInspectSymbol) {\n Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;\n }\n\n Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {\n if (isInstance(target, Uint8Array)) {\n target = Buffer.from(target, target.offset, target.byteLength);\n }\n\n if (!Buffer.isBuffer(target)) {\n throw new TypeError(\"The \\\"target\\\" argument must be one of type Buffer or Uint8Array. \" + \"Received type \" + typeof target);\n }\n\n if (start === undefined) {\n start = 0;\n }\n\n if (end === undefined) {\n end = target ? target.length : 0;\n }\n\n if (thisStart === undefined) {\n thisStart = 0;\n }\n\n if (thisEnd === undefined) {\n thisEnd = this.length;\n }\n\n if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {\n throw new RangeError(\"out of range index\");\n }\n\n if (thisStart >= thisEnd && start >= end) {\n return 0;\n }\n\n if (thisStart >= thisEnd) {\n return -1;\n }\n\n if (start >= end) {\n return 1;\n }\n\n start >>>= 0;\n end >>>= 0;\n thisStart >>>= 0;\n thisEnd >>>= 0;\n if (this === target) return 0;\n let x = thisEnd - thisStart;\n let y = end - start;\n const len = Math.min(x, y);\n const thisCopy = this.slice(thisStart, thisEnd);\n const targetCopy = target.slice(start, end);\n\n for (let i = 0; i < len; ++i) {\n if (thisCopy[i] !== targetCopy[i]) {\n x = thisCopy[i];\n y = targetCopy[i];\n break;\n }\n }\n\n if (x < y) return -1;\n if (y < x) return 1;\n return 0;\n }; // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,\n // OR the last index of `val` in `buffer` at offset <= `byteOffset`.\n //\n // Arguments:\n // - buffer - a Buffer to search\n // - val - a string, Buffer, or number\n // - byteOffset - an index into `buffer`; will be clamped to an int32\n // - encoding - an optional encoding, relevant is val is a string\n // - dir - true for indexOf, false for lastIndexOf\n\n\n function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {\n // Empty buffer means no match\n if (buffer.length === 0) return -1; // Normalize byteOffset\n\n if (typeof byteOffset === \"string\") {\n encoding = byteOffset;\n byteOffset = 0;\n } else if (byteOffset > 2147483647) {\n byteOffset = 2147483647;\n } else if (byteOffset < -2147483648) {\n byteOffset = -2147483648;\n }\n\n byteOffset = +byteOffset; // Coerce to Number.\n\n if (numberIsNaN(byteOffset)) {\n // byteOffset: it it's undefined, null, NaN, \"foo\", etc, search whole buffer\n byteOffset = dir ? 0 : buffer.length - 1;\n } // Normalize byteOffset: negative offsets start from the end of the buffer\n\n\n if (byteOffset < 0) byteOffset = buffer.length + byteOffset;\n\n if (byteOffset >= buffer.length) {\n if (dir) return -1;else byteOffset = buffer.length - 1;\n } else if (byteOffset < 0) {\n if (dir) byteOffset = 0;else return -1;\n } // Normalize val\n\n\n if (typeof val === \"string\") {\n val = Buffer.from(val, encoding);\n } // Finally, search either indexOf (if dir is true) or lastIndexOf\n\n\n if (Buffer.isBuffer(val)) {\n // Special case: looking for empty string/buffer always fails\n if (val.length === 0) {\n return -1;\n }\n\n return arrayIndexOf(buffer, val, byteOffset, encoding, dir);\n } else if (typeof val === \"number\") {\n val = val & 255; // Search for a byte value [0-255]\n\n if (typeof Uint8Array.prototype.indexOf === \"function\") {\n if (dir) {\n return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);\n } else {\n return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);\n }\n }\n\n return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);\n }\n\n throw new TypeError(\"val must be string, number or Buffer\");\n }\n\n function arrayIndexOf(arr, val, byteOffset, encoding, dir) {\n let indexSize = 1;\n let arrLength = arr.length;\n let valLength = val.length;\n\n if (encoding !== undefined) {\n encoding = String(encoding).toLowerCase();\n\n if (encoding === \"ucs2\" || encoding === \"ucs-2\" || encoding === \"utf16le\" || encoding === \"utf-16le\") {\n if (arr.length < 2 || val.length < 2) {\n return -1;\n }\n\n indexSize = 2;\n arrLength /= 2;\n valLength /= 2;\n byteOffset /= 2;\n }\n }\n\n function read(buf, i) {\n if (indexSize === 1) {\n return buf[i];\n } else {\n return buf.readUInt16BE(i * indexSize);\n }\n }\n\n let i;\n\n if (dir) {\n let foundIndex = -1;\n\n for (i = byteOffset; i < arrLength; i++) {\n if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {\n if (foundIndex === -1) foundIndex = i;\n if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;\n } else {\n if (foundIndex !== -1) i -= i - foundIndex;\n foundIndex = -1;\n }\n }\n } else {\n if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;\n\n for (i = byteOffset; i >= 0; i--) {\n let found = true;\n\n for (let j = 0; j < valLength; j++) {\n if (read(arr, i + j) !== read(val, j)) {\n found = false;\n break;\n }\n }\n\n if (found) return i;\n }\n }\n\n return -1;\n }\n\n Buffer.prototype.includes = function includes(val, byteOffset, encoding) {\n return this.indexOf(val, byteOffset, encoding) !== -1;\n };\n\n Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {\n return bidirectionalIndexOf(this, val, byteOffset, encoding, true);\n };\n\n Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {\n return bidirectionalIndexOf(this, val, byteOffset, encoding, false);\n };\n\n function hexWrite(buf, string, offset, length) {\n offset = Number(offset) || 0;\n const remaining = buf.length - offset;\n\n if (!length) {\n length = remaining;\n } else {\n length = Number(length);\n\n if (length > remaining) {\n length = remaining;\n }\n }\n\n const strLen = string.length;\n\n if (length > strLen / 2) {\n length = strLen / 2;\n }\n\n let i;\n\n for (i = 0; i < length; ++i) {\n const parsed = parseInt(string.substr(i * 2, 2), 16);\n if (numberIsNaN(parsed)) return i;\n buf[offset + i] = parsed;\n }\n\n return i;\n }\n\n function utf8Write(buf, string, offset, length) {\n return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);\n }\n\n function asciiWrite(buf, string, offset, length) {\n return blitBuffer(asciiToBytes(string), buf, offset, length);\n }\n\n function base64Write(buf, string, offset, length) {\n return blitBuffer(base64ToBytes(string), buf, offset, length);\n }\n\n function ucs2Write(buf, string, offset, length) {\n return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);\n }\n\n Buffer.prototype.write = function write(string, offset, length, encoding) {\n // Buffer#write(string)\n if (offset === undefined) {\n encoding = \"utf8\";\n length = this.length;\n offset = 0; // Buffer#write(string, encoding)\n } else if (length === undefined && typeof offset === \"string\") {\n encoding = offset;\n length = this.length;\n offset = 0; // Buffer#write(string, offset[, length][, encoding])\n } else if (isFinite(offset)) {\n offset = offset >>> 0;\n\n if (isFinite(length)) {\n length = length >>> 0;\n if (encoding === undefined) encoding = \"utf8\";\n } else {\n encoding = length;\n length = undefined;\n }\n } else {\n throw new Error(\"Buffer.write(string, encoding, offset[, length]) is no longer supported\");\n }\n\n const remaining = this.length - offset;\n if (length === undefined || length > remaining) length = remaining;\n\n if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {\n throw new RangeError(\"Attempt to write outside buffer bounds\");\n }\n\n if (!encoding) encoding = \"utf8\";\n let loweredCase = false;\n\n for (;;) {\n switch (encoding) {\n case \"hex\":\n return hexWrite(this, string, offset, length);\n\n case \"utf8\":\n case \"utf-8\":\n return utf8Write(this, string, offset, length);\n\n case \"ascii\":\n case \"latin1\":\n case \"binary\":\n return asciiWrite(this, string, offset, length);\n\n case \"base64\":\n // Warning: maxLength not taken into account in base64Write\n return base64Write(this, string, offset, length);\n\n case \"ucs2\":\n case \"ucs-2\":\n case \"utf16le\":\n case \"utf-16le\":\n return ucs2Write(this, string, offset, length);\n\n default:\n if (loweredCase) throw new TypeError(\"Unknown encoding: \" + encoding);\n encoding = (\"\" + encoding).toLowerCase();\n loweredCase = true;\n }\n }\n };\n\n Buffer.prototype.toJSON = function toJSON() {\n return {\n type: \"Buffer\",\n data: Array.prototype.slice.call(this._arr || this, 0)\n };\n };\n\n function base64Slice(buf, start, end) {\n if (start === 0 && end === buf.length) {\n return base64.fromByteArray(buf);\n } else {\n return base64.fromByteArray(buf.slice(start, end));\n }\n }\n\n function utf8Slice(buf, start, end) {\n end = Math.min(buf.length, end);\n const res = [];\n let i = start;\n\n while (i < end) {\n const firstByte = buf[i];\n let codePoint = null;\n let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;\n\n if (i + bytesPerSequence <= end) {\n let secondByte, thirdByte, fourthByte, tempCodePoint;\n\n switch (bytesPerSequence) {\n case 1:\n if (firstByte < 128) {\n codePoint = firstByte;\n }\n\n break;\n\n case 2:\n secondByte = buf[i + 1];\n\n if ((secondByte & 192) === 128) {\n tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;\n\n if (tempCodePoint > 127) {\n codePoint = tempCodePoint;\n }\n }\n\n break;\n\n case 3:\n secondByte = buf[i + 1];\n thirdByte = buf[i + 2];\n\n if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {\n tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;\n\n if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {\n codePoint = tempCodePoint;\n }\n }\n\n break;\n\n case 4:\n secondByte = buf[i + 1];\n thirdByte = buf[i + 2];\n fourthByte = buf[i + 3];\n\n if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {\n tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;\n\n if (tempCodePoint > 65535 && tempCodePoint < 1114112) {\n codePoint = tempCodePoint;\n }\n }\n\n }\n }\n\n if (codePoint === null) {\n // we did not generate a valid codePoint so insert a\n // replacement char (U+FFFD) and advance only 1 byte\n codePoint = 65533;\n bytesPerSequence = 1;\n } else if (codePoint > 65535) {\n // encode to utf16 (surrogate pair dance)\n codePoint -= 65536;\n res.push(codePoint >>> 10 & 1023 | 55296);\n codePoint = 56320 | codePoint & 1023;\n }\n\n res.push(codePoint);\n i += bytesPerSequence;\n }\n\n return decodeCodePointsArray(res);\n } // Based on http://stackoverflow.com/a/22747272/680742, the browser with\n // the lowest limit is Chrome, with 0x10000 args.\n // We go 1 magnitude less, for safety\n\n\n const MAX_ARGUMENTS_LENGTH = 4096;\n\n function decodeCodePointsArray(codePoints) {\n const len = codePoints.length;\n\n if (len <= MAX_ARGUMENTS_LENGTH) {\n return String.fromCharCode.apply(String, codePoints); // avoid extra slice()\n } // Decode in chunks to avoid \"call stack size exceeded\".\n\n\n let res = \"\";\n let i = 0;\n\n while (i < len) {\n res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));\n }\n\n return res;\n }\n\n function asciiSlice(buf, start, end) {\n let ret = \"\";\n end = Math.min(buf.length, end);\n\n for (let i = start; i < end; ++i) {\n ret += String.fromCharCode(buf[i] & 127);\n }\n\n return ret;\n }\n\n function latin1Slice(buf, start, end) {\n let ret = \"\";\n end = Math.min(buf.length, end);\n\n for (let i = start; i < end; ++i) {\n ret += String.fromCharCode(buf[i]);\n }\n\n return ret;\n }\n\n function hexSlice(buf, start, end) {\n const len = buf.length;\n if (!start || start < 0) start = 0;\n if (!end || end < 0 || end > len) end = len;\n let out = \"\";\n\n for (let i = start; i < end; ++i) {\n out += hexSliceLookupTable[buf[i]];\n }\n\n return out;\n }\n\n function utf16leSlice(buf, start, end) {\n const bytes = buf.slice(start, end);\n let res = \"\"; // If bytes.length is odd, the last 8 bits must be ignored (same as node.js)\n\n for (let i = 0; i < bytes.length - 1; i += 2) {\n res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);\n }\n\n return res;\n }\n\n Buffer.prototype.slice = function slice(start, end) {\n const len = this.length;\n start = ~~start;\n end = end === undefined ? len : ~~end;\n\n if (start < 0) {\n start += len;\n if (start < 0) start = 0;\n } else if (start > len) {\n start = len;\n }\n\n if (end < 0) {\n end += len;\n if (end < 0) end = 0;\n } else if (end > len) {\n end = len;\n }\n\n if (end < start) end = start;\n const newBuf = this.subarray(start, end); // Return an augmented `Uint8Array` instance\n\n Object.setPrototypeOf(newBuf, Buffer.prototype);\n return newBuf;\n };\n /*\n * Need to make sure that buffer isn't trying to write out of bounds.\n */\n\n\n function checkOffset(offset, ext, length) {\n if (offset % 1 !== 0 || offset < 0) throw new RangeError(\"offset is not uint\");\n if (offset + ext > length) throw new RangeError(\"Trying to access beyond buffer length\");\n }\n\n Buffer.prototype.readUintLE = Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) {\n offset = offset >>> 0;\n byteLength = byteLength >>> 0;\n if (!noAssert) checkOffset(offset, byteLength, this.length);\n let val = this[offset];\n let mul = 1;\n let i = 0;\n\n while (++i < byteLength && (mul *= 256)) {\n val += this[offset + i] * mul;\n }\n\n return val;\n };\n\n Buffer.prototype.readUintBE = Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) {\n offset = offset >>> 0;\n byteLength = byteLength >>> 0;\n\n if (!noAssert) {\n checkOffset(offset, byteLength, this.length);\n }\n\n let val = this[offset + --byteLength];\n let mul = 1;\n\n while (byteLength > 0 && (mul *= 256)) {\n val += this[offset + --byteLength] * mul;\n }\n\n return val;\n };\n\n Buffer.prototype.readUint8 = Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 1, this.length);\n return this[offset];\n };\n\n Buffer.prototype.readUint16LE = Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 2, this.length);\n return this[offset] | this[offset + 1] << 8;\n };\n\n Buffer.prototype.readUint16BE = Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 2, this.length);\n return this[offset] << 8 | this[offset + 1];\n };\n\n Buffer.prototype.readUint32LE = Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 4, this.length);\n return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;\n };\n\n Buffer.prototype.readUint32BE = Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 4, this.length);\n return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);\n };\n\n Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE(offset) {\n offset = offset >>> 0;\n validateNumber(offset, \"offset\");\n const first = this[offset];\n const last = this[offset + 7];\n\n if (first === undefined || last === undefined) {\n boundsError(offset, this.length - 8);\n }\n\n const lo = first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24;\n const hi = this[++offset] + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + last * 2 ** 24;\n return BigInt(lo) + (BigInt(hi) << BigInt(32));\n });\n Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE(offset) {\n offset = offset >>> 0;\n validateNumber(offset, \"offset\");\n const first = this[offset];\n const last = this[offset + 7];\n\n if (first === undefined || last === undefined) {\n boundsError(offset, this.length - 8);\n }\n\n const hi = first * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];\n const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last;\n return (BigInt(hi) << BigInt(32)) + BigInt(lo);\n });\n\n Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {\n offset = offset >>> 0;\n byteLength = byteLength >>> 0;\n if (!noAssert) checkOffset(offset, byteLength, this.length);\n let val = this[offset];\n let mul = 1;\n let i = 0;\n\n while (++i < byteLength && (mul *= 256)) {\n val += this[offset + i] * mul;\n }\n\n mul *= 128;\n if (val >= mul) val -= Math.pow(2, 8 * byteLength);\n return val;\n };\n\n Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) {\n offset = offset >>> 0;\n byteLength = byteLength >>> 0;\n if (!noAssert) checkOffset(offset, byteLength, this.length);\n let i = byteLength;\n let mul = 1;\n let val = this[offset + --i];\n\n while (i > 0 && (mul *= 256)) {\n val += this[offset + --i] * mul;\n }\n\n mul *= 128;\n if (val >= mul) val -= Math.pow(2, 8 * byteLength);\n return val;\n };\n\n Buffer.prototype.readInt8 = function readInt8(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 1, this.length);\n if (!(this[offset] & 128)) return this[offset];\n return (255 - this[offset] + 1) * -1;\n };\n\n Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 2, this.length);\n const val = this[offset] | this[offset + 1] << 8;\n return val & 32768 ? val | 4294901760 : val;\n };\n\n Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 2, this.length);\n const val = this[offset + 1] | this[offset] << 8;\n return val & 32768 ? val | 4294901760 : val;\n };\n\n Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 4, this.length);\n return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;\n };\n\n Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 4, this.length);\n return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];\n };\n\n Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE(offset) {\n offset = offset >>> 0;\n validateNumber(offset, \"offset\");\n const first = this[offset];\n const last = this[offset + 7];\n\n if (first === undefined || last === undefined) {\n boundsError(offset, this.length - 8);\n }\n\n const val = this[offset + 4] + this[offset + 5] * 2 ** 8 + this[offset + 6] * 2 ** 16 + (last << 24); // Overflow\n\n return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24);\n });\n Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE(offset) {\n offset = offset >>> 0;\n validateNumber(offset, \"offset\");\n const first = this[offset];\n const last = this[offset + 7];\n\n if (first === undefined || last === undefined) {\n boundsError(offset, this.length - 8);\n }\n\n const val = (first << 24) + // Overflow\n this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];\n return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last);\n });\n\n Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 4, this.length);\n return ieee754.read(this, offset, true, 23, 4);\n };\n\n Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 4, this.length);\n return ieee754.read(this, offset, false, 23, 4);\n };\n\n Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 8, this.length);\n return ieee754.read(this, offset, true, 52, 8);\n };\n\n Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {\n offset = offset >>> 0;\n if (!noAssert) checkOffset(offset, 8, this.length);\n return ieee754.read(this, offset, false, 52, 8);\n };\n\n function checkInt(buf, value, offset, ext, max, min) {\n if (!Buffer.isBuffer(buf)) throw new TypeError(\"\\\"buffer\\\" argument must be a Buffer instance\");\n if (value > max || value < min) throw new RangeError(\"\\\"value\\\" argument is out of bounds\");\n if (offset + ext > buf.length) throw new RangeError(\"Index out of range\");\n }\n\n Buffer.prototype.writeUintLE = Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) {\n value = +value;\n offset = offset >>> 0;\n byteLength = byteLength >>> 0;\n\n if (!noAssert) {\n const maxBytes = Math.pow(2, 8 * byteLength) - 1;\n checkInt(this, value, offset, byteLength, maxBytes, 0);\n }\n\n let mul = 1;\n let i = 0;\n this[offset] = value & 255;\n\n while (++i < byteLength && (mul *= 256)) {\n this[offset + i] = value / mul & 255;\n }\n\n return offset + byteLength;\n };\n\n Buffer.prototype.writeUintBE = Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) {\n value = +value;\n offset = offset >>> 0;\n byteLength = byteLength >>> 0;\n\n if (!noAssert) {\n const maxBytes = Math.pow(2, 8 * byteLength) - 1;\n checkInt(this, value, offset, byteLength, maxBytes, 0);\n }\n\n let i = byteLength - 1;\n let mul = 1;\n this[offset + i] = value & 255;\n\n while (--i >= 0 && (mul *= 256)) {\n this[offset + i] = value / mul & 255;\n }\n\n return offset + byteLength;\n };\n\n Buffer.prototype.writeUint8 = Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 1, 255, 0);\n this[offset] = value & 255;\n return offset + 1;\n };\n\n Buffer.prototype.writeUint16LE = Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);\n this[offset] = value & 255;\n this[offset + 1] = value >>> 8;\n return offset + 2;\n };\n\n Buffer.prototype.writeUint16BE = Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);\n this[offset] = value >>> 8;\n this[offset + 1] = value & 255;\n return offset + 2;\n };\n\n Buffer.prototype.writeUint32LE = Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);\n this[offset + 3] = value >>> 24;\n this[offset + 2] = value >>> 16;\n this[offset + 1] = value >>> 8;\n this[offset] = value & 255;\n return offset + 4;\n };\n\n Buffer.prototype.writeUint32BE = Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);\n this[offset] = value >>> 24;\n this[offset + 1] = value >>> 16;\n this[offset + 2] = value >>> 8;\n this[offset + 3] = value & 255;\n return offset + 4;\n };\n\n function wrtBigUInt64LE(buf, value, offset, min, max) {\n checkIntBI(value, min, max, buf, offset, 7);\n let lo = Number(value & BigInt(4294967295));\n buf[offset++] = lo;\n lo = lo >> 8;\n buf[offset++] = lo;\n lo = lo >> 8;\n buf[offset++] = lo;\n lo = lo >> 8;\n buf[offset++] = lo;\n let hi = Number(value >> BigInt(32) & BigInt(4294967295));\n buf[offset++] = hi;\n hi = hi >> 8;\n buf[offset++] = hi;\n hi = hi >> 8;\n buf[offset++] = hi;\n hi = hi >> 8;\n buf[offset++] = hi;\n return offset;\n }\n\n function wrtBigUInt64BE(buf, value, offset, min, max) {\n checkIntBI(value, min, max, buf, offset, 7);\n let lo = Number(value & BigInt(4294967295));\n buf[offset + 7] = lo;\n lo = lo >> 8;\n buf[offset + 6] = lo;\n lo = lo >> 8;\n buf[offset + 5] = lo;\n lo = lo >> 8;\n buf[offset + 4] = lo;\n let hi = Number(value >> BigInt(32) & BigInt(4294967295));\n buf[offset + 3] = hi;\n hi = hi >> 8;\n buf[offset + 2] = hi;\n hi = hi >> 8;\n buf[offset + 1] = hi;\n hi = hi >> 8;\n buf[offset] = hi;\n return offset + 8;\n }\n\n Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE(value, offset = 0) {\n return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt(\"0xffffffffffffffff\"));\n });\n Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value, offset = 0) {\n return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt(\"0xffffffffffffffff\"));\n });\n\n Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n const limit = Math.pow(2, 8 * byteLength - 1);\n checkInt(this, value, offset, byteLength, limit - 1, -limit);\n }\n\n let i = 0;\n let mul = 1;\n let sub = 0;\n this[offset] = value & 255;\n\n while (++i < byteLength && (mul *= 256)) {\n if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {\n sub = 1;\n }\n\n this[offset + i] = (value / mul >> 0) - sub & 255;\n }\n\n return offset + byteLength;\n };\n\n Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n const limit = Math.pow(2, 8 * byteLength - 1);\n checkInt(this, value, offset, byteLength, limit - 1, -limit);\n }\n\n let i = byteLength - 1;\n let mul = 1;\n let sub = 0;\n this[offset + i] = value & 255;\n\n while (--i >= 0 && (mul *= 256)) {\n if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {\n sub = 1;\n }\n\n this[offset + i] = (value / mul >> 0) - sub & 255;\n }\n\n return offset + byteLength;\n };\n\n Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 1, 127, -128);\n if (value < 0) value = 255 + value + 1;\n this[offset] = value & 255;\n return offset + 1;\n };\n\n Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);\n this[offset] = value & 255;\n this[offset + 1] = value >>> 8;\n return offset + 2;\n };\n\n Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);\n this[offset] = value >>> 8;\n this[offset + 1] = value & 255;\n return offset + 2;\n };\n\n Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);\n this[offset] = value & 255;\n this[offset + 1] = value >>> 8;\n this[offset + 2] = value >>> 16;\n this[offset + 3] = value >>> 24;\n return offset + 4;\n };\n\n Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {\n value = +value;\n offset = offset >>> 0;\n if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);\n if (value < 0) value = 4294967295 + value + 1;\n this[offset] = value >>> 24;\n this[offset + 1] = value >>> 16;\n this[offset + 2] = value >>> 8;\n this[offset + 3] = value & 255;\n return offset + 4;\n };\n\n Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE(value, offset = 0) {\n return wrtBigUInt64LE(this, value, offset, -BigInt(\"0x8000000000000000\"), BigInt(\"0x7fffffffffffffff\"));\n });\n Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE(value, offset = 0) {\n return wrtBigUInt64BE(this, value, offset, -BigInt(\"0x8000000000000000\"), BigInt(\"0x7fffffffffffffff\"));\n });\n\n function checkIEEE754(buf, value, offset, ext, max, min) {\n if (offset + ext > buf.length) throw new RangeError(\"Index out of range\");\n if (offset < 0) throw new RangeError(\"Index out of range\");\n }\n\n function writeFloat(buf, value, offset, littleEndian, noAssert) {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n checkIEEE754(buf, value, offset, 4);\n }\n\n ieee754.write(buf, value, offset, littleEndian, 23, 4);\n return offset + 4;\n }\n\n Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {\n return writeFloat(this, value, offset, true, noAssert);\n };\n\n Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {\n return writeFloat(this, value, offset, false, noAssert);\n };\n\n function writeDouble(buf, value, offset, littleEndian, noAssert) {\n value = +value;\n offset = offset >>> 0;\n\n if (!noAssert) {\n checkIEEE754(buf, value, offset, 8);\n }\n\n ieee754.write(buf, value, offset, littleEndian, 52, 8);\n return offset + 8;\n }\n\n Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {\n return writeDouble(this, value, offset, true, noAssert);\n };\n\n Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {\n return writeDouble(this, value, offset, false, noAssert);\n }; // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)\n\n\n Buffer.prototype.copy = function copy(target, targetStart, start, end) {\n if (!Buffer.isBuffer(target)) throw new TypeError(\"argument should be a Buffer\");\n if (!start) start = 0;\n if (!end && end !== 0) end = this.length;\n if (targetStart >= target.length) targetStart = target.length;\n if (!targetStart) targetStart = 0;\n if (end > 0 && end < start) end = start; // Copy 0 bytes; we're done\n\n if (end === start) return 0;\n if (target.length === 0 || this.length === 0) return 0; // Fatal error conditions\n\n if (targetStart < 0) {\n throw new RangeError(\"targetStart out of bounds\");\n }\n\n if (start < 0 || start >= this.length) throw new RangeError(\"Index out of range\");\n if (end < 0) throw new RangeError(\"sourceEnd out of bounds\"); // Are we oob?\n\n if (end > this.length) end = this.length;\n\n if (target.length - targetStart < end - start) {\n end = target.length - targetStart + start;\n }\n\n const len = end - start;\n\n if (this === target && typeof Uint8Array.prototype.copyWithin === \"function\") {\n // Use built-in when available, missing from IE11\n this.copyWithin(targetStart, start, end);\n } else {\n Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart);\n }\n\n return len;\n }; // Usage:\n // buffer.fill(number[, offset[, end]])\n // buffer.fill(buffer[, offset[, end]])\n // buffer.fill(string[, offset[, end]][, encoding])\n\n\n Buffer.prototype.fill = function fill(val, start, end, encoding) {\n // Handle string cases:\n if (typeof val === \"string\") {\n if (typeof start === \"string\") {\n encoding = start;\n start = 0;\n end = this.length;\n } else if (typeof end === \"string\") {\n encoding = end;\n end = this.length;\n }\n\n if (encoding !== undefined && typeof encoding !== \"string\") {\n throw new TypeError(\"encoding must be a string\");\n }\n\n if (typeof encoding === \"string\" && !Buffer.isEncoding(encoding)) {\n throw new TypeError(\"Unknown encoding: \" + encoding);\n }\n\n if (val.length === 1) {\n const code = val.charCodeAt(0);\n\n if (encoding === \"utf8\" && code < 128 || encoding === \"latin1\") {\n // Fast path: If `val` fits into a single byte, use that numeric value.\n val = code;\n }\n }\n } else if (typeof val === \"number\") {\n val = val & 255;\n } else if (typeof val === \"boolean\") {\n val = Number(val);\n } // Invalid ranges are not set to a default, so can range check early.\n\n\n if (start < 0 || this.length < start || this.length < end) {\n throw new RangeError(\"Out of range index\");\n }\n\n if (end <= start) {\n return this;\n }\n\n start = start >>> 0;\n end = end === undefined ? this.length : end >>> 0;\n if (!val) val = 0;\n let i;\n\n if (typeof val === \"number\") {\n for (i = start; i < end; ++i) {\n this[i] = val;\n }\n } else {\n const bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding);\n const len = bytes.length;\n\n if (len === 0) {\n throw new TypeError(\"The value \\\"\" + val + \"\\\" is invalid for argument \\\"value\\\"\");\n }\n\n for (i = 0; i < end - start; ++i) {\n this[i + start] = bytes[i % len];\n }\n }\n\n return this;\n }; // CUSTOM ERRORS\n // =============\n // Simplified versions from Node, changed for Buffer-only usage\n\n\n const errors = {};\n\n function E(sym, getMessage, Base) {\n errors[sym] = class NodeError extends Base {\n constructor() {\n super();\n Object.defineProperty(this, \"message\", {\n value: getMessage.apply(this, arguments),\n writable: true,\n configurable: true\n }); // Add the error code to the name to include it in the stack trace.\n\n this.name = `${this.name} [${sym}]`; // Access the stack to generate the error message including the error code\n // from the name.\n\n this.stack; // eslint-disable-line no-unused-expressions\n // Reset the name to the actual name.\n\n delete this.name;\n }\n\n get code() {\n return sym;\n }\n\n set code(value) {\n Object.defineProperty(this, \"code\", {\n configurable: true,\n enumerable: true,\n value,\n writable: true\n });\n }\n\n toString() {\n return `${this.name} [${sym}]: ${this.message}`;\n }\n\n };\n }\n\n E(\"ERR_BUFFER_OUT_OF_BOUNDS\", function (name) {\n if (name) {\n return `${name} is outside of buffer bounds`;\n }\n\n return \"Attempt to access memory outside buffer bounds\";\n }, RangeError);\n E(\"ERR_INVALID_ARG_TYPE\", function (name, actual) {\n return `The \"${name}\" argument must be of type number. Received type ${typeof actual}`;\n }, TypeError);\n E(\"ERR_OUT_OF_RANGE\", function (str, range, input) {\n let msg = `The value of \"${str}\" is out of range.`;\n let received = input;\n\n if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {\n received = addNumericalSeparator(String(input));\n } else if (typeof input === \"bigint\") {\n received = String(input);\n\n if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {\n received = addNumericalSeparator(received);\n }\n\n received += \"n\";\n }\n\n msg += ` It must be ${range}. Received ${received}`;\n return msg;\n }, RangeError);\n\n function addNumericalSeparator(val) {\n let res = \"\";\n let i = val.length;\n const start = val[0] === \"-\" ? 1 : 0;\n\n for (; i >= start + 4; i -= 3) {\n res = `_${val.slice(i - 3, i)}${res}`;\n }\n\n return `${val.slice(0, i)}${res}`;\n } // CHECK FUNCTIONS\n // ===============\n\n\n function checkBounds(buf, offset, byteLength) {\n validateNumber(offset, \"offset\");\n\n if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {\n boundsError(offset, buf.length - (byteLength + 1));\n }\n }\n\n function checkIntBI(value, min, max, buf, offset, byteLength) {\n if (value > max || value < min) {\n const n = typeof min === \"bigint\" ? \"n\" : \"\";\n let range;\n\n if (byteLength > 3) {\n if (min === 0 || min === BigInt(0)) {\n range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;\n } else {\n range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` + `${(byteLength + 1) * 8 - 1}${n}`;\n }\n } else {\n range = `>= ${min}${n} and <= ${max}${n}`;\n }\n\n throw new errors.ERR_OUT_OF_RANGE(\"value\", range, value);\n }\n\n checkBounds(buf, offset, byteLength);\n }\n\n function validateNumber(value, name) {\n if (typeof value !== \"number\") {\n throw new errors.ERR_INVALID_ARG_TYPE(name, \"number\", value);\n }\n }\n\n function boundsError(value, length, type) {\n if (Math.floor(value) !== value) {\n validateNumber(value, type);\n throw new errors.ERR_OUT_OF_RANGE(type || \"offset\", \"an integer\", value);\n }\n\n if (length < 0) {\n throw new errors.ERR_BUFFER_OUT_OF_BOUNDS();\n }\n\n throw new errors.ERR_OUT_OF_RANGE(type || \"offset\", `>= ${type ? 1 : 0} and <= ${length}`, value);\n } // HELPER FUNCTIONS\n // ================\n\n\n const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;\n\n function base64clean(str) {\n // Node takes equal signs as end of the Base64 encoding\n str = str.split(\"=\")[0]; // Node strips out invalid characters like \\n and \\t from the string, base64-js does not\n\n str = str.trim().replace(INVALID_BASE64_RE, \"\"); // Node converts strings with length < 2 to ''\n\n if (str.length < 2) return \"\"; // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not\n\n while (str.length % 4 !== 0) {\n str = str + \"=\";\n }\n\n return str;\n }\n\n function utf8ToBytes(string, units) {\n units = units || Infinity;\n let codePoint;\n const length = string.length;\n let leadSurrogate = null;\n const bytes = [];\n\n for (let i = 0; i < length; ++i) {\n codePoint = string.charCodeAt(i); // is surrogate component\n\n if (codePoint > 55295 && codePoint < 57344) {\n // last char was a lead\n if (!leadSurrogate) {\n // no lead yet\n if (codePoint > 56319) {\n // unexpected trail\n if ((units -= 3) > -1) bytes.push(239, 191, 189);\n continue;\n } else if (i + 1 === length) {\n // unpaired lead\n if ((units -= 3) > -1) bytes.push(239, 191, 189);\n continue;\n } // valid lead\n\n\n leadSurrogate = codePoint;\n continue;\n } // 2 leads in a row\n\n\n if (codePoint < 56320) {\n if ((units -= 3) > -1) bytes.push(239, 191, 189);\n leadSurrogate = codePoint;\n continue;\n } // valid surrogate pair\n\n\n codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;\n } else if (leadSurrogate) {\n // valid bmp char, but last char was a lead\n if ((units -= 3) > -1) bytes.push(239, 191, 189);\n }\n\n leadSurrogate = null; // encode utf8\n\n if (codePoint < 128) {\n if ((units -= 1) < 0) break;\n bytes.push(codePoint);\n } else if (codePoint < 2048) {\n if ((units -= 2) < 0) break;\n bytes.push(codePoint >> 6 | 192, codePoint & 63 | 128);\n } else if (codePoint < 65536) {\n if ((units -= 3) < 0) break;\n bytes.push(codePoint >> 12 | 224, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);\n } else if (codePoint < 1114112) {\n if ((units -= 4) < 0) break;\n bytes.push(codePoint >> 18 | 240, codePoint >> 12 & 63 | 128, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);\n } else {\n throw new Error(\"Invalid code point\");\n }\n }\n\n return bytes;\n }\n\n function asciiToBytes(str) {\n const byteArray = [];\n\n for (let i = 0; i < str.length; ++i) {\n // Node's code seems to be doing this and not & 0x7F..\n byteArray.push(str.charCodeAt(i) & 255);\n }\n\n return byteArray;\n }\n\n function utf16leToBytes(str, units) {\n let c, hi, lo;\n const byteArray = [];\n\n for (let i = 0; i < str.length; ++i) {\n if ((units -= 2) < 0) break;\n c = str.charCodeAt(i);\n hi = c >> 8;\n lo = c % 256;\n byteArray.push(lo);\n byteArray.push(hi);\n }\n\n return byteArray;\n }\n\n function base64ToBytes(str) {\n return base64.toByteArray(base64clean(str));\n }\n\n function blitBuffer(src, dst, offset, length) {\n let i;\n\n for (i = 0; i < length; ++i) {\n if (i + offset >= dst.length || i >= src.length) break;\n dst[i + offset] = src[i];\n }\n\n return i;\n } // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass\n // the `instanceof` check but they should be treated as of that type.\n // See: https://github.com/feross/buffer/issues/166\n\n\n function isInstance(obj, type) {\n return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;\n }\n\n function numberIsNaN(obj) {\n // For IE11 support\n return obj !== obj; // eslint-disable-line no-self-compare\n } // Create lookup table for `toString('hex')`\n // See: https://github.com/feross/buffer/issues/219\n\n\n const hexSliceLookupTable = function () {\n const alphabet = \"0123456789abcdef\";\n const table = new Array(256);\n\n for (let i = 0; i < 16; ++i) {\n const i16 = i * 16;\n\n for (let j = 0; j < 16; ++j) {\n table[i16 + j] = alphabet[i] + alphabet[j];\n }\n }\n\n return table;\n }(); // Return not function with Error if BigInt not supported\n\n\n function defineBigIntMethod(fn) {\n return typeof BigInt === \"undefined\" ? BufferBigIntNotDefined : fn;\n }\n\n function BufferBigIntNotDefined() {\n throw new Error(\"BigInt not supported\");\n }\n\n return exports$1;\n}\n\nconst exports = dew();\nexports['Buffer']; exports['SlowBuffer']; exports['INSPECT_MAX_BYTES']; exports['kMaxLength'];\n\nvar Buffer = exports.Buffer;\r\nvar INSPECT_MAX_BYTES = exports.INSPECT_MAX_BYTES;\r\nvar kMaxLength = exports.kMaxLength;\n\nexport { Buffer, INSPECT_MAX_BYTES, exports as default, kMaxLength };\n", "export * from './callbacks.js';\nexport * from './sync.js';\nexport * as promises from './promises.js';\nexport * as constants from './constants.js';\nexport { initialize, getMount, getMounts, mount, umount, _toUnixTimestamp } from './shared.js';\n", "import { Buffer } from 'buffer';\n/**\n * Standard libc error codes. More will be added to this enum and ErrorStrings as they are\n * needed.\n * @url http://www.gnu.org/software/libc/manual/html_node/Error-Codes.html\n */\nexport enum ErrorCode {\n\tEPERM = 1,\n\tENOENT = 2,\n\tEIO = 5,\n\tEBADF = 9,\n\tEACCES = 13,\n\tEBUSY = 16,\n\tEEXIST = 17,\n\tENOTDIR = 20,\n\tEISDIR = 21,\n\tEINVAL = 22,\n\tEFBIG = 27,\n\tENOSPC = 28,\n\tEROFS = 30,\n\tENOTEMPTY = 39,\n\tENOTSUP = 95,\n}\n\n/**\n * Strings associated with each error code.\n * @internal\n */\nexport const ErrorStrings: { [code: string | number]: string } = {};\nErrorStrings[ErrorCode.EPERM] = 'Operation not permitted.';\nErrorStrings[ErrorCode.ENOENT] = 'No such file or directory.';\nErrorStrings[ErrorCode.EIO] = 'Input/output error.';\nErrorStrings[ErrorCode.EBADF] = 'Bad file descriptor.';\nErrorStrings[ErrorCode.EACCES] = 'Permission denied.';\nErrorStrings[ErrorCode.EBUSY] = 'Resource busy or locked.';\nErrorStrings[ErrorCode.EEXIST] = 'File exists.';\nErrorStrings[ErrorCode.ENOTDIR] = 'File is not a directory.';\nErrorStrings[ErrorCode.EISDIR] = 'File is a directory.';\nErrorStrings[ErrorCode.EINVAL] = 'Invalid argument.';\nErrorStrings[ErrorCode.EFBIG] = 'File is too big.';\nErrorStrings[ErrorCode.ENOSPC] = 'No space left on disk.';\nErrorStrings[ErrorCode.EROFS] = 'Cannot modify a read-only file system.';\nErrorStrings[ErrorCode.ENOTEMPTY] = 'Directory is not empty.';\nErrorStrings[ErrorCode.ENOTSUP] = 'Operation is not supported.';\n\ninterface ApiErrorJSON {\n\terrno: ErrorCode;\n\tmessage: string;\n\tpath: string;\n\tcode: string;\n\tstack: string;\n}\n\n/**\n * Represents a ZenFS error. Passed back to applications after a failed\n * call to the ZenFS API.\n */\nexport class ApiError extends Error implements NodeJS.ErrnoException {\n\tpublic static fromJSON(json: ApiErrorJSON): ApiError {\n\t\tconst err = new ApiError(json.errno, json.message, json.path);\n\t\terr.code = json.code;\n\t\terr.stack = json.stack;\n\t\treturn err;\n\t}\n\n\t/**\n\t * Creates an ApiError object from a buffer.\n\t */\n\tpublic static fromBuffer(buffer: Buffer, i: number = 0): ApiError {\n\t\treturn ApiError.fromJSON(JSON.parse(buffer.toString('utf8', i + 4, i + 4 + buffer.readUInt32LE(i))));\n\t}\n\n\tpublic static FileError(code: ErrorCode, p: string): ApiError {\n\t\treturn new ApiError(code, ErrorStrings[code], p);\n\t}\n\n\tpublic static EACCES(path: string): ApiError {\n\t\treturn this.FileError(ErrorCode.EACCES, path);\n\t}\n\n\tpublic static ENOENT(path: string): ApiError {\n\t\treturn this.FileError(ErrorCode.ENOENT, path);\n\t}\n\n\tpublic static EEXIST(path: string): ApiError {\n\t\treturn this.FileError(ErrorCode.EEXIST, path);\n\t}\n\n\tpublic static EISDIR(path: string): ApiError {\n\t\treturn this.FileError(ErrorCode.EISDIR, path);\n\t}\n\n\tpublic static ENOTDIR(path: string): ApiError {\n\t\treturn this.FileError(ErrorCode.ENOTDIR, path);\n\t}\n\n\tpublic static EPERM(path: string): ApiError {\n\t\treturn this.FileError(ErrorCode.EPERM, path);\n\t}\n\n\tpublic static ENOTEMPTY(path: string): ApiError {\n\t\treturn this.FileError(ErrorCode.ENOTEMPTY, path);\n\t}\n\n\tpublic errno: ErrorCode;\n\tpublic code: string;\n\tpublic path?: string;\n\t// Unsupported.\n\tpublic syscall: string = '';\n\tpublic stack?: string;\n\n\t/**\n\t * Represents a ZenFS error. Passed back to applications after a failed\n\t * call to the ZenFS API.\n\t *\n\t * Error codes mirror those returned by regular Unix file operations, which is\n\t * what Node returns.\n\t * @constructor ApiError\n\t * @param type The type of the error.\n\t * @param [message] A descriptive error message.\n\t */\n\tconstructor(type: ErrorCode, message: string = ErrorStrings[type], path?: string) {\n\t\tsuper(message);\n\t\tthis.errno = type;\n\t\tthis.code = ErrorCode[type];\n\t\tthis.path = path;\n\t\tthis.message = `Error: ${this.code}: ${message}${this.path ? `, '${this.path}'` : ''}`;\n\t}\n\n\t/**\n\t * @return A friendly error message.\n\t */\n\tpublic toString(): string {\n\t\treturn this.message;\n\t}\n\n\tpublic toJSON(): any {\n\t\treturn {\n\t\t\terrno: this.errno,\n\t\t\tcode: this.code,\n\t\t\tpath: this.path,\n\t\t\tstack: this.stack,\n\t\t\tmessage: this.message,\n\t\t};\n\t}\n\n\t/**\n\t * Writes the API error into a buffer.\n\t */\n\tpublic writeToBuffer(buffer: Buffer = Buffer.alloc(this.bufferSize()), i: number = 0): Buffer {\n\t\tconst bytesWritten = buffer.write(JSON.stringify(this.toJSON()), i + 4);\n\t\tbuffer.writeUInt32LE(bytesWritten, i);\n\t\treturn buffer;\n\t}\n\n\t/**\n\t * The size of the API error in buffer-form in bytes.\n\t */\n\tpublic bufferSize(): number {\n\t\t// 4 bytes for string length.\n\t\treturn 4 + Buffer.byteLength(JSON.stringify(this.toJSON()));\n\t}\n}\n", "var exports = {},\n _dewExec = false;\n\nvar _global = typeof globalThis !== \"undefined\" ? globalThis : typeof self !== \"undefined\" ? self : global;\n\nfunction dew() {\n if (_dewExec) return exports;\n _dewExec = true;\n // shim for using process in browser\n var process = exports = {}; // cached from whatever global is present so that test runners that stub it\n // don't break things. But we need to wrap it in a try catch in case it is\n // wrapped in strict mode code which doesn't define any globals. It's inside a\n // function because try/catches deoptimize in certain engines.\n\n var cachedSetTimeout;\n var cachedClearTimeout;\n\n function defaultSetTimout() {\n throw new Error(\"setTimeout has not been defined\");\n }\n\n function defaultClearTimeout() {\n throw new Error(\"clearTimeout has not been defined\");\n }\n\n (function () {\n try {\n if (typeof setTimeout === \"function\") {\n cachedSetTimeout = setTimeout;\n } else {\n cachedSetTimeout = defaultSetTimout;\n }\n } catch (e) {\n cachedSetTimeout = defaultSetTimout;\n }\n\n try {\n if (typeof clearTimeout === \"function\") {\n cachedClearTimeout = clearTimeout;\n } else {\n cachedClearTimeout = defaultClearTimeout;\n }\n } catch (e) {\n cachedClearTimeout = defaultClearTimeout;\n }\n })();\n\n function runTimeout(fun) {\n if (cachedSetTimeout === setTimeout) {\n //normal enviroments in sane situations\n return setTimeout(fun, 0);\n } // if setTimeout wasn't available but was latter defined\n\n\n if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {\n cachedSetTimeout = setTimeout;\n return setTimeout(fun, 0);\n }\n\n try {\n // when when somebody has screwed with setTimeout but no I.E. maddness\n return cachedSetTimeout(fun, 0);\n } catch (e) {\n try {\n // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally\n return cachedSetTimeout.call(null, fun, 0);\n } catch (e) {\n // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error\n return cachedSetTimeout.call(this || _global, fun, 0);\n }\n }\n }\n\n function runClearTimeout(marker) {\n if (cachedClearTimeout === clearTimeout) {\n //normal enviroments in sane situations\n return clearTimeout(marker);\n } // if clearTimeout wasn't available but was latter defined\n\n\n if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {\n cachedClearTimeout = clearTimeout;\n return clearTimeout(marker);\n }\n\n try {\n // when when somebody has screwed with setTimeout but no I.E. maddness\n return cachedClearTimeout(marker);\n } catch (e) {\n try {\n // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally\n return cachedClearTimeout.call(null, marker);\n } catch (e) {\n // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.\n // Some versions of I.E. have different rules for clearTimeout vs setTimeout\n return cachedClearTimeout.call(this || _global, marker);\n }\n }\n }\n\n var queue = [];\n var draining = false;\n var currentQueue;\n var queueIndex = -1;\n\n function cleanUpNextTick() {\n if (!draining || !currentQueue) {\n return;\n }\n\n draining = false;\n\n if (currentQueue.length) {\n queue = currentQueue.concat(queue);\n } else {\n queueIndex = -1;\n }\n\n if (queue.length) {\n drainQueue();\n }\n }\n\n function drainQueue() {\n if (draining) {\n return;\n }\n\n var timeout = runTimeout(cleanUpNextTick);\n draining = true;\n var len = queue.length;\n\n while (len) {\n currentQueue = queue;\n queue = [];\n\n while (++queueIndex < len) {\n if (currentQueue) {\n currentQueue[queueIndex].run();\n }\n }\n\n queueIndex = -1;\n len = queue.length;\n }\n\n currentQueue = null;\n draining = false;\n runClearTimeout(timeout);\n }\n\n process.nextTick = function (fun) {\n var args = new Array(arguments.length - 1);\n\n if (arguments.length > 1) {\n for (var i = 1; i < arguments.length; i++) {\n args[i - 1] = arguments[i];\n }\n }\n\n queue.push(new Item(fun, args));\n\n if (queue.length === 1 && !draining) {\n runTimeout(drainQueue);\n }\n }; // v8 likes predictible objects\n\n\n function Item(fun, array) {\n (this || _global).fun = fun;\n (this || _global).array = array;\n }\n\n Item.prototype.run = function () {\n (this || _global).fun.apply(null, (this || _global).array);\n };\n\n process.title = \"browser\";\n process.browser = true;\n process.env = {};\n process.argv = [];\n process.version = \"\"; // empty string to avoid regexp issues\n\n process.versions = {};\n\n function noop() {}\n\n process.on = noop;\n process.addListener = noop;\n process.once = noop;\n process.off = noop;\n process.removeListener = noop;\n process.removeAllListeners = noop;\n process.emit = noop;\n process.prependListener = noop;\n process.prependOnceListener = noop;\n\n process.listeners = function (name) {\n return [];\n };\n\n process.binding = function (name) {\n throw new Error(\"process.binding is not supported\");\n };\n\n process.cwd = function () {\n return \"/\";\n };\n\n process.chdir = function (dir) {\n throw new Error(\"process.chdir is not supported\");\n };\n\n process.umask = function () {\n return 0;\n };\n\n return exports;\n}\n\nvar process = dew();\n\nprocess.platform = 'browser';\nprocess.addListener;\nprocess.argv;\nprocess.binding;\nprocess.browser;\nprocess.chdir;\nprocess.cwd;\nprocess.emit;\nprocess.env;\nprocess.listeners;\nprocess.nextTick;\nprocess.off;\nprocess.on;\nprocess.once;\nprocess.prependListener;\nprocess.prependOnceListener;\nprocess.removeAllListeners;\nprocess.removeListener;\nprocess.title;\nprocess.umask;\nprocess.version;\nprocess.versions;\n\nexport { process as p };\n", "import { p as process } from './chunk-2eac56ff.js';\n\nvar exports$1 = {},\n _dewExec = false;\nfunction dew() {\n if (_dewExec) return exports$1;\n _dewExec = true;\n var process$1 = process;\n\n function assertPath(path) {\n if (typeof path !== \"string\") {\n throw new TypeError(\"Path must be a string. Received \" + JSON.stringify(path));\n }\n } // Resolves . and .. elements in a path with directory names\n\n\n function normalizeStringPosix(path, allowAboveRoot) {\n var res = \"\";\n var lastSegmentLength = 0;\n var lastSlash = -1;\n var dots = 0;\n var code;\n\n for (var i = 0; i <= path.length; ++i) {\n if (i < path.length) code = path.charCodeAt(i);else if (code === 47\n /*/*/\n ) break;else code = 47\n /*/*/\n ;\n\n if (code === 47\n /*/*/\n ) {\n if (lastSlash === i - 1 || dots === 1) ; else if (lastSlash !== i - 1 && dots === 2) {\n if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46\n /*.*/\n || res.charCodeAt(res.length - 2) !== 46\n /*.*/\n ) {\n if (res.length > 2) {\n var lastSlashIndex = res.lastIndexOf(\"/\");\n\n if (lastSlashIndex !== res.length - 1) {\n if (lastSlashIndex === -1) {\n res = \"\";\n lastSegmentLength = 0;\n } else {\n res = res.slice(0, lastSlashIndex);\n lastSegmentLength = res.length - 1 - res.lastIndexOf(\"/\");\n }\n\n lastSlash = i;\n dots = 0;\n continue;\n }\n } else if (res.length === 2 || res.length === 1) {\n res = \"\";\n lastSegmentLength = 0;\n lastSlash = i;\n dots = 0;\n continue;\n }\n }\n\n if (allowAboveRoot) {\n if (res.length > 0) res += \"/..\";else res = \"..\";\n lastSegmentLength = 2;\n }\n } else {\n if (res.length > 0) res += \"/\" + path.slice(lastSlash + 1, i);else res = path.slice(lastSlash + 1, i);\n lastSegmentLength = i - lastSlash - 1;\n }\n\n lastSlash = i;\n dots = 0;\n } else if (code === 46\n /*.*/\n && dots !== -1) {\n ++dots;\n } else {\n dots = -1;\n }\n }\n\n return res;\n }\n\n function _format(sep, pathObject) {\n var dir = pathObject.dir || pathObject.root;\n var base = pathObject.base || (pathObject.name || \"\") + (pathObject.ext || \"\");\n\n if (!dir) {\n return base;\n }\n\n if (dir === pathObject.root) {\n return dir + base;\n }\n\n return dir + sep + base;\n }\n\n var posix = {\n // path.resolve([from ...], to)\n resolve: function resolve() {\n var resolvedPath = \"\";\n var resolvedAbsolute = false;\n var cwd;\n\n for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {\n var path;\n if (i >= 0) path = arguments[i];else {\n if (cwd === undefined) cwd = process$1.cwd();\n path = cwd;\n }\n assertPath(path); // Skip empty entries\n\n if (path.length === 0) {\n continue;\n }\n\n resolvedPath = path + \"/\" + resolvedPath;\n resolvedAbsolute = path.charCodeAt(0) === 47\n /*/*/\n ;\n } // At this point the path should be resolved to a full absolute path, but\n // handle relative paths to be safe (might happen when process.cwd() fails)\n // Normalize the path\n\n\n resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);\n\n if (resolvedAbsolute) {\n if (resolvedPath.length > 0) return \"/\" + resolvedPath;else return \"/\";\n } else if (resolvedPath.length > 0) {\n return resolvedPath;\n } else {\n return \".\";\n }\n },\n normalize: function normalize(path) {\n assertPath(path);\n if (path.length === 0) return \".\";\n var isAbsolute = path.charCodeAt(0) === 47\n /*/*/\n ;\n var trailingSeparator = path.charCodeAt(path.length - 1) === 47\n /*/*/\n ; // Normalize the path\n\n path = normalizeStringPosix(path, !isAbsolute);\n if (path.length === 0 && !isAbsolute) path = \".\";\n if (path.length > 0 && trailingSeparator) path += \"/\";\n if (isAbsolute) return \"/\" + path;\n return path;\n },\n isAbsolute: function isAbsolute(path) {\n assertPath(path);\n return path.length > 0 && path.charCodeAt(0) === 47\n /*/*/\n ;\n },\n join: function join() {\n if (arguments.length === 0) return \".\";\n var joined;\n\n for (var i = 0; i < arguments.length; ++i) {\n var arg = arguments[i];\n assertPath(arg);\n\n if (arg.length > 0) {\n if (joined === undefined) joined = arg;else joined += \"/\" + arg;\n }\n }\n\n if (joined === undefined) return \".\";\n return posix.normalize(joined);\n },\n relative: function relative(from, to) {\n assertPath(from);\n assertPath(to);\n if (from === to) return \"\";\n from = posix.resolve(from);\n to = posix.resolve(to);\n if (from === to) return \"\"; // Trim any leading backslashes\n\n var fromStart = 1;\n\n for (; fromStart < from.length; ++fromStart) {\n if (from.charCodeAt(fromStart) !== 47\n /*/*/\n ) break;\n }\n\n var fromEnd = from.length;\n var fromLen = fromEnd - fromStart; // Trim any leading backslashes\n\n var toStart = 1;\n\n for (; toStart < to.length; ++toStart) {\n if (to.charCodeAt(toStart) !== 47\n /*/*/\n ) break;\n }\n\n var toEnd = to.length;\n var toLen = toEnd - toStart; // Compare paths to find the longest common path from root\n\n var length = fromLen < toLen ? fromLen : toLen;\n var lastCommonSep = -1;\n var i = 0;\n\n for (; i <= length; ++i) {\n if (i === length) {\n if (toLen > length) {\n if (to.charCodeAt(toStart + i) === 47\n /*/*/\n ) {\n // We get here if `from` is the exact base path for `to`.\n // For example: from='/foo/bar'; to='/foo/bar/baz'\n return to.slice(toStart + i + 1);\n } else if (i === 0) {\n // We get here if `from` is the root\n // For example: from='/'; to='/foo'\n return to.slice(toStart + i);\n }\n } else if (fromLen > length) {\n if (from.charCodeAt(fromStart + i) === 47\n /*/*/\n ) {\n // We get here if `to` is the exact base path for `from`.\n // For example: from='/foo/bar/baz'; to='/foo/bar'\n lastCommonSep = i;\n } else if (i === 0) {\n // We get here if `to` is the root.\n // For example: from='/foo'; to='/'\n lastCommonSep = 0;\n }\n }\n\n break;\n }\n\n var fromCode = from.charCodeAt(fromStart + i);\n var toCode = to.charCodeAt(toStart + i);\n if (fromCode !== toCode) break;else if (fromCode === 47\n /*/*/\n ) lastCommonSep = i;\n }\n\n var out = \"\"; // Generate the relative path based on the path difference between `to`\n // and `from`\n\n for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {\n if (i === fromEnd || from.charCodeAt(i) === 47\n /*/*/\n ) {\n if (out.length === 0) out += \"..\";else out += \"/..\";\n }\n } // Lastly, append the rest of the destination (`to`) path that comes after\n // the common path parts\n\n\n if (out.length > 0) return out + to.slice(toStart + lastCommonSep);else {\n toStart += lastCommonSep;\n if (to.charCodeAt(toStart) === 47\n /*/*/\n ) ++toStart;\n return to.slice(toStart);\n }\n },\n _makeLong: function _makeLong(path) {\n return path;\n },\n dirname: function dirname(path) {\n assertPath(path);\n if (path.length === 0) return \".\";\n var code = path.charCodeAt(0);\n var hasRoot = code === 47\n /*/*/\n ;\n var end = -1;\n var matchedSlash = true;\n\n for (var i = path.length - 1; i >= 1; --i) {\n code = path.charCodeAt(i);\n\n if (code === 47\n /*/*/\n ) {\n if (!matchedSlash) {\n end = i;\n break;\n }\n } else {\n // We saw the first non-path separator\n matchedSlash = false;\n }\n }\n\n if (end === -1) return hasRoot ? \"/\" : \".\";\n if (hasRoot && end === 1) return \"//\";\n return path.slice(0, end);\n },\n basename: function basename(path, ext) {\n if (ext !== undefined && typeof ext !== \"string\") throw new TypeError(\"\\\"ext\\\" argument must be a string\");\n assertPath(path);\n var start = 0;\n var end = -1;\n var matchedSlash = true;\n var i;\n\n if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {\n if (ext.length === path.length && ext === path) return \"\";\n var extIdx = ext.length - 1;\n var firstNonSlashEnd = -1;\n\n for (i = path.length - 1; i >= 0; --i) {\n var code = path.charCodeAt(i);\n\n if (code === 47\n /*/*/\n ) {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n start = i + 1;\n break;\n }\n } else {\n if (firstNonSlashEnd === -1) {\n // We saw the first non-path separator, remember this index in case\n // we need it if the extension ends up not matching\n matchedSlash = false;\n firstNonSlashEnd = i + 1;\n }\n\n if (extIdx >= 0) {\n // Try to match the explicit extension\n if (code === ext.charCodeAt(extIdx)) {\n if (--extIdx === -1) {\n // We matched the extension, so mark this as the end of our path\n // component\n end = i;\n }\n } else {\n // Extension does not match, so our result is the entire path\n // component\n extIdx = -1;\n end = firstNonSlashEnd;\n }\n }\n }\n }\n\n if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length;\n return path.slice(start, end);\n } else {\n for (i = path.length - 1; i >= 0; --i) {\n if (path.charCodeAt(i) === 47\n /*/*/\n ) {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n start = i + 1;\n break;\n }\n } else if (end === -1) {\n // We saw the first non-path separator, mark this as the end of our\n // path component\n matchedSlash = false;\n end = i + 1;\n }\n }\n\n if (end === -1) return \"\";\n return path.slice(start, end);\n }\n },\n extname: function extname(path) {\n assertPath(path);\n var startDot = -1;\n var startPart = 0;\n var end = -1;\n var matchedSlash = true; // Track the state of characters (if any) we see before our first dot and\n // after any path separator we find\n\n var preDotState = 0;\n\n for (var i = path.length - 1; i >= 0; --i) {\n var code = path.charCodeAt(i);\n\n if (code === 47\n /*/*/\n ) {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n startPart = i + 1;\n break;\n }\n\n continue;\n }\n\n if (end === -1) {\n // We saw the first non-path separator, mark this as the end of our\n // extension\n matchedSlash = false;\n end = i + 1;\n }\n\n if (code === 46\n /*.*/\n ) {\n // If this is our first dot, mark it as the start of our extension\n if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1;\n } else if (startDot !== -1) {\n // We saw a non-dot and non-path separator before our dot, so we should\n // have a good chance at having a non-empty extension\n preDotState = -1;\n }\n }\n\n if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot\n preDotState === 0 || // The (right-most) trimmed path component is exactly '..'\n preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {\n return \"\";\n }\n\n return path.slice(startDot, end);\n },\n format: function format(pathObject) {\n if (pathObject === null || typeof pathObject !== \"object\") {\n throw new TypeError(\"The \\\"pathObject\\\" argument must be of type Object. Received type \" + typeof pathObject);\n }\n\n return _format(\"/\", pathObject);\n },\n parse: function parse(path) {\n assertPath(path);\n var ret = {\n root: \"\",\n dir: \"\",\n base: \"\",\n ext: \"\",\n name: \"\"\n };\n if (path.length === 0) return ret;\n var code = path.charCodeAt(0);\n var isAbsolute = code === 47\n /*/*/\n ;\n var start;\n\n if (isAbsolute) {\n ret.root = \"/\";\n start = 1;\n } else {\n start = 0;\n }\n\n var startDot = -1;\n var startPart = 0;\n var end = -1;\n var matchedSlash = true;\n var i = path.length - 1; // Track the state of characters (if any) we see before our first dot and\n // after any path separator we find\n\n var preDotState = 0; // Get non-dir info\n\n for (; i >= start; --i) {\n code = path.charCodeAt(i);\n\n if (code === 47\n /*/*/\n ) {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n startPart = i + 1;\n break;\n }\n\n continue;\n }\n\n if (end === -1) {\n // We saw the first non-path separator, mark this as the end of our\n // extension\n matchedSlash = false;\n end = i + 1;\n }\n\n if (code === 46\n /*.*/\n ) {\n // If this is our first dot, mark it as the start of our extension\n if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1;\n } else if (startDot !== -1) {\n // We saw a non-dot and non-path separator before our dot, so we should\n // have a good chance at having a non-empty extension\n preDotState = -1;\n }\n }\n\n if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot\n preDotState === 0 || // The (right-most) trimmed path component is exactly '..'\n preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {\n if (end !== -1) {\n if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end);\n }\n } else {\n if (startPart === 0 && isAbsolute) {\n ret.name = path.slice(1, startDot);\n ret.base = path.slice(1, end);\n } else {\n ret.name = path.slice(startPart, startDot);\n ret.base = path.slice(startPart, end);\n }\n\n ret.ext = path.slice(startDot, end);\n }\n\n if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = \"/\";\n return ret;\n },\n sep: \"/\",\n delimiter: \":\",\n win32: null,\n posix: null\n };\n posix.posix = posix;\n exports$1 = posix;\n return exports$1;\n}\n\nconst exports = dew();\n\nexport { exports as e };\n", "import { e as exports } from './chunk-23dbec7b.js';\nexport { e as default } from './chunk-23dbec7b.js';\nimport './chunk-2eac56ff.js';\n\nvar _makeLong = exports._makeLong;\r\nvar basename = exports.basename;\r\nvar delimiter = exports.delimiter;\r\nvar dirname = exports.dirname;\r\nvar extname = exports.extname;\r\nvar format = exports.format;\r\nvar isAbsolute = exports.isAbsolute;\r\nvar join = exports.join;\r\nvar normalize = exports.normalize;\r\nvar parse = exports.parse;\r\nvar posix = exports.posix;\r\nvar relative = exports.relative;\r\nvar resolve = exports.resolve;\r\nvar sep = exports.sep;\r\nvar win32 = exports.win32;\n\nexport { _makeLong, basename, delimiter, dirname, extname, format, isAbsolute, join, normalize, parse, posix, relative, resolve, sep, win32 };\n", "/*\nFS Constants\nSee https://nodejs.org/api/fs.html#file-access-constants\n*/\n\n// File Access Constants\n\n/** Constant for fs.access(). File is visible to the calling process. */\nexport const F_OK = 0;\n\n/** Constant for fs.access(). File can be read by the calling process. */\nexport const R_OK = 4;\n\n/** Constant for fs.access(). File can be written by the calling process. */\nexport const W_OK = 2;\n\n/** Constant for fs.access(). File can be executed by the calling process. */\nexport const X_OK = 1;\n\n// File Copy Constants\n\n/** Constant for fs.copyFile. Flag indicating the destination file should not be overwritten if it already exists. */\nexport const COPYFILE_EXCL = 1;\n\n/**\n * Constant for fs.copyFile. Copy operation will attempt to create a copy-on-write reflink.\n * If the underlying platform does not support copy-on-write, then a fallback copy mechanism is used.\n */\nexport const COPYFILE_FICLONE = 2;\n\n/**\n * Constant for fs.copyFile. Copy operation will attempt to create a copy-on-write reflink.\n * If the underlying platform does not support copy-on-write, then the operation will fail with an error.\n */\nexport const COPYFILE_FICLONE_FORCE = 4;\n\n// File Open Constants\n\n/** Constant for fs.open(). Flag indicating to open a file for read-only access. */\nexport const O_RDONLY = 0;\n\n/** Constant for fs.open(). Flag indicating to open a file for write-only access. */\nexport const O_WRONLY = 1;\n\n/** Constant for fs.open(). Flag indicating to open a file for read-write access. */\nexport const O_RDWR = 2;\n\n/** Constant for fs.open(). Flag indicating to create the file if it does not already exist. */\nexport const O_CREAT = 0o100; // Node internal is\n\n/** Constant for fs.open(). Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists. */\nexport const O_EXCL = 0o200;\n\n/**\n * Constant for fs.open(). Flag indicating that if path identifies a terminal device,\n * opening the path shall not cause that terminal to become the controlling terminal for the process\n * (if the process does not already have one).\n */\nexport const O_NOCTTY = 0o400;\n\n/** Constant for fs.open(). Flag indicating that if the file exists and is a regular file, and the file is opened successfully for write access, its length shall be truncated to zero. */\nexport const O_TRUNC = 0o1000;\n\n/** Constant for fs.open(). Flag indicating that data will be appended to the end of the file. */\nexport const O_APPEND = 0o2000;\n\n/** Constant for fs.open(). Flag indicating that the open should fail if the path is not a directory. */\nexport const O_DIRECTORY = 0o200000;\n\n/**\n * constant for fs.open().\n * Flag indicating reading accesses to the file system will no longer result in\n * an update to the atime information associated with the file.\n * This flag is available on Linux operating systems only.\n */\nexport const O_NOATIME = 0o1000000;\n\n/** Constant for fs.open(). Flag indicating that the open should fail if the path is a symbolic link. */\nexport const O_NOFOLLOW = 0o400000;\n\n/** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O. */\nexport const O_SYNC = 0o4010000;\n\n/** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O with write operations waiting for data integrity. */\nexport const O_DSYNC = 0o10000;\n\n/** Constant for fs.open(). Flag indicating to open the symbolic link itself rather than the resource it is pointing to. */\nexport const O_SYMLINK = 0o100000;\n\n/** Constant for fs.open(). When set, an attempt will be made to minimize caching effects of file I/O. */\nexport const O_DIRECT = 0o40000;\n\n/** Constant for fs.open(). Flag indicating to open the file in nonblocking mode when possible. */\nexport const O_NONBLOCK = 0o4000;\n\n// File Type Constants\n\n/** Constant for fs.Stats mode property for determining a file's type. Bit mask used to extract the file type code. */\nexport const S_IFMT = 0o170000;\n\n/** Constant for fs.Stats mode property for determining a file's type. File type constant for a regular file. */\nexport const S_IFREG = 0o100000;\n\n/** Constant for fs.Stats mode property for determining a file's type. File type constant for a directory. */\nexport const S_IFDIR = 0o40000;\n\n/** Constant for fs.Stats mode property for determining a file's type. File type constant for a character-oriented device file. */\nexport const S_IFCHR = 0o20000;\n\n/** Constant for fs.Stats mode property for determining a file's type. File type constant for a block-oriented device file. */\nexport const S_IFBLK = 0o60000;\n\n/** Constant for fs.Stats mode property for determining a file's type. File type constant for a FIFO/pipe. */\nexport const S_IFIFO = 0o10000;\n\n/** Constant for fs.Stats mode property for determining a file's type. File type constant for a symbolic link. */\nexport const S_IFLNK = 0o120000;\n\n/** Constant for fs.Stats mode property for determining a file's type. File type constant for a socket. */\nexport const S_IFSOCK = 0o140000;\n\n// File Mode Constants\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by owner. */\nexport const S_IRWXU = 0o700;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by owner. */\nexport const S_IRUSR = 0o400;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by owner. */\nexport const S_IWUSR = 0o200;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by owner. */\nexport const S_IXUSR = 0o100;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by group. */\nexport const S_IRWXG = 0o70;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by group. */\nexport const S_IRGRP = 0o40;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by group. */\nexport const S_IWGRP = 0o20;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by group. */\nexport const S_IXGRP = 0o10;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by others. */\nexport const S_IRWXO = 7;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by others. */\nexport const S_IROTH = 4;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by others. */\nexport const S_IWOTH = 2;\n\n/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by others. */\nexport const S_IXOTH = 1;\n", "/**\n * Credentials used for FS ops.\n * Similar to Linux's cred struct. See https://github.com/torvalds/linux/blob/master/include/linux/cred.h\n */\nexport class Cred {\n\tconstructor(public uid: number, public gid: number, public suid: number, public sgid: number, public euid: number, public egid: number) {}\n\n\tpublic static Root = new Cred(0, 0, 0, 0, 0, 0);\n}\n", "import type { StatsBase } from 'fs';\nimport { Cred } from './cred.js';\nimport { Buffer } from 'buffer';\nimport { S_IFDIR, S_IFLNK, S_IFMT, S_IFREG } from './emulation/constants.js';\n\n/**\n * Indicates the type of the given file. Applied to 'mode'.\n */\nexport enum FileType {\n\tFILE = S_IFREG,\n\tDIRECTORY = S_IFDIR,\n\tSYMLINK = S_IFLNK,\n}\n\n/**\n * Implementation of Node's `Stats`.\n *\n * Attribute descriptions are from `man 2 stat'\n * @see http://nodejs.org/api/fs.html#fs_class_fs_stats\n * @see http://man7.org/linux/man-pages/man2/stat.2.html\n */\nexport class Stats implements StatsBase<number> {\n\tpublic static fromBuffer(buffer: Buffer): Stats {\n\t\tconst size = buffer.readUInt32LE(0),\n\t\t\tmode = buffer.readUInt32LE(4),\n\t\t\tatime = buffer.readDoubleLE(8),\n\t\t\tmtime = buffer.readDoubleLE(16),\n\t\t\tctime = buffer.readDoubleLE(24),\n\t\t\tuid = buffer.readUInt32LE(32),\n\t\t\tgid = buffer.readUInt32LE(36);\n\n\t\treturn new Stats(mode & S_IFMT, size, mode & ~S_IFMT, atime, mtime, ctime, uid, gid);\n\t}\n\n\t/**\n\t * Clones the stats object.\n\t */\n\tpublic static clone(s: Stats): Stats {\n\t\treturn new Stats(s.mode & S_IFMT, s.size, s.mode & ~S_IFMT, s.atimeMs, s.mtimeMs, s.ctimeMs, s.uid, s.gid, s.birthtimeMs);\n\t}\n\n\tpublic blocks: number;\n\tpublic mode: number;\n\t// ID of device containing file\n\tpublic dev: number = 0;\n\t// inode number\n\tpublic ino: number = 0;\n\t// device ID (if special file)\n\tpublic rdev: number = 0;\n\t// number of hard links\n\tpublic nlink: number = 1;\n\t// blocksize for file system I/O\n\tpublic blksize: number = 4096;\n\t// user ID of owner\n\tpublic uid: number = 0;\n\t// group ID of owner\n\tpublic gid: number = 0;\n\t// Some file systems stash data on stats objects.\n\tpublic fileData: Buffer | null = null;\n\tpublic atimeMs: number;\n\tpublic mtimeMs: number;\n\tpublic ctimeMs: number;\n\tpublic birthtimeMs: number;\n\tpublic size: number;\n\n\tpublic get atime(): Date {\n\t\treturn new Date(this.atimeMs);\n\t}\n\n\tpublic get mtime(): Date {\n\t\treturn new Date(this.mtimeMs);\n\t}\n\n\tpublic get ctime(): Date {\n\t\treturn new Date(this.ctimeMs);\n\t}\n\n\tpublic get birthtime(): Date {\n\t\treturn new Date(this.birthtimeMs);\n\t}\n\n\t/**\n\t * Provides information about a particular entry in the file system.\n\t * @param itemType Type of the item (FILE, DIRECTORY, SYMLINK, or SOCKET)\n\t * @param size Size of the item in bytes. For directories/symlinks,\n\t * this is normally the size of the struct that represents the item.\n\t * @param mode Unix-style file mode (e.g. 0o644)\n\t * @param atimeMs time of last access, in milliseconds since epoch\n\t * @param mtimeMs time of last modification, in milliseconds since epoch\n\t * @param ctimeMs time of last time file status was changed, in milliseconds since epoch\n\t * @param uid the id of the user that owns the file\n\t * @param gid the id of the group that owns the file\n\t * @param birthtimeMs time of file creation, in milliseconds since epoch\n\t */\n\tconstructor(itemType: FileType, size: number, mode?: number, atimeMs?: number, mtimeMs?: number, ctimeMs?: number, uid?: number, gid?: number, birthtimeMs?: number) {\n\t\tthis.size = size;\n\t\tlet currentTime = 0;\n\t\tif (typeof atimeMs !== 'number') {\n\t\t\tcurrentTime = Date.now();\n\t\t\tatimeMs = currentTime;\n\t\t}\n\t\tif (typeof mtimeMs !== 'number') {\n\t\t\tif (!currentTime) {\n\t\t\t\tcurrentTime = Date.now();\n\t\t\t}\n\t\t\tmtimeMs = currentTime;\n\t\t}\n\t\tif (typeof ctimeMs !== 'number') {\n\t\t\tif (!currentTime) {\n\t\t\t\tcurrentTime = Date.now();\n\t\t\t}\n\t\t\tctimeMs = currentTime;\n\t\t}\n\t\tif (typeof birthtimeMs !== 'number') {\n\t\t\tif (!currentTime) {\n\t\t\t\tcurrentTime = Date.now();\n\t\t\t}\n\t\t\tbirthtimeMs = currentTime;\n\t\t}\n\t\tif (typeof uid !== 'number') {\n\t\t\tuid = 0;\n\t\t}\n\t\tif (typeof gid !== 'number') {\n\t\t\tgid = 0;\n\t\t}\n\t\tthis.atimeMs = atimeMs;\n\t\tthis.ctimeMs = ctimeMs;\n\t\tthis.mtimeMs = mtimeMs;\n\t\tthis.birthtimeMs = birthtimeMs;\n\n\t\tif (!mode) {\n\t\t\tswitch (itemType) {\n\t\t\t\tcase FileType.FILE:\n\t\t\t\t\tthis.mode = 0o644;\n\t\t\t\t\tbreak;\n\t\t\t\tcase FileType.DIRECTORY:\n\t\t\t\tdefault:\n\t\t\t\t\tthis.mode = 0o777;\n\t\t\t}\n\t\t} else {\n\t\t\tthis.mode = mode;\n\t\t}\n\t\t// number of 512B blocks allocated\n\t\tthis.blocks = Math.ceil(size / 512);\n\t\t// Check if mode also includes top-most bits, which indicate the file's\n\t\t// type.\n\t\tif ((this.mode & S_IFMT) == 0) {\n\t\t\tthis.mode |= itemType;\n\t\t}\n\t}\n\n\tpublic toBuffer(): Buffer {\n\t\tconst buffer = Buffer.alloc(32);\n\t\tbuffer.writeUInt32LE(this.size, 0);\n\t\tbuffer.writeUInt32LE(this.mode, 4);\n\t\tbuffer.writeDoubleLE(this.atime.getTime(), 8);\n\t\tbuffer.writeDoubleLE(this.mtime.getTime(), 16);\n\t\tbuffer.writeDoubleLE(this.ctime.getTime(), 24);\n\t\tbuffer.writeUInt32LE(this.uid, 32);\n\t\tbuffer.writeUInt32LE(this.gid, 36);\n\t\treturn buffer;\n\t}\n\n\t/**\n\t * @return [Boolean] True if this item is a file.\n\t */\n\tpublic isFile(): boolean {\n\t\treturn (this.mode & S_IFMT) === S_IFREG;\n\t}\n\n\t/**\n\t * @return [Boolean] True if this item is a directory.\n\t */\n\tpublic isDirectory(): boolean {\n\t\treturn (this.mode & S_IFMT) === S_IFDIR;\n\t}\n\n\t/**\n\t * @return [Boolean] True if this item is a symbolic link (only valid through lstat)\n\t */\n\tpublic isSymbolicLink(): boolean {\n\t\treturn (this.mode & S_IFMT) === S_IFLNK;\n\t}\n\n\t/**\n\t * Checks if a given user/group has access to this item\n\t * @param mode The request access as 4 bits (unused, read, write, execute)\n\t * @param uid The requesting UID\n\t * @param gid The requesting GID\n\t * @returns [Boolean] True if the request has access, false if the request does not\n\t */\n\tpublic hasAccess(mode: number, cred: Cred): boolean {\n\t\tif (cred.euid === 0 || cred.egid === 0) {\n\t\t\t//Running as root\n\t\t\treturn true;\n\t\t}\n\t\tconst perms = this.mode & ~S_IFMT;\n\t\tlet uMode = 0xf,\n\t\t\tgMode = 0xf,\n\t\t\twMode = 0xf;\n\n\t\tif (cred.euid == this.uid) {\n\t\t\tconst uPerms = (0xf00 & perms) >> 8;\n\t\t\tuMode = (mode ^ uPerms) & mode;\n\t\t}\n\t\tif (cred.egid == this.gid) {\n\t\t\tconst gPerms = (0xf0 & perms) >> 4;\n\t\t\tgMode = (mode ^ gPerms) & mode;\n\t\t}\n\t\tconst wPerms = 0xf & perms;\n\t\twMode = (mode ^ wPerms) & mode;\n\t\t/*\n Result = 0b0xxx (read, write, execute)\n If any bits are set that means the request does not have that permission.\n */\n\t\tconst result = uMode & gMode & wMode;\n\t\treturn !result;\n\t}\n\n\t/**\n\t * Convert the current stats object into a cred object\n\t */\n\tpublic getCred(uid: number = this.uid, gid: number = this.gid): Cred {\n\t\treturn new Cred(uid, gid, this.uid, this.gid, uid, gid);\n\t}\n\n\t/**\n\t * Change the mode of the file. We use this helper function to prevent messing\n\t * up the type of the file, which is encoded in mode.\n\t */\n\tpublic chmod(mode: number): void {\n\t\tthis.mode = (this.mode & S_IFMT) | mode;\n\t}\n\n\t/**\n\t * Change the owner user/group of the file.\n\t * This function makes sure it is a valid UID/GID (that is, a 32 unsigned int)\n\t */\n\tpublic chown(uid: number, gid: number): void {\n\t\tif (!isNaN(+uid) && 0 <= +uid && +uid < 2 ** 32) {\n\t\t\tthis.uid = uid;\n\t\t}\n\t\tif (!isNaN(+gid) && 0 <= +gid && +gid < 2 ** 32) {\n\t\t\tthis.gid = gid;\n\t\t}\n\t}\n\n\t// We don't support the following types of files.\n\n\tpublic isSocket(): boolean {\n\t\treturn false;\n\t}\n\n\tpublic isBlockDevice(): boolean {\n\t\treturn false;\n\t}\n\n\tpublic isCharacterDevice(): boolean {\n\t\treturn false;\n\t}\n\n\tpublic isFIFO(): boolean {\n\t\treturn false;\n\t}\n}\n", "import { ApiError, ErrorCode } from './ApiError.js';\nimport { Stats } from './stats.js';\nimport { FileSystem } from './filesystem.js';\nimport { getMount } from './emulation/shared.js';\nimport { Buffer } from 'buffer';\n\nexport enum ActionType {\n\t// Indicates that the code should not do anything.\n\tNOP = 0,\n\t// Indicates that the code should throw an exception.\n\tTHROW_EXCEPTION = 1,\n\t// Indicates that the code should truncate the file, but only if it is a file.\n\tTRUNCATE_FILE = 2,\n\t// Indicates that the code should create the file.\n\tCREATE_FILE = 3,\n}\n\n/**\n * Represents one of the following file flags. A convenience object.\n *\n * * `'r'` - Open file for reading. An exception occurs if the file does not exist.\n * * `'r+'` - Open file for reading and writing. An exception occurs if the file does not exist.\n * * `'rs'` - Open file for reading in synchronous mode. Instructs the filesystem to not cache writes.\n * * `'rs+'` - Open file for reading and writing, and opens the file in synchronous mode.\n * * `'w'` - Open file for writing. The file is created (if it does not exist) or truncated (if it exists).\n * * `'wx'` - Like 'w' but opens the file in exclusive mode.\n * * `'w+'` - Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).\n * * `'wx+'` - Like 'w+' but opens the file in exclusive mode.\n * * `'a'` - Open file for appending. The file is created if it does not exist.\n * * `'ax'` - Like 'a' but opens the file in exclusive mode.\n * * `'a+'` - Open file for reading and appending. The file is created if it does not exist.\n * * `'ax+'` - Like 'a+' but opens the file in exclusive mode.\n *\n * Exclusive mode ensures that the file path is newly created.\n */\nexport class FileFlag {\n\t// Contains cached FileMode instances.\n\tprivate static flagCache: Map<string, FileFlag> = new Map();\n\t// Array of valid mode strings.\n\tprivate static validFlagStrs = ['r', 'r+', 'rs', 'rs+', 'w', 'wx', 'w+', 'wx+', 'a', 'ax', 'a+', 'ax+'];\n\n\t/**\n\t * Get an object representing the given file flag.\n\t * @param modeStr The string representing the flag\n\t * @return The FileFlag object representing the flag\n\t * @throw when the flag string is invalid\n\t */\n\tpublic static getFileFlag(flagStr: string): FileFlag {\n\t\t// Check cache first.\n\t\tif (!FileFlag.flagCache.has(flagStr)) {\n\t\t\tFileFlag.flagCache.set(flagStr, new FileFlag(flagStr));\n\t\t}\n\t\treturn FileFlag.flagCache.get(flagStr);\n\t}\n\n\tprivate flagStr: string;\n\t/**\n\t * This should never be called directly.\n\t * @param modeStr The string representing the mode\n\t * @throw when the mode string is invalid\n\t */\n\tconstructor(flagStr: string) {\n\t\tthis.flagStr = flagStr;\n\t\tif (FileFlag.validFlagStrs.indexOf(flagStr) < 0) {\n\t\t\tthrow new ApiError(ErrorCode.EINVAL, 'Invalid flag: ' + flagStr);\n\t\t}\n\t}\n\n\t/**\n\t * Get the underlying flag string for this flag.\n\t */\n\tpublic getFlagString(): string {\n\t\treturn this.flagStr;\n\t}\n\n\t/**\n\t * Get the equivalent mode (0b0xxx: read, write, execute)\n\t * Note: Execute will always be 0\n\t */\n\tpublic getMode(): number {\n\t\tlet mode = 0;\n\t\tmode <<= 1;\n\t\tmode += +this.isReadable();\n\t\tmode <<= 1;\n\t\tmode += +this.isWriteable();\n\t\tmode <<= 1;\n\t\treturn mode;\n\t}\n\n\t/**\n\t * Returns true if the file is readable.\n\t */\n\tpublic isReadable(): boolean {\n\t\treturn this.flagStr.indexOf('r') !== -1 || this.flagStr.indexOf('+') !== -1;\n\t}\n\t/**\n\t * Returns true if the file is writeable.\n\t */\n\tpublic isWriteable(): boolean {\n\t\treturn this.flagStr.indexOf('w') !== -1 || this.flagStr.indexOf('a') !== -1 || this.flagStr.indexOf('+') !== -1;\n\t}\n\t/**\n\t * Returns true if the file mode should truncate.\n\t */\n\tpublic isTruncating(): boolean {\n\t\treturn this.flagStr.indexOf('w') !== -1;\n\t}\n\t/**\n\t * Returns true if the file is appendable.\n\t */\n\tpublic isAppendable(): boolean {\n\t\treturn this.flagStr.indexOf('a') !== -1;\n\t}\n\t/**\n\t * Returns true if the file is open in synchronous mode.\n\t */\n\tpublic isSynchronous(): boolean {\n\t\treturn this.flagStr.indexOf('s') !== -1;\n\t}\n\t/**\n\t * Returns true if the file is open in exclusive mode.\n\t */\n\tpublic isExclusive(): boolean {\n\t\treturn this.flagStr.indexOf('x') !== -1;\n\t}\n\t/**\n\t * Returns one of the static fields on this object that indicates the\n\t * appropriate response to the path existing.\n\t */\n\tpublic pathExistsAction(): ActionType {\n\t\tif (this.isExclusive()) {\n\t\t\treturn ActionType.THROW_EXCEPTION;\n\t\t} else if (this.isTruncating()) {\n\t\t\treturn ActionType.TRUNCATE_FILE;\n\t\t} else {\n\t\t\treturn ActionType.NOP;\n\t\t}\n\t}\n\t/**\n\t * Returns one of the static fields on this object that indicates the\n\t * appropriate response to the path not existing.\n\t */\n\tpublic pathNotExistsAction(): ActionType {\n\t\tif ((this.isWriteable() || this.isAppendable()) && this.flagStr !== 'r+') {\n\t\t\treturn ActionType.CREATE_FILE;\n\t\t} else {\n\t\t\treturn ActionType.THROW_EXCEPTION;\n\t\t}\n\t}\n}\n\nexport interface File {\n\t/**\n\t * **Core**: Get the current file position.\n\t */\n\tgetPos(): number | undefined;\n\t/**\n\t * **Core**: Asynchronous `stat`.\n\t */\n\tstat(): Promise<Stats>;\n\t/**\n\t * **Core**: Synchronous `stat`.\n\t */\n\tstatSync(): Stats;\n\t/**\n\t * **Core**: Asynchronous close.\n\t */\n\tclose(): Promise<void>;\n\t/**\n\t * **Core**: Synchronous close.\n\t */\n\tcloseSync(): void;\n\t/**\n\t * **Core**: Asynchronous truncate.\n\t */\n\ttruncate(len: number): Promise<void>;\n\t/**\n\t * **Core**: Synchronous truncate.\n\t */\n\ttruncateSync(len: number): void;\n\t/**\n\t * **Core**: Asynchronous sync.\n\t */\n\tsync(): Promise<void>;\n\t/**\n\t * **Core**: Synchronous sync.\n\t */\n\tsyncSync(): void;\n\t/**\n\t * **Core**: Write buffer to the file.\n\t * Note that it is unsafe to use fs.write multiple times on the same file\n\t * without waiting for the callback.\n\t * @param buffer Buffer containing the data to write to\n\t * the file.\n\t * @param offset Offset in the buffer to start reading data from.\n\t * @param length The amount of bytes to write to the file.\n\t * @param position Offset from the beginning of the file where this\n\t * data should be written. If position is null, the data will be written at\n\t * the current position.\n\t * @returns Promise resolving to the new length of the buffer\n\t */\n\twrite(buffer: Buffer, offset: number, length: number, position: number | null): Promise<number>;\n\t/**\n\t * **Core**: Write buffer to the file.\n\t * Note that it is unsafe to use fs.writeSync multiple times on the same file\n\t * without waiting for it to return.\n\t * @param buffer Buffer containing the data to write to\n\t * the file.\n\t * @param offset Offset in the buffer to start reading data from.\n\t * @param length The amount of bytes to write to the file.\n\t * @param position Offset from the beginning of the file where this\n\t * data should be written. If position is null, the data will be written at\n\t * the current position.\n\t */\n\twriteSync(buffer: Buffer, offset: number, length: number, position: number | null): number;\n\t/**\n\t * **Core**: Read data from the file.\n\t * @param buffer The buffer that the data will be\n\t * written to.\n\t * @param offset The offset within the buffer where writing will\n\t * start.\n\t * @param length An integer specifying the number of bytes to read.\n\t * @param position An integer specifying where to begin reading from\n\t * in the file. If position is null, data will be read from the current file\n\t * position.\n\t * @returns Promise resolving to the new length of the buffer\n\t */\n\tread(buffer: Buffer, offset: number, length: number, position: number | null): Promise<{ bytesRead: number; buffer: Buffer }>;\n\t/**\n\t * **Core**: Read data from the file.\n\t * @param buffer The buffer that the data will be written to.\n\t * @param offset The offset within the buffer where writing will start.\n\t * @param length An integer specifying the number of bytes to read.\n\t * @param position An integer specifying where to begin reading from\n\t * in the file. If position is null, data will be read from the current file\n\t * position.\n\t */\n\treadSync(buffer: Buffer, offset: number, length: number, position: number): number;\n\t/**\n\t * **Supplementary**: Asynchronous `datasync`.\n\t *\n\t * Default implementation maps to `sync`.\n\t */\n\tdatasync(): Promise<void>;\n\t/**\n\t * **Supplementary**: Synchronous `datasync`.\n\t *\n\t * Default implementation maps to `syncSync`.\n\t */\n\tdatasyncSync(): void;\n\t/**\n\t * **Optional**: Asynchronous `chown`.\n\t */\n\tchown(uid: number, gid: number): Promise<void>;\n\t/**\n\t * **Optional**: Synchronous `chown`.\n\t */\n\tchownSync(uid: number, gid: number): void;\n\t/**\n\t * **Optional**: Asynchronous `fchmod`.\n\t */\n\tchmod(mode: number): Promise<void>;\n\t/**\n\t * **Optional**: Synchronous `fchmod`.\n\t */\n\tchmodSync(mode: number): void;\n\t/**\n\t * **Optional**: Change the file timestamps of the file.\n\t */\n\tutimes(atime: Date, mtime: Date): Promise<void>;\n\t/**\n\t * **Optional**: Change the file timestamps of the file.\n\t */\n\tutimesSync(atime: Date, mtime: Date): void;\n}\n\n/**\n * Base class that contains shared implementations of functions for the file\n * object.\n */\nexport class BaseFile {\n\tpublic async sync(): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic syncSync(): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async datasync(): Promise<void> {\n\t\treturn this.sync();\n\t}\n\tpublic datasyncSync(): void {\n\t\treturn this.syncSync();\n\t}\n\tpublic async chown(uid: number, gid: number): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic chownSync(uid: number, gid: number): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async chmod(mode: number): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic chmodSync(mode: number): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async utimes(atime: Date, mtime: Date): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic utimesSync(atime: Date, mtime: Date): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n}\n\n/**\n * An implementation of the File interface that operates on a file that is\n * completely in-memory. PreloadFiles are backed by a Buffer.\n *\n * This is also an abstract class, as it lacks an implementation of 'sync' and\n * 'close'. Each filesystem that wishes to use this file representation must\n * extend this class and implement those two methods.\n * @todo 'close' lever that disables functionality once closed.\n */\nexport class PreloadFile<T extends FileSystem> extends BaseFile {\n\tprotected _fs: T;\n\tprotected _pos: number = 0;\n\tprotected _path: string;\n\tprotected _stat: Stats;\n\tprotected _flag: FileFlag;\n\tprotected _buffer: Buffer;\n\tprotected _dirty: boolean = false;\n\t/**\n\t * Creates a file with the given path and, optionally, the given contents. Note\n\t * that, if contents is specified, it will be mutated by the file!\n\t * @param _fs The file system that created the file.\n\t * @param _path\n\t * @param _mode The mode that the file was opened using.\n\t * Dictates permissions and where the file pointer starts.\n\t * @param _stat The stats object for the given file.\n\t * PreloadFile will mutate this object. Note that this object must contain\n\t * the appropriate mode that the file was opened as.\n\t * @param contents A buffer containing the entire\n\t * contents of the file. PreloadFile will mutate this buffer. If not\n\t * specified, we assume it is a new file.\n\t */\n\tconstructor(_fs: T, _path: string, _flag: FileFlag, _stat: Stats, contents?: Buffer) {\n\t\tsuper();\n\t\tthis._fs = _fs;\n\t\tthis._path = _path;\n\t\tthis._flag = _flag;\n\t\tthis._stat = _stat;\n\t\tthis._buffer = contents ? contents : Buffer.alloc(0);\n\t\t// Note: This invariant is *not* maintained once the file starts getting\n\t\t// modified.\n\t\t// Note: Only actually matters if file is readable, as writeable modes may\n\t\t// truncate/append to file.\n\t\tif (this._stat.size !== this._buffer.length && this._flag.isReadable()) {\n\t\t\tthrow new Error(`Invalid buffer: Buffer is ${this._buffer.length} long, yet Stats object specifies that file is ${this._stat.size} long.`);\n\t\t}\n\t}\n\n\t/**\n\t * NONSTANDARD: Get the underlying buffer for this file. !!DO NOT MUTATE!! Will mess up dirty tracking.\n\t */\n\tpublic getBuffer(): Buffer {\n\t\treturn this._buffer;\n\t}\n\n\t/**\n\t * NONSTANDARD: Get underlying stats for this file. !!DO NOT MUTATE!!\n\t */\n\tpublic getStats(): Stats {\n\t\treturn this._stat;\n\t}\n\n\tpublic getFlag(): FileFlag {\n\t\treturn this._flag;\n\t}\n\n\t/**\n\t * Get the path to this file.\n\t * @return [String] The path to the file.\n\t */\n\tpublic getPath(): string {\n\t\treturn this._path;\n\t}\n\n\t/**\n\t * Get the current file position.\n\t *\n\t * We emulate the following bug mentioned in the Node documentation:\n\t * > On Linux, positional writes don't work when the file is opened in append\n\t * mode. The kernel ignores the position argument and always appends the data\n\t * to the end of the file.\n\t * @return [Number] The current file position.\n\t */\n\tpublic getPos(): number {\n\t\tif (this._flag.isAppendable()) {\n\t\t\treturn this._stat.size;\n\t\t}\n\t\treturn this._pos;\n\t}\n\n\t/**\n\t * Advance the current file position by the indicated number of positions.\n\t * @param [Number] delta\n\t */\n\tpublic advancePos(delta: number): number {\n\t\treturn (this._pos += delta);\n\t}\n\n\t/**\n\t * Set the file position.\n\t * @param [Number] newPos\n\t */\n\tpublic setPos(newPos: number): number {\n\t\treturn (this._pos = newPos);\n\t}\n\n\t/**\n\t * **Core**: Asynchronous sync. Must be implemented by subclasses of this\n\t * class.\n\t * @param [Function(ZenFS.ApiError)] cb\n\t */\n\tpublic async sync(): Promise<void> {\n\t\tthis.syncSync();\n\t}\n\n\t/**\n\t * **Core**: Synchronous sync.\n\t */\n\tpublic syncSync(): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\n\t/**\n\t * **Core**: Asynchronous close. Must be implemented by subclasses of this\n\t * class.\n\t * @param [Function(ZenFS.ApiError)] cb\n\t */\n\tpublic async close(): Promise<void> {\n\t\tthis.closeSync();\n\t}\n\n\t/**\n\t * **Core**: Synchronous close.\n\t */\n\tpublic closeSync(): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\n\t/**\n\t * Asynchronous `stat`.\n\t * @param [Function(ZenFS.ApiError, ZenFS.node.fs.Stats)] cb\n\t */\n\tpublic async stat(): Promise<Stats> {\n\t\treturn Stats.clone(this._stat);\n\t}\n\n\t/**\n\t * Synchronous `stat`.\n\t */\n\tpublic statSync(): Stats {\n\t\treturn Stats.clone(this._stat);\n\t}\n\n\t/**\n\t * Asynchronous truncate.\n\t * @param [Number] len\n\t * @param [Function(ZenFS.ApiError)] cb\n\t */\n\tpublic truncate(len: number): Promise<void> {\n\t\tthis.truncateSync(len);\n\t\tif (this._flag.isSynchronous() && !getMount('/')!.metadata.synchronous) {\n\t\t\treturn this.sync();\n\t\t}\n\t}\n\n\t/**\n\t * Synchronous truncate.\n\t * @param [Number] len\n\t */\n\tpublic truncateSync(len: number): void {\n\t\tthis._dirty = true;\n\t\tif (!this._flag.isWriteable()) {\n\t\t\tthrow new ApiError(ErrorCode.EPERM, 'File not opened with a writeable mode.');\n\t\t}\n\t\tthis._stat.mtimeMs = Date.now();\n\t\tif (len > this._buffer.length) {\n\t\t\tconst buf = Buffer.alloc(len - this._buffer.length, 0);\n\t\t\t// Write will set @_stat.size for us.\n\t\t\tthis.writeSync(buf, 0, buf.length, this._buffer.length);\n\t\t\tif (this._flag.isSynchronous() && getMount('/')!.metadata.synchronous) {\n\t\t\t\tthis.syncSync();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tthis._stat.size = len;\n\t\t// Truncate buffer to 'len'.\n\t\tconst newBuff = Buffer.alloc(len);\n\t\tthis._buffer.copy(newBuff, 0, 0, len);\n\t\tthis._buffer = newBuff;\n\t\tif (this._flag.isSynchronous() && getMount('/')!.metadata.synchronous) {\n\t\t\tthis.syncSync();\n\t\t}\n\t}\n\n\t/**\n\t * Write buffer to the file.\n\t * Note that it is unsafe to use fs.write multiple times on the same file\n\t * without waiting for the callback.\n\t * @param [ZenFS.node.Buffer] buffer Buffer containing the data to write to\n\t * the file.\n\t * @param [Number] offset Offset in the buffer to start reading data from.\n\t * @param [Number] length The amount of bytes to write to the file.\n\t * @param [Number] position Offset from the beginning of the file where this\n\t * data should be written. If position is null, the data will be written at\n\t * the current position.\n\t * @param [Function(ZenFS.ApiError, Number, ZenFS.node.Buffer)]\n\t * cb The number specifies the number of bytes written into the file.\n\t */\n\tpublic async write(buffer: Buffer, offset: number, length: number, position: number): Promise<number> {\n\t\treturn this.writeSync(buffer, offset, length, position);\n\t}\n\n\t/**\n\t * Write buffer to the file.\n\t * Note that it is unsafe to use fs.writeSync multiple times on the same file\n\t * without waiting for the callback.\n\t * @param [ZenFS.node.Buffer] buffer Buffer containing the data to write to\n\t * the file.\n\t * @param [Number] offset Offset in the buffer to start reading data from.\n\t * @param [Number] length The amount of bytes to write to the file.\n\t * @param [Number] position Offset from the beginning of the file where this\n\t * data should be written. If position is null, the data will be written at\n\t * the current position.\n\t * @return [Number]\n\t */\n\tpublic writeSync(buffer: Buffer, offset: number, length: number, position: number): number {\n\t\tthis._dirty = true;\n\t\tif (position === undefined || position === null) {\n\t\t\tposition = this.getPos();\n\t\t}\n\t\tif (!this._flag.isWriteable()) {\n\t\t\tthrow new ApiError(ErrorCode.EPERM, 'File not opened with a writeable mode.');\n\t\t}\n\t\tconst endFp = position + length;\n\t\tif (endFp > this._stat.size) {\n\t\t\tthis._stat.size = endFp;\n\t\t\tif (endFp > this._buffer.length) {\n\t\t\t\t// Extend the buffer!\n\t\t\t\tconst newBuff = Buffer.alloc(endFp);\n\t\t\t\tthis._buffer.copy(newBuff);\n\t\t\t\tthis._buffer = newBuff;\n\t\t\t}\n\t\t}\n\t\tconst len = buffer.copy(this._buffer, position, offset, offset + length);\n\t\tthis._stat.mtimeMs = Date.now();\n\t\tif (this._flag.isSynchronous()) {\n\t\t\tthis.syncSync();\n\t\t\treturn len;\n\t\t}\n\t\tthis.setPos(position + len);\n\t\treturn len;\n\t}\n\n\t/**\n\t * Read data from the file.\n\t * @param [ZenFS.node.Buffer] buffer The buffer that the data will be\n\t * written to.\n\t * @param [Number] offset The offset within the buffer where writing will\n\t * start.\n\t * @param [Number] length An integer specifying the number of bytes to read.\n\t * @param [Number] position An integer specifying where to begin reading from\n\t * in the file. If position is null, data will be read from the current file\n\t * position.\n\t * @param [Function(ZenFS.ApiError, Number, ZenFS.node.Buffer)] cb The\n\t * number is the number of bytes read\n\t */\n\tpublic async read(buffer: Buffer, offset: number, length: number, position: number): Promise<{ bytesRead: number; buffer: Buffer }> {\n\t\treturn { bytesRead: this.readSync(buffer, offset, length, position), buffer };\n\t}\n\n\t/**\n\t * Read data from the file.\n\t * @param [ZenFS.node.Buffer] buffer The buffer that the data will be\n\t * written to.\n\t * @param [Number] offset The offset within the buffer where writing will\n\t * start.\n\t * @param [Number] length An integer specifying the number of bytes to read.\n\t * @param [Number] position An integer specifying where to begin reading from\n\t * in the file. If position is null, data will be read from the current file\n\t * position.\n\t * @return [Number]\n\t */\n\tpublic readSync(buffer: Buffer, offset: number, length: number, position: number): number {\n\t\tif (!this._flag.isReadable()) {\n\t\t\tthrow new ApiError(ErrorCode.EPERM, 'File not opened with a readable mode.');\n\t\t}\n\t\tif (position === undefined || position === null) {\n\t\t\tposition = this.getPos();\n\t\t}\n\t\tconst endRead = position + length;\n\t\tif (endRead > this._stat.size) {\n\t\t\tlength = this._stat.size - position;\n\t\t}\n\t\tconst rv = this._buffer.copy(buffer, offset, position, position + length);\n\t\tthis._stat.atimeMs = Date.now();\n\t\tthis._pos = position + length;\n\t\treturn rv;\n\t}\n\n\t/**\n\t * Asynchronous `fchmod`.\n\t * @param [Number|String] mode\n\t */\n\tpublic async chmod(mode: number): Promise<void> {\n\t\tthis.chmodSync(mode);\n\t}\n\n\t/**\n\t * Synchronous `fchmod`.\n\t * @param [Number] mode\n\t */\n\tpublic chmodSync(mode: number): void {\n\t\tif (!this._fs.metadata.supportsProperties) {\n\t\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t\t}\n\t\tthis._dirty = true;\n\t\tthis._stat.chmod(mode);\n\t\tthis.syncSync();\n\t}\n\n\t/**\n\t * Asynchronous `fchown`.\n\t * @param [Number] uid\n\t * @param [Number] gid\n\t */\n\tpublic async chown(uid: number, gid: number): Promise<void> {\n\t\tthis.chownSync(uid, gid);\n\t}\n\n\t/**\n\t * Synchronous `fchown`.\n\t * @param [Number] uid\n\t * @param [Number] gid\n\t */\n\tpublic chownSync(uid: number, gid: number): void {\n\t\tif (!this._fs.metadata.supportsProperties) {\n\t\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t\t}\n\t\tthis._dirty = true;\n\t\tthis._stat.chown(uid, gid);\n\t\tthis.syncSync();\n\t}\n\n\tprotected isDirty(): boolean {\n\t\treturn this._dirty;\n\t}\n\n\t/**\n\t * Resets the dirty bit. Should only be called after a sync has completed successfully.\n\t */\n\tprotected resetDirty() {\n\t\tthis._dirty = false;\n\t}\n}\n\n/**\n * File class for the InMemory and XHR file systems.\n * Doesn't sync to anything, so it works nicely for memory-only files.\n */\nexport class NoSyncFile<T extends FileSystem> extends PreloadFile<T> implements File {\n\tconstructor(_fs: T, _path: string, _flag: FileFlag, _stat: Stats, contents?: Buffer) {\n\t\tsuper(_fs, _path, _flag, _stat, contents);\n\t}\n\t/**\n\t * Asynchronous sync. Doesn't do anything, simply calls the cb.\n\t * @param [Function(ZenFS.ApiError)] cb\n\t */\n\tpublic async sync(): Promise<void> {\n\t\treturn;\n\t}\n\t/**\n\t * Synchronous sync. Doesn't do anything.\n\t */\n\tpublic syncSync(): void {\n\t\t// NOP.\n\t}\n\t/**\n\t * Asynchronous close. Doesn't do anything, simply calls the cb.\n\t * @param [Function(ZenFS.ApiError)] cb\n\t */\n\tpublic async close(): Promise<void> {\n\t\treturn;\n\t}\n\t/**\n\t * Synchronous close. Doesn't do anything.\n\t */\n\tpublic closeSync(): void {\n\t\t// NOP.\n\t}\n}\n", "/* eslint-disable @typescript-eslint/no-unused-vars */\n// disable no-unused-vars since BaseFileSystem uses them a lot\n\nimport { ApiError, ErrorCode } from './ApiError.js';\nimport { Stats } from './stats.js';\nimport { File, FileFlag, ActionType } from './file.js';\nimport * as path from 'path';\nimport { Cred } from './cred.js';\nimport { Buffer } from 'buffer';\n\nexport type BFSOneArgCallback = (e?: ApiError) => unknown;\nexport type BFSCallback<T> = (e?: ApiError, rv?: T) => unknown;\nexport type BFSThreeArgCallback<T, U> = (e?: ApiError, arg1?: T, arg2?: U) => unknown;\n\nexport type FileContents = Buffer | string;\n\n/**\n * Metadata about a FileSystem\n */\nexport interface FileSystemMetadata {\n\t/**\n\t * The name of the FS\n\t */\n\tname: string;\n\n\t/**\n\t * Wheter the FS is readonly or not\n\t */\n\treadonly: boolean;\n\n\t/**\n\t * Does the FS support synchronous operations\n\t */\n\tsynchronous: boolean;\n\n\t/**\n\t * Does the FS support properties\n\t */\n\tsupportsProperties: boolean;\n\n\t/**\n\t * Does the FS support links\n\t */\n\tsupportsLinks: boolean;\n\n\t/**\n\t * The total space\n\t */\n\ttotalSpace: number;\n\n\t/**\n\t * The available space\n\t */\n\tfreeSpace: number;\n}\n\n/**\n * Structure for a filesystem. **All** ZenFS FileSystems must implement\n * this.\n *\n * ### Argument Assumptions\n *\n * You can assume the following about arguments passed to each API method:\n *\n * - Every path is an absolute path. `.`, `..`, and other items\n * are resolved into an absolute form.\n * - All arguments are present. Any optional arguments at the Node API level\n * have been passed in with their default values.\n */\nexport abstract class FileSystem {\n\tstatic readonly Name: string;\n\n\tabstract readonly metadata: FileSystemMetadata;\n\n\tconstructor(options?: object) {\n\t\t// unused\n\t}\n\n\tabstract whenReady(): Promise<this>;\n\n\t// File or directory operations\n\t/**\n\t * Asynchronous access.\n\t */\n\tabstract access(p: string, mode: number, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous access.\n\t */\n\tabstract accessSync(p: string, mode: number, cred: Cred): void;\n\t/**\n\t * Asynchronous rename. No arguments other than a possible exception\n\t * are given to the completion callback.\n\t */\n\tabstract rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous rename.\n\t */\n\tabstract renameSync(oldPath: string, newPath: string, cred: Cred): void;\n\t/**\n\t * Asynchronous `stat`.\n\t */\n\tabstract stat(p: string, cred: Cred): Promise<Stats>;\n\t/**\n\t * Synchronous `stat`.\n\t */\n\tabstract statSync(p: string, cred: Cred): Stats;\n\t// File operations\n\t/**\n\t * Asynchronous file open.\n\t * @see http://www.manpagez.com/man/2/open/\n\t * @param flags Handles the complexity of the various file\n\t * modes. See its API for more details.\n\t * @param mode Mode to use to open the file. Can be ignored if the\n\t * filesystem doesn't support permissions.\n\t */\n\tabstract open(p: string, flag: FileFlag, mode: number, cred: Cred): Promise<File>;\n\t/**\n\t * Synchronous file open.\n\t * @see http://www.manpagez.com/man/2/open/\n\t * @param flags Handles the complexity of the various file\n\t * modes. See its API for more details.\n\t * @param mode Mode to use to open the file. Can be ignored if the\n\t * filesystem doesn't support permissions.\n\t */\n\tabstract openSync(p: string, flag: FileFlag, mode: number, cred: Cred): File;\n\t/**\n\t * Asynchronous `unlink`.\n\t */\n\tabstract unlink(p: string, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous `unlink`.\n\t */\n\tabstract unlinkSync(p: string, cred: Cred): void;\n\t// Directory operations\n\t/**\n\t * Asynchronous `rmdir`.\n\t */\n\tabstract rmdir(p: string, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous `rmdir`.\n\t */\n\tabstract rmdirSync(p: string, cred: Cred): void;\n\t/**\n\t * Asynchronous `mkdir`.\n\t * @param mode Mode to make the directory using. Can be ignored if\n\t * the filesystem doesn't support permissions.\n\t */\n\tabstract mkdir(p: string, mode: number, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous `mkdir`.\n\t * @param mode Mode to make the directory using. Can be ignored if\n\t * the filesystem doesn't support permissions.\n\t */\n\tabstract mkdirSync(p: string, mode: number, cred: Cred): void;\n\t/**\n\t * Asynchronous `readdir`. Reads the contents of a directory.\n\t *\n\t * The callback gets two arguments `(err, files)` where `files` is an array of\n\t * the names of the files in the directory excluding `'.'` and `'..'`.\n\t */\n\tabstract readdir(p: string, cred: Cred): Promise<string[]>;\n\t/**\n\t * Synchronous `readdir`. Reads the contents of a directory.\n\t */\n\tabstract readdirSync(p: string, cred: Cred): string[];\n\t// **SUPPLEMENTAL INTERFACE METHODS**\n\t// File or directory operations\n\t/**\n\t * Test whether or not the given path exists by checking with\n\t * the file system. Then call the callback argument with either true or false.\n\t */\n\tabstract exists(p: string, cred: Cred): Promise<boolean>;\n\t/**\n\t * Test whether or not the given path exists by checking with\n\t * the file system.\n\t */\n\tabstract existsSync(p: string, cred: Cred): boolean;\n\t/**\n\t * Asynchronous `realpath`. The callback gets two arguments\n\t * `(err, resolvedPath)`.\n\t *\n\t * Note that the Node API will resolve `path` to an absolute path.\n\t * @param cache An object literal of mapped paths that can be used to\n\t * force a specific path resolution or avoid additional `fs.stat` calls for\n\t * known real paths. If not supplied by the user, it'll be an empty object.\n\t */\n\tabstract realpath(p: string, cred: Cred): Promise<string>;\n\t/**\n\t * Synchronous `realpath`.\n\t *\n\t * Note that the Node API will resolve `path` to an absolute path.\n\t * @param cache An object literal of mapped paths that can be used to\n\t * force a specific path resolution or avoid additional `fs.stat` calls for\n\t * known real paths. If not supplied by the user, it'll be an empty object.\n\t */\n\tabstract realpathSync(p: string, cred: Cred): string;\n\t// File operations\n\t/**\n\t * Asynchronous `truncate`.\n\t */\n\tabstract truncate(p: string, len: number, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous `truncate`.\n\t */\n\tabstract truncateSync(p: string, len: number, cred: Cred): void;\n\t/**\n\t * Asynchronously reads the entire contents of a file.\n\t * @param encoding If non-null, the file's contents should be decoded\n\t * into a string using that encoding. Otherwise, if encoding is null, fetch\n\t * the file's contents as a Buffer.\n\t * If no encoding is specified, then the raw buffer is returned.\n\t */\n\tabstract readFile(fname: string, encoding: BufferEncoding | null, flag: FileFlag, cred: Cred): Promise<FileContents>;\n\t/**\n\t * Synchronously reads the entire contents of a file.\n\t * @param encoding If non-null, the file's contents should be decoded\n\t * into a string using that encoding. Otherwise, if encoding is null, fetch\n\t * the file's contents as a Buffer.\n\t */\n\tabstract readFileSync(fname: string, encoding: BufferEncoding | null, flag: FileFlag, cred: Cred): FileContents;\n\t/**\n\t * Asynchronously writes data to a file, replacing the file\n\t * if it already exists.\n\t *\n\t * The encoding option is ignored if data is a buffer.\n\t */\n\tabstract writeFile(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronously writes data to a file, replacing the file\n\t * if it already exists.\n\t *\n\t * The encoding option is ignored if data is a buffer.\n\t */\n\tabstract writeFileSync(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): void;\n\t/**\n\t * Asynchronously append data to a file, creating the file if\n\t * it not yet exists.\n\t */\n\tabstract appendFile(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronously append data to a file, creating the file if\n\t * it not yet exists.\n\t */\n\tabstract appendFileSync(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): void;\n\t// **OPTIONAL INTERFACE METHODS**\n\t// Property operations\n\t// This isn't always possible on some filesystem types (e.g. Dropbox).\n\t/**\n\t * Asynchronous `chmod`.\n\t */\n\tabstract chmod(p: string, mode: number, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous `chmod`.\n\t */\n\tabstract chmodSync(p: string, mode: number, cred: Cred): void;\n\t/**\n\t * Asynchronous `chown`.\n\t */\n\tabstract chown(p: string, new_uid: number, new_gid: number, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous `chown`.\n\t */\n\tabstract chownSync(p: string, new_uid: number, new_gid: number, cred: Cred): void;\n\t/**\n\t * Change file timestamps of the file referenced by the supplied\n\t * path.\n\t */\n\tabstract utimes(p: string, atime: Date, mtime: Date, cred: Cred): Promise<void>;\n\t/**\n\t * Change file timestamps of the file referenced by the supplied\n\t * path.\n\t */\n\tabstract utimesSync(p: string, atime: Date, mtime: Date, cred: Cred): void;\n\t// Symlink operations\n\t// Symlinks aren't always supported.\n\t/**\n\t * Asynchronous `link`.\n\t */\n\tabstract link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous `link`.\n\t */\n\tabstract linkSync(srcpath: string, dstpath: string, cred: Cred): void;\n\t/**\n\t * Asynchronous `symlink`.\n\t * @param type can be either `'dir'` or `'file'`\n\t */\n\tabstract symlink(srcpath: string, dstpath: string, type: string, cred: Cred): Promise<void>;\n\t/**\n\t * Synchronous `symlink`.\n\t * @param type can be either `'dir'` or `'file'`\n\t */\n\tabstract symlinkSync(srcpath: string, dstpath: string, type: string, cred: Cred): void;\n\t/**\n\t * Asynchronous readlink.\n\t */\n\tabstract readlink(p: string, cred: Cred): Promise<string>;\n\t/**\n\t * Synchronous readlink.\n\t */\n\tabstract readlinkSync(p: string, cred: Cred): string;\n}\n\n/**\n * Basic filesystem class. Most filesystems should extend this class, as it\n * provides default implementations for a handful of methods.\n */\nexport class BaseFileSystem extends FileSystem {\n\tstatic readonly Name: string = this.name;\n\n\tprotected _ready: Promise<this> = Promise.resolve(this);\n\n\tpublic constructor(options?: { [key: string]: unknown }) {\n\t\tsuper();\n\t}\n\n\tpublic get metadata(): FileSystemMetadata {\n\t\treturn {\n\t\t\tname: this.constructor.name,\n\t\t\treadonly: false,\n\t\t\tsynchronous: false,\n\t\t\tsupportsProperties: false,\n\t\t\tsupportsLinks: false,\n\t\t\ttotalSpace: 0,\n\t\t\tfreeSpace: 0,\n\t\t};\n\t}\n\n\tpublic whenReady(): Promise<this> {\n\t\treturn this._ready;\n\t}\n\n\t/**\n\t * Opens the file at path p with the given flag. The file must exist.\n\t * @param p The path to open.\n\t * @param flag The flag to use when opening the file.\n\t */\n\tpublic async openFile(p: string, flag: FileFlag, cred: Cred): Promise<File> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\t/**\n\t * Create the file at path p with the given mode. Then, open it with the given\n\t * flag.\n\t */\n\tpublic async createFile(p: string, flag: FileFlag, mode: number, cred: Cred): Promise<File> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async open(p: string, flag: FileFlag, mode: number, cred: Cred): Promise<File> {\n\t\ttry {\n\t\t\tconst stats = await this.stat(p, cred);\n\t\t\tswitch (flag.pathExistsAction()) {\n\t\t\t\tcase ActionType.THROW_EXCEPTION:\n\t\t\t\t\tthrow ApiError.EEXIST(p);\n\t\t\t\tcase ActionType.TRUNCATE_FILE:\n\t\t\t\t\t// NOTE: In a previous implementation, we deleted the file and\n\t\t\t\t\t// re-created it. However, this created a race condition if another\n\t\t\t\t\t// asynchronous request was trying to read the file, as the file\n\t\t\t\t\t// would not exist for a small period of time.\n\t\t\t\t\tconst fd = await this.openFile(p, flag, cred);\n\t\t\t\t\tif (!fd) throw new Error('BFS has reached an impossible code path; please file a bug.');\n\n\t\t\t\t\tawait fd.truncate(0);\n\t\t\t\t\tawait fd.sync();\n\t\t\t\t\treturn fd;\n\t\t\t\tcase ActionType.NOP:\n\t\t\t\t\treturn this.openFile(p, flag, cred);\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');\n\t\t\t}\n\t\t\t// File exists.\n\t\t} catch (e) {\n\t\t\t// File does not exist.\n\t\t\tswitch (flag.pathNotExistsAction()) {\n\t\t\t\tcase ActionType.CREATE_FILE:\n\t\t\t\t\t// Ensure parent exists.\n\t\t\t\t\tconst parentStats = await this.stat(path.dirname(p), cred);\n\t\t\t\t\tif (parentStats && !parentStats.isDirectory()) {\n\t\t\t\t\t\tthrow ApiError.ENOTDIR(path.dirname(p));\n\t\t\t\t\t}\n\t\t\t\t\treturn this.createFile(p, flag, mode, cred);\n\t\t\t\tcase ActionType.THROW_EXCEPTION:\n\t\t\t\t\tthrow ApiError.ENOENT(p);\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');\n\t\t\t}\n\t\t}\n\t}\n\tpublic async access(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic accessSync(p: string, mode: number, cred: Cred): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async rename(oldPath: string, newPath: string, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic renameSync(oldPath: string, newPath: string, cred: Cred): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async stat(p: string, cred: Cred): Promise<Stats> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic statSync(p: string, cred: Cred): Stats {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\t/**\n\t * Opens the file at path p with the given flag. The file must exist.\n\t * @param p The path to open.\n\t * @param flag The flag to use when opening the file.\n\t * @return A File object corresponding to the opened file.\n\t */\n\tpublic openFileSync(p: string, flag: FileFlag, cred: Cred): File {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\t/**\n\t * Create the file at path p with the given mode. Then, open it with the given\n\t * flag.\n\t */\n\tpublic createFileSync(p: string, flag: FileFlag, mode: number, cred: Cred): File {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic openSync(p: string, flag: FileFlag, mode: number, cred: Cred): File {\n\t\t// Check if the path exists, and is a file.\n\t\tlet stats: Stats;\n\t\ttry {\n\t\t\tstats = this.statSync(p, cred);\n\t\t} catch (e) {\n\t\t\t// File does not exist.\n\t\t\tswitch (flag.pathNotExistsAction()) {\n\t\t\t\tcase ActionType.CREATE_FILE:\n\t\t\t\t\t// Ensure parent exists.\n\t\t\t\t\tconst parentStats = this.statSync(path.dirname(p), cred);\n\t\t\t\t\tif (!parentStats.isDirectory()) {\n\t\t\t\t\t\tthrow ApiError.ENOTDIR(path.dirname(p));\n\t\t\t\t\t}\n\t\t\t\t\treturn this.createFileSync(p, flag, mode, cred);\n\t\t\t\tcase ActionType.THROW_EXCEPTION:\n\t\t\t\t\tthrow ApiError.ENOENT(p);\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');\n\t\t\t}\n\t\t}\n\t\tif (!stats.hasAccess(mode, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\n\t\t// File exists.\n\t\tswitch (flag.pathExistsAction()) {\n\t\t\tcase ActionType.THROW_EXCEPTION:\n\t\t\t\tthrow ApiError.EEXIST(p);\n\t\t\tcase ActionType.TRUNCATE_FILE:\n\t\t\t\t// Delete file.\n\t\t\t\tthis.unlinkSync(p, cred);\n\t\t\t\t// Create file. Use the same mode as the old file.\n\t\t\t\t// Node itself modifies the ctime when this occurs, so this action\n\t\t\t\t// will preserve that behavior if the underlying file system\n\t\t\t\t// supports those properties.\n\t\t\t\treturn this.createFileSync(p, flag, stats.mode, cred);\n\t\t\tcase ActionType.NOP:\n\t\t\t\treturn this.openFileSync(p, flag, cred);\n\t\t\tdefault:\n\t\t\t\tthrow new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');\n\t\t}\n\t}\n\tpublic async unlink(p: string, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic unlinkSync(p: string, cred: Cred): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async rmdir(p: string, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic rmdirSync(p: string, cred: Cred): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async mkdir(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic mkdirSync(p: string, mode: number, cred: Cred): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async readdir(p: string, cred: Cred): Promise<string[]> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic readdirSync(p: string, cred: Cred): string[] {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async exists(p: string, cred: Cred): Promise<boolean> {\n\t\ttry {\n\t\t\tawait this.stat(p, cred);\n\t\t\treturn true;\n\t\t} catch (e) {\n\t\t\treturn false;\n\t\t}\n\t}\n\tpublic existsSync(p: string, cred: Cred): boolean {\n\t\ttry {\n\t\t\tthis.statSync(p, cred);\n\t\t\treturn true;\n\t\t} catch (e) {\n\t\t\treturn false;\n\t\t}\n\t}\n\tpublic async realpath(p: string, cred: Cred): Promise<string> {\n\t\tif (this.metadata.supportsLinks) {\n\t\t\t// The path could contain symlinks. Split up the path,\n\t\t\t// resolve any symlinks, return the resolved string.\n\t\t\tconst splitPath = p.split(path.sep);\n\t\t\t// TODO: Simpler to just pass through file, find sep and such.\n\t\t\tfor (let i = 0; i < splitPath.length; i++) {\n\t\t\t\tconst addPaths = splitPath.slice(0, i + 1);\n\t\t\t\tsplitPath[i] = path.join(...addPaths);\n\t\t\t}\n\t\t\treturn splitPath.join(path.sep);\n\t\t} else {\n\t\t\t// No symlinks. We just need to verify that it exists.\n\t\t\tif (!(await this.exists(p, cred))) {\n\t\t\t\tthrow ApiError.ENOENT(p);\n\t\t\t}\n\t\t\treturn p;\n\t\t}\n\t}\n\tpublic realpathSync(p: string, cred: Cred): string {\n\t\tif (this.metadata.supportsLinks) {\n\t\t\t// The path could contain symlinks. Split up the path,\n\t\t\t// resolve any symlinks, return the resolved string.\n\t\t\tconst splitPath = p.split(path.sep);\n\t\t\t// TODO: Simpler to just pass through file, find sep and such.\n\t\t\tfor (let i = 0; i < splitPath.length; i++) {\n\t\t\t\tconst addPaths = splitPath.slice(0, i + 1);\n\t\t\t\tsplitPath[i] = path.join(...addPaths);\n\t\t\t}\n\t\t\treturn splitPath.join(path.sep);\n\t\t} else {\n\t\t\t// No symlinks. We just need to verify that it exists.\n\t\t\tif (this.existsSync(p, cred)) {\n\t\t\t\treturn p;\n\t\t\t} else {\n\t\t\t\tthrow ApiError.ENOENT(p);\n\t\t\t}\n\t\t}\n\t}\n\tpublic async truncate(p: string, len: number, cred: Cred): Promise<void> {\n\t\tconst fd = await this.open(p, FileFlag.getFileFlag('r+'), 0o644, cred);\n\t\ttry {\n\t\t\tawait fd.truncate(len);\n\t\t} finally {\n\t\t\tawait fd.close();\n\t\t}\n\t}\n\tpublic truncateSync(p: string, len: number, cred: Cred): void {\n\t\tconst fd = this.openSync(p, FileFlag.getFileFlag('r+'), 0o644, cred);\n\t\t// Need to safely close FD, regardless of whether or not truncate succeeds.\n\t\ttry {\n\t\t\tfd.truncateSync(len);\n\t\t} finally {\n\t\t\tfd.closeSync();\n\t\t}\n\t}\n\tpublic async readFile(fname: string, encoding: BufferEncoding | null, flag: FileFlag, cred: Cred): Promise<FileContents> {\n\t\t// Get file.\n\t\tconst fd = await this.open(fname, flag, 0o644, cred);\n\t\ttry {\n\t\t\tconst stat = await fd.stat();\n\t\t\t// Allocate buffer.\n\t\t\tconst buf = Buffer.alloc(stat.size);\n\t\t\tawait fd.read(buf, 0, stat.size, 0);\n\t\t\tawait fd.close();\n\t\t\tif (encoding === null) {\n\t\t\t\treturn buf;\n\t\t\t}\n\t\t\treturn buf.toString(encoding);\n\t\t} finally {\n\t\t\tawait fd.close();\n\t\t}\n\t}\n\tpublic readFileSync(fname: string, encoding: BufferEncoding | null, flag: FileFlag, cred: Cred): FileContents {\n\t\t// Get file.\n\t\tconst fd = this.openSync(fname, flag, 0o644, cred);\n\t\ttry {\n\t\t\tconst stat = fd.statSync();\n\t\t\t// Allocate buffer.\n\t\t\tconst buf = Buffer.alloc(stat.size);\n\t\t\tfd.readSync(buf, 0, stat.size, 0);\n\t\t\tfd.closeSync();\n\t\t\tif (encoding === null) {\n\t\t\t\treturn buf;\n\t\t\t}\n\t\t\treturn buf.toString(encoding);\n\t\t} finally {\n\t\t\tfd.closeSync();\n\t\t}\n\t}\n\tpublic async writeFile(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): Promise<void> {\n\t\t// Get file.\n\t\tconst fd = await this.open(fname, flag, mode, cred);\n\t\ttry {\n\t\t\tif (typeof data === 'string') {\n\t\t\t\tdata = Buffer.from(data, encoding!);\n\t\t\t}\n\t\t\t// Write into file.\n\t\t\tawait fd.write(data, 0, data.length, 0);\n\t\t} finally {\n\t\t\tawait fd.close();\n\t\t}\n\t}\n\tpublic writeFileSync(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): void {\n\t\t// Get file.\n\t\tconst fd = this.openSync(fname, flag, mode, cred);\n\t\ttry {\n\t\t\tif (typeof data === 'string') {\n\t\t\t\tdata = Buffer.from(data, encoding!);\n\t\t\t}\n\t\t\t// Write into file.\n\t\t\tfd.writeSync(data, 0, data.length, 0);\n\t\t} finally {\n\t\t\tfd.closeSync();\n\t\t}\n\t}\n\tpublic async appendFile(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): Promise<void> {\n\t\tconst fd = await this.open(fname, flag, mode, cred);\n\t\ttry {\n\t\t\tif (typeof data === 'string') {\n\t\t\t\tdata = Buffer.from(data, encoding!);\n\t\t\t}\n\t\t\tawait fd.write(data, 0, data.length, null);\n\t\t} finally {\n\t\t\tawait fd.close();\n\t\t}\n\t}\n\tpublic appendFileSync(fname: string, data: FileContents, encoding: BufferEncoding | null, flag: FileFlag, mode: number, cred: Cred): void {\n\t\tconst fd = this.openSync(fname, flag, mode, cred);\n\t\ttry {\n\t\t\tif (typeof data === 'string') {\n\t\t\t\tdata = Buffer.from(data, encoding!);\n\t\t\t}\n\t\t\tfd.writeSync(data, 0, data.length, null);\n\t\t} finally {\n\t\t\tfd.closeSync();\n\t\t}\n\t}\n\tpublic async chmod(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic chmodSync(p: string, mode: number, cred: Cred) {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async chown(p: string, new_uid: number, new_gid: number, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic chownSync(p: string, new_uid: number, new_gid: number, cred: Cred): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async utimes(p: string, atime: Date, mtime: Date, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic utimesSync(p: string, atime: Date, mtime: Date, cred: Cred): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async link(srcpath: string, dstpath: string, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic linkSync(srcpath: string, dstpath: string, cred: Cred): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async symlink(srcpath: string, dstpath: string, type: string, cred: Cred): Promise<void> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic symlinkSync(srcpath: string, dstpath: string, type: string, cred: Cred): void {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic async readlink(p: string, cred: Cred): Promise<string> {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n\tpublic readlinkSync(p: string, cred: Cred): string {\n\t\tthrow new ApiError(ErrorCode.ENOTSUP);\n\t}\n}\n\n/**\n * Implements the asynchronous API in terms of the synchronous API.\n */\nexport class SynchronousFileSystem extends BaseFileSystem {\n\tpublic get metadata(): FileSystemMetadata {\n\t\treturn { ...super.metadata, synchronous: true };\n\t}\n\n\tpublic async access(p: string, mode: number, cred: Cred): Promise<void> {\n\t\treturn this.accessSync(p, mode, cred);\n\t}\n\n\tpublic async rename(oldPath: string, newPath: string, cred: Cred): Promise<void> {\n\t\treturn this.renameSync(oldPath, newPath, cred);\n\t}\n\n\tpublic async stat(p: string | null, cred: Cred): Promise<Stats> {\n\t\treturn this.statSync(p, cred);\n\t}\n\n\tpublic async open(p: string, flags: FileFlag, mode: number, cred: Cred): Promise<File> {\n\t\treturn this.openSync(p, flags, mode, cred);\n\t}\n\n\tpublic async unlink(p: string, cred: Cred): Promise<void> {\n\t\treturn this.unlinkSync(p, cred);\n\t}\n\n\tpublic async rmdir(p: string, cred: Cred): Promise<void> {\n\t\treturn this.rmdirSync(p, cred);\n\t}\n\n\tpublic async mkdir(p: string, mode: number, cred: Cred): Promise<void> {\n\t\treturn this.mkdirSync(p, mode, cred);\n\t}\n\n\tpublic async readdir(p: string, cred: Cred): Promise<string[]> {\n\t\treturn this.readdirSync(p, cred);\n\t}\n\n\tpublic async chmod(p: string, mode: number, cred: Cred): Promise<void> {\n\t\treturn this.chmodSync(p, mode, cred);\n\t}\n\n\tpublic async chown(p: string, new_uid: number, new_gid: number, cred: Cred): Promise<void> {\n\t\treturn this.chownSync(p, new_uid, new_gid, cred);\n\t}\n\n\tpublic async utimes(p: string, atime: Date, mtime: Date, cred: Cred): Promise<void> {\n\t\treturn this.utimesSync(p, atime, mtime, cred);\n\t}\n\n\tpublic async link(srcpath: string, dstpath: string, cred: Cred): Promise<void> {\n\t\treturn this.linkSync(srcpath, dstpath, cred);\n\t}\n\n\tpublic async symlink(srcpath: string, dstpath: string, type: string, cred: Cred): Promise<void> {\n\t\treturn this.symlinkSync(srcpath, dstpath, type, cred);\n\t}\n\n\tpublic async readlink(p: string, cred: Cred): Promise<string> {\n\t\treturn this.readlinkSync(p, cred);\n\t}\n}\n", "import { Stats, FileType } from './stats.js';\nimport { Buffer } from 'buffer';\n\n/**\n * Generic inode definition that can easily be serialized.\n */\nexport default class Inode {\n\t/**\n\t * Converts the buffer into an Inode.\n\t */\n\tpublic static fromBuffer(buffer: Buffer): Inode {\n\t\tif (buffer === undefined) {\n\t\t\tthrow new Error('NO');\n\t\t}\n\t\treturn new Inode(\n\t\t\tbuffer.toString('ascii', 38),\n\t\t\tbuffer.readUInt32LE(0),\n\t\t\tbuffer.readUInt16LE(4),\n\t\t\tbuffer.readDoubleLE(6),\n\t\t\tbuffer.readDoubleLE(14),\n\t\t\tbuffer.readDoubleLE(22),\n\t\t\tbuffer.readUInt32LE(30),\n\t\t\tbuffer.readUInt32LE(34)\n\t\t);\n\t}\n\n\tconstructor(\n\t\tpublic id: string,\n\t\tpublic size: number,\n\t\tpublic mode: number,\n\t\tpublic atime: number,\n\t\tpublic mtime: number,\n\t\tpublic ctime: number,\n\t\tpublic uid: number,\n\t\tpublic gid: number\n\t) {}\n\n\t/**\n\t * Handy function that converts the Inode to a Node Stats object.\n\t */\n\tpublic toStats(): Stats {\n\t\treturn new Stats(\n\t\t\t(this.mode & 0xf000) === FileType.DIRECTORY ? FileType.DIRECTORY : FileType.FILE,\n\t\t\tthis.size,\n\t\t\tthis.mode,\n\t\t\tthis.atime,\n\t\t\tthis.mtime,\n\t\t\tthis.ctime,\n\t\t\tthis.uid,\n\t\t\tthis.gid\n\t\t);\n\t}\n\n\t/**\n\t * Get the size of this Inode, in bytes.\n\t */\n\tpublic getSize(): number {\n\t\t// ASSUMPTION: ID is ASCII (1 byte per char).\n\t\treturn 38 + this.id.length;\n\t}\n\n\t/**\n\t * Writes the inode into the start of the buffer.\n\t */\n\tpublic toBuffer(buff: Buffer = Buffer.alloc(this.getSize())): Buffer {\n\t\tbuff.writeUInt32LE(this.size, 0);\n\t\tbuff.writeUInt16LE(this.mode, 4);\n\t\tbuff.writeDoubleLE(this.atime, 6);\n\t\tbuff.writeDoubleLE(this.mtime, 14);\n\t\tbuff.writeDoubleLE(this.ctime, 22);\n\t\tbuff.writeUInt32LE(this.uid, 30);\n\t\tbuff.writeUInt32LE(this.gid, 34);\n\t\tbuff.write(this.id, 38, this.id.length, 'ascii');\n\t\treturn buff;\n\t}\n\n\t/**\n\t * Updates the Inode using information from the stats object. Used by file\n\t * systems at sync time, e.g.:\n\t * - Program opens file and gets a File object.\n\t * - Program mutates file. File object is responsible for maintaining\n\t * metadata changes locally -- typically in a Stats object.\n\t * - Program closes file. File object's metadata changes are synced with the\n\t * file system.\n\t * @return True if any changes have occurred.\n\t */\n\tpublic update(stats: Stats): boolean {\n\t\tlet hasChanged = false;\n\t\tif (this.size !== stats.size) {\n\t\t\tthis.size = stats.size;\n\t\t\thasChanged = true;\n\t\t}\n\n\t\tif (this.mode !== stats.mode) {\n\t\t\tthis.mode = stats.mode;\n\t\t\thasChanged = true;\n\t\t}\n\n\t\tconst atimeMs = stats.atime.getTime();\n\t\tif (this.atime !== atimeMs) {\n\t\t\tthis.atime = atimeMs;\n\t\t\thasChanged = true;\n\t\t}\n\n\t\tconst mtimeMs = stats.mtime.getTime();\n\t\tif (this.mtime !== mtimeMs) {\n\t\t\tthis.mtime = mtimeMs;\n\t\t\thasChanged = true;\n\t\t}\n\n\t\tconst ctimeMs = stats.ctime.getTime();\n\t\tif (this.ctime !== ctimeMs) {\n\t\t\tthis.ctime = ctimeMs;\n\t\t\thasChanged = true;\n\t\t}\n\n\t\tif (this.uid !== stats.uid) {\n\t\t\tthis.uid = stats.uid;\n\t\t\thasChanged = true;\n\t\t}\n\n\t\tif (this.uid !== stats.uid) {\n\t\t\tthis.uid = stats.uid;\n\t\t\thasChanged = true;\n\t\t}\n\n\t\treturn hasChanged;\n\t}\n\n\t// XXX: Copied from Stats. Should reconcile these two into something more\n\t// compact.\n\n\t/**\n\t * @return [Boolean] True if this item is a file.\n\t */\n\tpublic isFile(): boolean {\n\t\treturn (this.mode & 0xf000) === FileType.FILE;\n\t}\n\n\t/**\n\t * @return [Boolean] True if this item is a directory.\n\t */\n\tpublic isDirectory(): boolean {\n\t\treturn (this.mode & 0xf000) === FileType.DIRECTORY;\n\t}\n}\n", "/**\n * Grab bag of utility functions used across the code.\n */\nimport { FileSystem } from './filesystem.js';\nimport { ErrorCode, ApiError } from './ApiError.js';\nimport * as path from 'path';\nimport { Cred } from './cred.js';\nimport { Buffer } from 'buffer';\nimport type { BaseBackendConstructor } from './backends/backend.js';\n\n/**\n * Synchronous recursive makedir.\n * @internal\n */\nexport function mkdirpSync(p: string, mode: number, cred: Cred, fs: FileSystem): void {\n\tif (!fs.existsSync(p, cred)) {\n\t\tmkdirpSync(path.dirname(p), mode, cred, fs);\n\t\tfs.mkdirSync(p, mode, cred);\n\t}\n}\n\n/**\n * Copies a slice of the given buffer\n * @internal\n */\nexport function copyingSlice(buff: Buffer, start: number = 0, end = buff.length): Buffer {\n\tif (start < 0 || end < 0 || end > buff.length || start > end) {\n\t\tthrow new TypeError(`Invalid slice bounds on buffer of length ${buff.length}: [${start}, ${end}]`);\n\t}\n\tif (buff.length === 0) {\n\t\t// Avoid s0 corner case in ArrayBuffer case.\n\t\treturn Buffer.alloc(0);\n\t} else {\n\t\treturn buff.subarray(start, end);\n\t}\n}\n\n/**\n * Option validator for a Buffer file system option.\n * @internal\n */\nexport async function bufferValidator(v: object): Promise<void> {\n\tif (!Buffer.isBuffer(v)) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'option must be a Buffer.');\n\t}\n}\n\n/*\n * Levenshtein distance, from the `js-levenshtein` NPM module.\n * Copied here to avoid complexity of adding another CommonJS module dependency.\n */\n\nfunction _min(d0: number, d1: number, d2: number, bx: number, ay: number): number {\n\treturn Math.min(d0 + 1, d1 + 1, d2 + 1, bx === ay ? d1 : d1 + 1);\n}\n\n/**\n * Calculates levenshtein distance.\n * @param a\n * @param b\n */\nfunction levenshtein(a: string, b: string): number {\n\tif (a === b) {\n\t\treturn 0;\n\t}\n\n\tif (a.length > b.length) {\n\t\t[a, b] = [b, a]; // Swap a and b\n\t}\n\n\tlet la = a.length;\n\tlet lb = b.length;\n\n\t// Trim common suffix\n\twhile (la > 0 && a.charCodeAt(la - 1) === b.charCodeAt(lb - 1)) {\n\t\tla--;\n\t\tlb--;\n\t}\n\n\tlet offset = 0;\n\n\t// Trim common prefix\n\twhile (offset < la && a.charCodeAt(offset) === b.charCodeAt(offset)) {\n\t\toffset++;\n\t}\n\n\tla -= offset;\n\tlb -= offset;\n\n\tif (la === 0 || lb === 1) {\n\t\treturn lb;\n\t}\n\n\tconst vector = new Array<number>(la << 1);\n\n\tfor (let y = 0; y < la; ) {\n\t\tvector[la + y] = a.charCodeAt(offset + y);\n\t\tvector[y] = ++y;\n\t}\n\n\tlet x: number;\n\tlet d0: number;\n\tlet d1: number;\n\tlet d2: number;\n\tlet d3: number;\n\tfor (x = 0; x + 3 < lb; ) {\n\t\tconst bx0 = b.charCodeAt(offset + (d0 = x));\n\t\tconst bx1 = b.charCodeAt(offset + (d1 = x + 1));\n\t\tconst bx2 = b.charCodeAt(offset + (d2 = x + 2));\n\t\tconst bx3 = b.charCodeAt(offset + (d3 = x + 3));\n\t\tlet dd = (x += 4);\n\t\tfor (let y = 0; y < la; ) {\n\t\t\tconst ay = vector[la + y];\n\t\t\tconst dy = vector[y];\n\t\t\td0 = _min(dy, d0, d1, bx0, ay);\n\t\t\td1 = _min(d0, d1, d2, bx1, ay);\n\t\t\td2 = _min(d1, d2, d3, bx2, ay);\n\t\t\tdd = _min(d2, d3, dd, bx3, ay);\n\t\t\tvector[y++] = dd;\n\t\t\td3 = d2;\n\t\t\td2 = d1;\n\t\t\td1 = d0;\n\t\t\td0 = dy;\n\t\t}\n\t}\n\n\tlet dd: number = 0;\n\tfor (; x < lb; ) {\n\t\tconst bx0 = b.charCodeAt(offset + (d0 = x));\n\t\tdd = ++x;\n\t\tfor (let y = 0; y < la; y++) {\n\t\t\tconst dy = vector[y];\n\t\t\tvector[y] = dd = dy < d0 || dd < d0 ? (dy > dd ? dd + 1 : dy + 1) : bx0 === vector[la + y] ? d0 : d0 + 1;\n\t\t\td0 = dy;\n\t\t}\n\t}\n\n\treturn dd;\n}\n\n/**\n * Checks that the given options object is valid for the file system options.\n * @internal\n */\nexport async function checkOptions(backend: BaseBackendConstructor, opts: object): Promise<void> {\n\tconst optsInfo = backend.Options;\n\tconst fsName = backend.Name;\n\n\tlet pendingValidators = 0;\n\tlet callbackCalled = false;\n\tlet loopEnded = false;\n\n\t// Check for required options.\n\tfor (const optName in optsInfo) {\n\t\tif (Object.prototype.hasOwnProperty.call(optsInfo, optName)) {\n\t\t\tconst opt = optsInfo[optName];\n\t\t\tconst providedValue = opts && opts[optName];\n\n\t\t\tif (providedValue === undefined || providedValue === null) {\n\t\t\t\tif (!opt.optional) {\n\t\t\t\t\t// Required option, not provided.\n\t\t\t\t\t// Any incorrect options provided? Which ones are close to the provided one?\n\t\t\t\t\t// (edit distance 5 === close)\n\t\t\t\t\tconst incorrectOptions = Object.keys(opts)\n\t\t\t\t\t\t.filter(o => !(o in optsInfo))\n\t\t\t\t\t\t.map((a: string) => {\n\t\t\t\t\t\t\treturn { str: a, distance: levenshtein(optName, a) };\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.filter(o => o.distance < 5)\n\t\t\t\t\t\t.sort((a, b) => a.distance - b.distance);\n\t\t\t\t\t// Validators may be synchronous.\n\t\t\t\t\tif (callbackCalled) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcallbackCalled = true;\n\t\t\t\t\tthrow new ApiError(\n\t\t\t\t\t\tErrorCode.EINVAL,\n\t\t\t\t\t\t`[${fsName}] Required option '${optName}' not provided.${\n\t\t\t\t\t\t\tincorrectOptions.length > 0 ? ` You provided unrecognized option '${incorrectOptions[0].str}'; perhaps you meant to type '${optName}'.` : ''\n\t\t\t\t\t\t}\\nOption description: ${opt.description}`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// Else: Optional option, not provided. That is OK.\n\t\t\t} else {\n\t\t\t\t// Option provided! Check type.\n\t\t\t\tlet typeMatches = false;\n\t\t\t\tif (Array.isArray(opt.type)) {\n\t\t\t\t\ttypeMatches = opt.type.indexOf(typeof providedValue) !== -1;\n\t\t\t\t} else {\n\t\t\t\t\ttypeMatches = typeof providedValue === opt.type;\n\t\t\t\t}\n\t\t\t\tif (!typeMatches) {\n\t\t\t\t\t// Validators may be synchronous.\n\t\t\t\t\tif (callbackCalled) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcallbackCalled = true;\n\t\t\t\t\tthrow new ApiError(\n\t\t\t\t\t\tErrorCode.EINVAL,\n\t\t\t\t\t\t`[${fsName}] Value provided for option ${optName} is not the proper type. Expected ${\n\t\t\t\t\t\t\tArray.isArray(opt.type) ? `one of {${opt.type.join(', ')}}` : opt.type\n\t\t\t\t\t\t}, but received ${typeof providedValue}\\nOption description: ${opt.description}`\n\t\t\t\t\t);\n\t\t\t\t} else if (opt.validator) {\n\t\t\t\t\tpendingValidators++;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait opt.validator(providedValue);\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tif (!callbackCalled) {\n\t\t\t\t\t\t\tif (e) {\n\t\t\t\t\t\t\t\tcallbackCalled = true;\n\t\t\t\t\t\t\t\tthrow e;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tpendingValidators--;\n\t\t\t\t\t\t\tif (pendingValidators === 0 && loopEnded) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Otherwise: All good!\n\t\t\t}\n\t\t}\n\t}\n\tloopEnded = true;\n\tif (pendingValidators === 0 && !callbackCalled) {\n\t\treturn;\n\t}\n}\n\n/** Waits n ms. */\nexport function wait(ms: number): Promise<void> {\n\treturn new Promise(resolve => {\n\t\tsetTimeout(resolve, ms);\n\t});\n}\n\n/**\n * Converts a callback into a promise. Assumes last parameter is the callback\n * @todo Look at changing resolve value from cbArgs[0] to include other callback arguments?\n */\nexport function toPromise(fn: (...fnArgs: unknown[]) => unknown) {\n\treturn function (...args: unknown[]): Promise<unknown> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\targs.push((e: ApiError, ...cbArgs: unknown[]) => {\n\t\t\t\tif (e) {\n\t\t\t\t\treject(e);\n\t\t\t\t} else {\n\t\t\t\t\tresolve(cbArgs[0]);\n\t\t\t\t}\n\t\t\t});\n\t\t\tfn(...args);\n\t\t});\n\t};\n}\n\n/**\n * @internal\n */\nexport const setImmediate = typeof globalThis.setImmediate == 'function' ? globalThis.setImmediate : cb => setTimeout(cb, 0);\n\n/**\n * @internal\n */\nexport const ROOT_NODE_ID: string = '/';\n\n/**\n * Returns an empty directory node.\n * @internal\n */\nexport function getEmptyDirNode(): Buffer {\n\treturn Buffer.from('{}');\n}\n\n/**\n * Generates a random ID.\n * @internal\n */\nexport function randomUUID(): string {\n\t// From http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript\n\treturn 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {\n\t\tconst r = (Math.random() * 16) | 0;\n\t\tconst v = c === 'x' ? r : (r & 0x3) | 0x8;\n\t\treturn v.toString(16);\n\t});\n}\n", "import * as path from 'path';\nimport { ApiError, ErrorCode } from '../ApiError.js';\nimport { Cred } from '../cred.js';\nimport { W_OK, R_OK } from '../emulation/constants.js';\nimport { File, FileFlag, PreloadFile } from '../file.js';\nimport { SynchronousFileSystem } from '../filesystem.js';\nimport Inode from '../inode.js';\nimport { Stats, FileType } from '../stats.js';\nimport { randomUUID, getEmptyDirNode, ROOT_NODE_ID } from '../utils.js';\n\n/**\n * Represents a *synchronous* key-value store.\n */\nexport interface SyncKeyValueStore {\n\t/**\n\t * The name of the key-value store.\n\t */\n\tname(): string;\n\t/**\n\t * Empties the key-value store completely.\n\t */\n\tclear(): void;\n\t/**\n\t * Begins a new read-only transaction.\n\t */\n\tbeginTransaction(type: 'readonly'): SyncKeyValueROTransaction;\n\t/**\n\t * Begins a new read-write transaction.\n\t */\n\tbeginTransaction(type: 'readwrite'): SyncKeyValueRWTransaction;\n\tbeginTransaction(type: string): SyncKeyValueROTransaction;\n}\n\n/**\n * A read-only transaction for a synchronous key value store.\n */\nexport interface SyncKeyValueROTransaction {\n\t/**\n\t * Retrieves the data at the given key. Throws an ApiError if an error occurs\n\t * or if the key does not exist.\n\t * @param key The key to look under for data.\n\t * @return The data stored under the key, or undefined if not present.\n\t */\n\tget(key: string): Buffer | undefined;\n}\n\n/**\n * A read-write transaction for a synchronous key value store.\n */\nexport interface SyncKeyValueRWTransaction extends SyncKeyValueROTransaction {\n\t/**\n\t * Adds the data to the store under the given key.\n\t * @param key The key to add the data under.\n\t * @param data The data to add to the store.\n\t * @param overwrite If 'true', overwrite any existing data. If 'false',\n\t * avoids storing the data if the key exists.\n\t * @return True if storage succeeded, false otherwise.\n\t */\n\tput(key: string, data: Buffer, overwrite: boolean): boolean;\n\t/**\n\t * Deletes the data at the given key.\n\t * @param key The key to delete from the store.\n\t */\n\tdel(key: string): void;\n\t/**\n\t * Commits the transaction.\n\t */\n\tcommit(): void;\n\t/**\n\t * Aborts and rolls back the transaction.\n\t */\n\tabort(): void;\n}\n\n/**\n * An interface for simple synchronous key-value stores that don't have special\n * support for transactions and such.\n */\nexport interface SimpleSyncStore {\n\tget(key: string): Buffer | undefined;\n\tput(key: string, data: Buffer, overwrite: boolean): boolean;\n\tdel(key: string): void;\n}\n\n/**\n * A simple RW transaction for simple synchronous key-value stores.\n */\nexport class SimpleSyncRWTransaction implements SyncKeyValueRWTransaction {\n\t/**\n\t * Stores data in the keys we modify prior to modifying them.\n\t * Allows us to roll back commits.\n\t */\n\tprivate originalData: { [key: string]: Buffer | undefined } = {};\n\t/**\n\t * List of keys modified in this transaction, if any.\n\t */\n\tprivate modifiedKeys: string[] = [];\n\n\tconstructor(private store: SimpleSyncStore) {}\n\n\tpublic get(key: string): Buffer | undefined {\n\t\tconst val = this.store.get(key);\n\t\tthis.stashOldValue(key, val);\n\t\treturn val;\n\t}\n\n\tpublic put(key: string, data: Buffer, overwrite: boolean): boolean {\n\t\tthis.markModified(key);\n\t\treturn this.store.put(key, data, overwrite);\n\t}\n\n\tpublic del(key: string): void {\n\t\tthis.markModified(key);\n\t\tthis.store.del(key);\n\t}\n\n\tpublic commit(): void {\n\t\t/* NOP */\n\t}\n\n\tpublic abort(): void {\n\t\t// Rollback old values.\n\t\tfor (const key of this.modifiedKeys) {\n\t\t\tconst value = this.originalData[key];\n\t\t\tif (!value) {\n\t\t\t\t// Key didn't exist.\n\t\t\t\tthis.store.del(key);\n\t\t\t} else {\n\t\t\t\t// Key existed. Store old value.\n\t\t\t\tthis.store.put(key, value, true);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate _has(key: string) {\n\t\treturn Object.prototype.hasOwnProperty.call(this.originalData, key);\n\t}\n\n\t/**\n\t * Stashes given key value pair into `originalData` if it doesn't already\n\t * exist. Allows us to stash values the program is requesting anyway to\n\t * prevent needless `get` requests if the program modifies the data later\n\t * on during the transaction.\n\t */\n\tprivate stashOldValue(key: string, value: Buffer | undefined) {\n\t\t// Keep only the earliest value in the transaction.\n\t\tif (!this._has(key)) {\n\t\t\tthis.originalData[key] = value;\n\t\t}\n\t}\n\n\t/**\n\t * Marks the given key as modified, and stashes its value if it has not been\n\t * stashed already.\n\t */\n\tprivate markModified(key: string) {\n\t\tif (this.modifiedKeys.indexOf(key) === -1) {\n\t\t\tthis.modifiedKeys.push(key);\n\t\t\tif (!this._has(key)) {\n\t\t\t\tthis.originalData[key] = this.store.get(key);\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport interface SyncKeyValueFileSystemOptions {\n\t/**\n\t * The actual key-value store to read from/write to.\n\t */\n\tstore: SyncKeyValueStore;\n\t/**\n\t * Should the file system support properties (mtime/atime/ctime/chmod/etc)?\n\t * Enabling this slightly increases the storage space per file, and adds\n\t * atime updates every time a file is accessed, mtime updates every time\n\t * a file is modified, and permission checks on every operation.\n\t *\n\t * Defaults to *false*.\n\t */\n\tsupportProps?: boolean;\n\t/**\n\t * Should the file system support links?\n\t */\n\tsupportLinks?: boolean;\n}\n\nexport class SyncKeyValueFile extends PreloadFile<SyncKeyValueFileSystem> implements File {\n\tconstructor(_fs: SyncKeyValueFileSystem, _path: string, _flag: FileFlag, _stat: Stats, contents?: Buffer) {\n\t\tsuper(_fs, _path, _flag, _stat, contents);\n\t}\n\n\tpublic syncSync(): void {\n\t\tif (this.isDirty()) {\n\t\t\tthis._fs._syncSync(this.getPath(), this.getBuffer(), this.getStats());\n\t\t\tthis.resetDirty();\n\t\t}\n\t}\n\n\tpublic closeSync(): void {\n\t\tthis.syncSync();\n\t}\n}\n\n/**\n * A \"Synchronous key-value file system\". Stores data to/retrieves data from an\n * underlying key-value store.\n *\n * We use a unique ID for each node in the file system. The root node has a\n * fixed ID.\n * @todo Introduce Node ID caching.\n * @todo Check modes.\n */\nexport class SyncKeyValueFileSystem extends SynchronousFileSystem {\n\tpublic static isAvailable(): boolean {\n\t\treturn true;\n\t}\n\n\tprivate store: SyncKeyValueStore;\n\n\tconstructor(options: SyncKeyValueFileSystemOptions) {\n\t\tsuper();\n\t\tthis.store = options.store;\n\t\t// INVARIANT: Ensure that the root exists.\n\t\tthis.makeRootDirectory();\n\t}\n\n\tpublic getName(): string {\n\t\treturn this.store.name();\n\t}\n\tpublic isReadOnly(): boolean {\n\t\treturn false;\n\t}\n\tpublic supportsSymlinks(): boolean {\n\t\treturn false;\n\t}\n\tpublic supportsProps(): boolean {\n\t\treturn true;\n\t}\n\tpublic supportsSynch(): boolean {\n\t\treturn true;\n\t}\n\n\t/**\n\t * Delete all contents stored in the file system.\n\t */\n\tpublic empty(): void {\n\t\tthis.store.clear();\n\t\t// INVARIANT: Root always exists.\n\t\tthis.makeRootDirectory();\n\t}\n\n\tpublic accessSync(p: string, mode: number, cred: Cred): void {\n\t\tconst tx = this.store.beginTransaction('readonly'),\n\t\t\tnode = this.findINode(tx, p);\n\t\tif (!node.toStats().hasAccess(mode, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\t}\n\n\tpublic renameSync(oldPath: string, newPath: string, cred: Cred): void {\n\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\toldParent = path.dirname(oldPath),\n\t\t\toldName = path.basename(oldPath),\n\t\t\tnewParent = path.dirname(newPath),\n\t\t\tnewName = path.basename(newPath),\n\t\t\t// Remove oldPath from parent's directory listing.\n\t\t\toldDirNode = this.findINode(tx, oldParent),\n\t\t\toldDirList = this.getDirListing(tx, oldParent, oldDirNode);\n\n\t\tif (!oldDirNode.toStats().hasAccess(W_OK, cred)) {\n\t\t\tthrow ApiError.EACCES(oldPath);\n\t\t}\n\n\t\tif (!oldDirList[oldName]) {\n\t\t\tthrow ApiError.ENOENT(oldPath);\n\t\t}\n\t\tconst nodeId: string = oldDirList[oldName];\n\t\tdelete oldDirList[oldName];\n\n\t\t// Invariant: Can't move a folder inside itself.\n\t\t// This funny little hack ensures that the check passes only if oldPath\n\t\t// is a subpath of newParent. We append '/' to avoid matching folders that\n\t\t// are a substring of the bottom-most folder in the path.\n\t\tif ((newParent + '/').indexOf(oldPath + '/') === 0) {\n\t\t\tthrow new ApiError(ErrorCode.EBUSY, oldParent);\n\t\t}\n\n\t\t// Add newPath to parent's directory listing.\n\t\tlet newDirNode: Inode, newDirList: typeof oldDirList;\n\t\tif (newParent === oldParent) {\n\t\t\t// Prevent us from re-grabbing the same directory listing, which still\n\t\t\t// contains oldName.\n\t\t\tnewDirNode = oldDirNode;\n\t\t\tnewDirList = oldDirList;\n\t\t} else {\n\t\t\tnewDirNode = this.findINode(tx, newParent);\n\t\t\tnewDirList = this.getDirListing(tx, newParent, newDirNode);\n\t\t}\n\n\t\tif (newDirList[newName]) {\n\t\t\t// If it's a file, delete it.\n\t\t\tconst newNameNode = this.getINode(tx, newPath, newDirList[newName]);\n\t\t\tif (newNameNode.isFile()) {\n\t\t\t\ttry {\n\t\t\t\t\ttx.del(newNameNode.id);\n\t\t\t\t\ttx.del(newDirList[newName]);\n\t\t\t\t} catch (e) {\n\t\t\t\t\ttx.abort();\n\t\t\t\t\tthrow e;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// If it's a directory, throw a permissions error.\n\t\t\t\tthrow ApiError.EPERM(newPath);\n\t\t\t}\n\t\t}\n\t\tnewDirList[newName] = nodeId;\n\n\t\t// Commit the two changed directory listings.\n\t\ttry {\n\t\t\ttx.put(oldDirNode.id, Buffer.from(JSON.stringify(oldDirList)), true);\n\t\t\ttx.put(newDirNode.id, Buffer.from(JSON.stringify(newDirList)), true);\n\t\t} catch (e) {\n\t\t\ttx.abort();\n\t\t\tthrow e;\n\t\t}\n\n\t\ttx.commit();\n\t}\n\n\tpublic statSync(p: string, cred: Cred): Stats {\n\t\t// Get the inode to the item, convert it into a Stats object.\n\t\tconst stats = this.findINode(this.store.beginTransaction('readonly'), p).toStats();\n\t\tif (!stats.hasAccess(R_OK, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\t\treturn stats;\n\t}\n\n\tpublic createFileSync(p: string, flag: FileFlag, mode: number, cred: Cred): File {\n\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\tdata = Buffer.alloc(0),\n\t\t\tnewFile = this.commitNewFile(tx, p, FileType.FILE, mode, cred, data);\n\t\t// Open the file.\n\t\treturn new SyncKeyValueFile(this, p, flag, newFile.toStats(), data);\n\t}\n\n\tpublic openFileSync(p: string, flag: FileFlag, cred: Cred): File {\n\t\tconst tx = this.store.beginTransaction('readonly'),\n\t\t\tnode = this.findINode(tx, p),\n\t\t\tdata = tx.get(node.id);\n\t\tif (!node.toStats().hasAccess(flag.getMode(), cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\t\tif (data === undefined) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t\treturn new SyncKeyValueFile(this, p, flag, node.toStats(), data);\n\t}\n\n\tpublic unlinkSync(p: string, cred: Cred): void {\n\t\tthis.removeEntry(p, false, cred);\n\t}\n\n\tpublic rmdirSync(p: string, cred: Cred): void {\n\t\t// Check first if directory is empty.\n\t\tif (this.readdirSync(p, cred).length > 0) {\n\t\t\tthrow ApiError.ENOTEMPTY(p);\n\t\t} else {\n\t\t\tthis.removeEntry(p, true, cred);\n\t\t}\n\t}\n\n\tpublic mkdirSync(p: string, mode: number, cred: Cred): void {\n\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\tdata = Buffer.from('{}');\n\t\tthis.commitNewFile(tx, p, FileType.DIRECTORY, mode, cred, data);\n\t}\n\n\tpublic readdirSync(p: string, cred: Cred): string[] {\n\t\tconst tx = this.store.beginTransaction('readonly');\n\t\tconst node = this.findINode(tx, p);\n\t\tif (!node.toStats().hasAccess(R_OK, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\t\treturn Object.keys(this.getDirListing(tx, p, node));\n\t}\n\n\tpublic chmodSync(p: string, mode: number, cred: Cred): void {\n\t\tconst fd = this.openFileSync(p, FileFlag.getFileFlag('r+'), cred);\n\t\tfd.chmodSync(mode);\n\t}\n\n\tpublic chownSync(p: string, new_uid: number, new_gid: number, cred: Cred): void {\n\t\tconst fd = this.openFileSync(p, FileFlag.getFileFlag('r+'), cred);\n\t\tfd.chownSync(new_uid, new_gid);\n\t}\n\n\tpublic _syncSync(p: string, data: Buffer, stats: Stats): void {\n\t\t// @todo Ensure mtime updates properly, and use that to determine if a data\n\t\t// update is required.\n\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\t// We use the _findInode helper because we actually need the INode id.\n\t\t\tfileInodeId = this._findINode(tx, path.dirname(p), path.basename(p)),\n\t\t\tfileInode = this.getINode(tx, p, fileInodeId),\n\t\t\tinodeChanged = fileInode.update(stats);\n\n\t\ttry {\n\t\t\t// Sync data.\n\t\t\ttx.put(fileInode.id, data, true);\n\t\t\t// Sync metadata.\n\t\t\tif (inodeChanged) {\n\t\t\t\ttx.put(fileInodeId, fileInode.toBuffer(), true);\n\t\t\t}\n\t\t} catch (e) {\n\t\t\ttx.abort();\n\t\t\tthrow e;\n\t\t}\n\t\ttx.commit();\n\t}\n\n\t/**\n\t * Checks if the root directory exists. Creates it if it doesn't.\n\t */\n\tprivate makeRootDirectory() {\n\t\tconst tx = this.store.beginTransaction('readwrite');\n\t\tif (tx.get(ROOT_NODE_ID) === undefined) {\n\t\t\t// Create new inode.\n\t\t\tconst currTime = new Date().getTime(),\n\t\t\t\t// Mode 0666, owned by root:root\n\t\t\t\tdirInode = new Inode(randomUUID(), 4096, 511 | FileType.DIRECTORY, currTime, currTime, currTime, 0, 0);\n\t\t\t// If the root doesn't exist, the first random ID shouldn't exist,\n\t\t\t// either.\n\t\t\ttx.put(dirInode.id, getEmptyDirNode(), false);\n\t\t\ttx.put(ROOT_NODE_ID, dirInode.toBuffer(), false);\n\t\t\ttx.commit();\n\t\t}\n\t}\n\n\t/**\n\t * Helper function for findINode.\n\t * @param parent The parent directory of the file we are attempting to find.\n\t * @param filename The filename of the inode we are attempting to find, minus\n\t * the parent.\n\t * @return string The ID of the file's inode in the file system.\n\t */\n\tprivate _findINode(tx: SyncKeyValueROTransaction, parent: string, filename: string, visited: Set<string> = new Set<string>()): string {\n\t\tconst currentPath = path.posix.join(parent, filename);\n\t\tif (visited.has(currentPath)) {\n\t\t\tthrow new ApiError(ErrorCode.EIO, 'Infinite loop detected while finding inode', currentPath);\n\t\t}\n\n\t\tvisited.add(currentPath);\n\t\tconst readDirectory = (inode: Inode): string => {\n\t\t\t// Get the root's directory listing.\n\t\t\tconst dirList = this.getDirListing(tx, parent, inode);\n\t\t\t// Get the file's ID.\n\t\t\tif (dirList[filename]) {\n\t\t\t\treturn dirList[filename];\n\t\t\t} else {\n\t\t\t\tthrow ApiError.ENOENT(path.resolve(parent, filename));\n\t\t\t}\n\t\t};\n\t\tif (parent === '.') {\n\t\t\tparent = process.cwd();\n\t\t}\n\t\tif (parent === '/') {\n\t\t\tif (filename === '') {\n\t\t\t\t// BASE CASE #1: Return the root's ID.\n\t\t\t\treturn ROOT_NODE_ID;\n\t\t\t} else {\n\t\t\t\t// BASE CASE #2: Find the item in the root node.\n\t\t\t\treturn readDirectory(this.getINode(tx, parent, ROOT_NODE_ID));\n\t\t\t}\n\t\t} else {\n\t\t\treturn readDirectory(this.getINode(tx, parent + path.sep + filename, this._findINode(tx, path.dirname(parent), path.basename(parent), visited)));\n\t\t}\n\t}\n\n\t/**\n\t * Finds the Inode of the given path.\n\t * @param p The path to look up.\n\t * @return The Inode of the path p.\n\t * @todo memoize/cache\n\t */\n\tprivate findINode(tx: SyncKeyValueROTransaction, p: string): Inode {\n\t\treturn this.getINode(tx, p, this._findINode(tx, path.dirname(p), path.basename(p)));\n\t}\n\n\t/**\n\t * Given the ID of a node, retrieves the corresponding Inode.\n\t * @param tx The transaction to use.\n\t * @param p The corresponding path to the file (used for error messages).\n\t * @param id The ID to look up.\n\t */\n\tprivate getINode(tx: SyncKeyValueROTransaction, p: string, id: string): Inode {\n\t\tconst inode = tx.get(id);\n\t\tif (inode === undefined) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t\treturn Inode.fromBuffer(inode);\n\t}\n\n\t/**\n\t * Given the Inode of a directory, retrieves the corresponding directory\n\t * listing.\n\t */\n\tprivate getDirListing(tx: SyncKeyValueROTransaction, p: string, inode: Inode): { [fileName: string]: string } {\n\t\tif (!inode.isDirectory()) {\n\t\t\tthrow ApiError.ENOTDIR(p);\n\t\t}\n\t\tconst data = tx.get(inode.id);\n\t\tif (data === undefined) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t\treturn JSON.parse(data.toString());\n\t}\n\n\t/**\n\t * Creates a new node under a random ID. Retries 5 times before giving up in\n\t * the exceedingly unlikely chance that we try to reuse a random GUID.\n\t * @return The GUID that the data was stored under.\n\t */\n\tprivate addNewNode(tx: SyncKeyValueRWTransaction, data: Buffer): string {\n\t\tconst retries = 0;\n\t\tlet currId: string;\n\t\twhile (retries < 5) {\n\t\t\ttry {\n\t\t\t\tcurrId = randomUUID();\n\t\t\t\ttx.put(currId, data, false);\n\t\t\t\treturn currId;\n\t\t\t} catch (e) {\n\t\t\t\t// Ignore and reroll.\n\t\t\t}\n\t\t}\n\t\tthrow new ApiError(ErrorCode.EIO, 'Unable to commit data to key-value store.');\n\t}\n\n\t/**\n\t * Commits a new file (well, a FILE or a DIRECTORY) to the file system with\n\t * the given mode.\n\t * Note: This will commit the transaction.\n\t * @param p The path to the new file.\n\t * @param type The type of the new file.\n\t * @param mode The mode to create the new file with.\n\t * @param data The data to store at the file's data node.\n\t * @return The Inode for the new file.\n\t */\n\tprivate commitNewFile(tx: SyncKeyValueRWTransaction, p: string, type: FileType, mode: number, cred: Cred, data: Buffer): Inode {\n\t\tconst parentDir = path.dirname(p),\n\t\t\tfname = path.basename(p),\n\t\t\tparentNode = this.findINode(tx, parentDir),\n\t\t\tdirListing = this.getDirListing(tx, parentDir, parentNode),\n\t\t\tcurrTime = new Date().getTime();\n\n\t\t//Check that the creater has correct access\n\t\tif (!parentNode.toStats().hasAccess(0b0100 /* Write */, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\n\t\t// Invariant: The root always exists.\n\t\t// If we don't check this prior to taking steps below, we will create a\n\t\t// file with name '' in root should p == '/'.\n\t\tif (p === '/') {\n\t\t\tthrow ApiError.EEXIST(p);\n\t\t}\n\n\t\t// Check if file already exists.\n\t\tif (dirListing[fname]) {\n\t\t\tthrow ApiError.EEXIST(p);\n\t\t}\n\n\t\tlet fileNode: Inode;\n\t\ttry {\n\t\t\t// Commit data.\n\t\t\tconst dataId = this.addNewNode(tx, data);\n\t\t\tfileNode = new Inode(dataId, data.length, mode | type, currTime, currTime, currTime, cred.uid, cred.gid);\n\t\t\t// Commit file node.\n\t\t\tconst fileNodeId = this.addNewNode(tx, fileNode.toBuffer());\n\t\t\t// Update and commit parent directory listing.\n\t\t\tdirListing[fname] = fileNodeId;\n\t\t\ttx.put(parentNode.id, Buffer.from(JSON.stringify(dirListing)), true);\n\t\t} catch (e) {\n\t\t\ttx.abort();\n\t\t\tthrow e;\n\t\t}\n\t\ttx.commit();\n\t\treturn fileNode;\n\t}\n\n\t/**\n\t * Remove all traces of the given path from the file system.\n\t * @param p The path to remove from the file system.\n\t * @param isDir Does the path belong to a directory, or a file?\n\t * @todo Update mtime.\n\t */\n\tprivate removeEntry(p: string, isDir: boolean, cred: Cred): void {\n\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\tparent: string = path.dirname(p),\n\t\t\tparentNode = this.findINode(tx, parent),\n\t\t\tparentListing = this.getDirListing(tx, parent, parentNode),\n\t\t\tfileName: string = path.basename(p);\n\n\t\tif (!parentListing[fileName]) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\n\t\tconst fileNodeId = parentListing[fileName];\n\n\t\t// Get file inode.\n\t\tconst fileNode = this.getINode(tx, p, fileNodeId);\n\n\t\tif (!fileNode.toStats().hasAccess(W_OK, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\n\t\t// Remove from directory listing of parent.\n\t\tdelete parentListing[fileName];\n\n\t\tif (!isDir && fileNode.isDirectory()) {\n\t\t\tthrow ApiError.EISDIR(p);\n\t\t} else if (isDir && !fileNode.isDirectory()) {\n\t\t\tthrow ApiError.ENOTDIR(p);\n\t\t}\n\n\t\ttry {\n\t\t\t// Delete data.\n\t\t\ttx.del(fileNode.id);\n\t\t\t// Delete node.\n\t\t\ttx.del(fileNodeId);\n\t\t\t// Update directory listing.\n\t\t\ttx.put(parentNode.id, Buffer.from(JSON.stringify(parentListing)), true);\n\t\t} catch (e) {\n\t\t\ttx.abort();\n\t\t\tthrow e;\n\t\t}\n\t\t// Success.\n\t\ttx.commit();\n\t}\n}\n", "import type { BFSCallback, FileSystem } from '../filesystem.js';\nimport { checkOptions } from '../utils.js';\n\n/**\n * Describes a file system option.\n */\nexport interface BackendOption<T> {\n\t/**\n\t * The basic JavaScript type(s) for this option.\n\t */\n\ttype: string | string[];\n\n\t/**\n\t * Whether or not the option is optional (e.g., can be set to null or undefined).\n\t * Defaults to `false`.\n\t */\n\toptional?: boolean;\n\n\t/**\n\t * Description of the option. Used in error messages and documentation.\n\t */\n\tdescription: string;\n\n\t/**\n\t * A custom validation function to check if the option is valid.\n\t * Resolves if valid and rejects if not.\n\t */\n\tvalidator?(opt: T): Promise<void>;\n}\n\n/**\n * Describes all of the options available in a file system.\n */\nexport interface BackendOptions {\n\t[name: string]: BackendOption<unknown>;\n}\n\n/**\n * Contains types for static functions on a backend.\n */\nexport interface BaseBackendConstructor<FS extends typeof FileSystem = typeof FileSystem> {\n\tnew (...params: ConstructorParameters<FS>): InstanceType<FS>;\n\n\t/**\n\t * A name to identify the backend.\n\t */\n\tName: string;\n\n\t/**\n\t * Describes all of the options available for this backend.\n\t */\n\tOptions: BackendOptions;\n\n\t/**\n\t * Whether the backend is available in the current environment.\n\t * It supports checking synchronously and asynchronously\n\t * Sync:\n\t * Returns 'true' if this backend is available in the current\n\t * environment. For example, a `localStorage`-backed filesystem will return\n\t * 'false' if the browser does not support that API.\n\t *\n\t * Defaults to 'false', as the FileSystem base class isn't usable alone.\n\t */\n\tisAvailable(): boolean;\n}\n\n/**\n * Contains types for static functions on a backend.\n */\nexport interface BackendConstructor<FS extends typeof FileSystem = typeof FileSystem> extends BaseBackendConstructor<FS> {\n\t/**\n\t * Creates backend of this given type with the given\n\t * options, and either returns the result in a promise or callback.\n\t */\n\tCreate(): Promise<InstanceType<FS>>;\n\tCreate(options: object): Promise<InstanceType<FS>>;\n\tCreate(cb: BFSCallback<InstanceType<FS>>): void;\n\tCreate(options: object, cb: BFSCallback<InstanceType<FS>>): void;\n\tCreate(options: object, cb?: BFSCallback<InstanceType<FS>>): Promise<InstanceType<FS>> | void;\n}\n\nexport function CreateBackend<FS extends BaseBackendConstructor>(this: FS): Promise<InstanceType<FS>>;\nexport function CreateBackend<FS extends BaseBackendConstructor>(this: FS, options: BackendOptions): Promise<InstanceType<FS>>;\nexport function CreateBackend<FS extends BaseBackendConstructor>(this: FS, cb: BFSCallback<InstanceType<FS>>): void;\nexport function CreateBackend<FS extends BaseBackendConstructor>(this: FS, options: BackendOptions, cb: BFSCallback<InstanceType<FS>>): void;\nexport function CreateBackend<FS extends BaseBackendConstructor>(\n\tthis: FS,\n\toptions?: BackendOptions | BFSCallback<InstanceType<FS>>,\n\tcb?: BFSCallback<InstanceType<FS>>\n): Promise<InstanceType<FS>> | void {\n\tcb = typeof options === 'function' ? options : cb;\n\n\tcheckOptions(this, options);\n\n\tconst fs = new this(typeof options === 'function' ? {} : options) as InstanceType<FS>;\n\n\t// Promise\n\tif (typeof cb != 'function') {\n\t\treturn fs.whenReady();\n\t}\n\n\t// Callback\n\tfs.whenReady()\n\t\t.then(fs => cb(null, fs))\n\t\t.catch(err => cb(err));\n}\n", "import { SyncKeyValueStore, SimpleSyncStore, SimpleSyncRWTransaction, SyncKeyValueRWTransaction, SyncKeyValueFileSystem } from './SyncStore.js';\nimport { CreateBackend, type BackendOptions } from './backend.js';\n\n/**\n * A simple in-memory key-value store backed by a JavaScript object.\n */\nexport class InMemoryStore implements SyncKeyValueStore, SimpleSyncStore {\n\tprivate store: Map<string, Buffer> = new Map<string, Buffer>();\n\n\tpublic name() {\n\t\treturn InMemoryFileSystem.Name;\n\t}\n\tpublic clear() {\n\t\tthis.store.clear();\n\t}\n\n\tpublic beginTransaction(type: string): SyncKeyValueRWTransaction {\n\t\treturn new SimpleSyncRWTransaction(this);\n\t}\n\n\tpublic get(key: string): Buffer {\n\t\treturn this.store.get(key);\n\t}\n\n\tpublic put(key: string, data: Buffer, overwrite: boolean): boolean {\n\t\tif (!overwrite && this.store.has(key)) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.store.set(key, data);\n\t\treturn true;\n\t}\n\n\tpublic del(key: string): void {\n\t\tthis.store.delete(key);\n\t}\n}\n\n/**\n * A simple in-memory file system backed by an InMemoryStore.\n * Files are not persisted across page loads.\n */\nexport class InMemoryFileSystem extends SyncKeyValueFileSystem {\n\tpublic static readonly Name = 'InMemory';\n\n\tpublic static Create = CreateBackend.bind(this);\n\n\tpublic static readonly Options: BackendOptions = {};\n\n\tpublic constructor() {\n\t\tsuper({ store: new InMemoryStore() });\n\t}\n}\n", "// Utilities and shared data\n\nimport { posix as path } from 'path';\nimport { ApiError, ErrorCode } from '../ApiError.js';\nimport { Cred } from '../cred.js';\nimport { FileSystem } from '../filesystem.js';\nimport { File } from '../file.js';\n//import { BackendConstructor } from '../backends.js';\nimport { InMemoryFileSystem } from '../backends/InMemory.js';\nimport { BackendConstructor } from '../backends/backend.js';\n\n/**\n * converts Date or number to a fractional UNIX timestamp\n * Grabbed from NodeJS sources (lib/fs.js)\n */\nexport function _toUnixTimestamp(time: Date | number): number {\n\tif (typeof time === 'number') {\n\t\treturn time;\n\t} else if (time instanceof Date) {\n\t\treturn time.getTime() / 1000;\n\t}\n\tthrow new Error('Cannot parse time: ' + time);\n}\n\nexport function normalizeMode(mode: unknown, def: number): number {\n\tswitch (typeof mode) {\n\t\tcase 'number':\n\t\t\t// (path, flag, mode, cb?)\n\t\t\treturn mode;\n\t\tcase 'string':\n\t\t\t// (path, flag, modeString, cb?)\n\t\t\tconst trueMode = parseInt(mode, 8);\n\t\t\tif (!isNaN(trueMode)) {\n\t\t\t\treturn trueMode;\n\t\t\t}\n\t\t\t// Invalid string.\n\t\t\treturn def;\n\t\tdefault:\n\t\t\treturn def;\n\t}\n}\n\nexport function normalizeTime(time: number | Date): Date {\n\tif (time instanceof Date) {\n\t\treturn time;\n\t}\n\n\tif (typeof time === 'number') {\n\t\treturn new Date(time * 1000);\n\t}\n\n\tthrow new ApiError(ErrorCode.EINVAL, `Invalid time.`);\n}\n\nexport function normalizePath(p: string): string {\n\t// Node doesn't allow null characters in paths.\n\tif (p.indexOf('\\u0000') >= 0) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Path must be a string without null bytes.');\n\t}\n\tif (p === '') {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Path must not be empty.');\n\t}\n\tp = p.replaceAll(/\\/+/g, '/');\n\treturn path.resolve(p);\n}\n\nexport function normalizeOptions(options: any, defEnc: string | null, defFlag: string, defMode: number | null): { encoding: BufferEncoding; flag: string; mode: number } {\n\t// typeof null === 'object' so special-case handing is needed.\n\tswitch (options === null ? 'null' : typeof options) {\n\t\tcase 'object':\n\t\t\treturn {\n\t\t\t\tencoding: typeof options['encoding'] !== 'undefined' ? options['encoding'] : defEnc,\n\t\t\t\tflag: typeof options['flag'] !== 'undefined' ? options['flag'] : defFlag,\n\t\t\t\tmode: normalizeMode(options['mode'], defMode!),\n\t\t\t};\n\t\tcase 'string':\n\t\t\treturn {\n\t\t\t\tencoding: options,\n\t\t\t\tflag: defFlag,\n\t\t\t\tmode: defMode!,\n\t\t\t};\n\t\tcase 'null':\n\t\tcase 'undefined':\n\t\tcase 'function':\n\t\t\treturn {\n\t\t\t\tencoding: defEnc! as BufferEncoding,\n\t\t\t\tflag: defFlag,\n\t\t\t\tmode: defMode!,\n\t\t\t};\n\t\tdefault:\n\t\t\tthrow new TypeError(`\"options\" must be a string or an object, got ${typeof options} instead.`);\n\t}\n}\n\nexport function nop() {\n\t// do nothing\n}\n\n// credentials\nexport let cred: Cred;\nexport function setCred(val: Cred): void {\n\tcred = val;\n}\n\n// descriptors\nexport const fdMap: Map<number, File> = new Map();\nlet nextFd = 100;\nexport function getFdForFile(file: File): number {\n\tconst fd = nextFd++;\n\tfdMap.set(fd, file);\n\treturn fd;\n}\nexport function fd2file(fd: number): File {\n\tif (!fdMap.has(fd)) {\n\t\tthrow new ApiError(ErrorCode.EBADF, 'Invalid file descriptor.');\n\t}\n\treturn fdMap.get(fd);\n}\n\n// mounting\nexport interface MountMapping {\n\t[point: string]: InstanceType<BackendConstructor>;\n}\n\nexport const mounts: Map<string, FileSystem> = new Map();\n\n/*\nSet a default root.\nThere is a very small but not 0 change that initialize() will try to unmount the default before it is mounted.\nThis can be fixed by using a top-level await, which is not done to maintain ES6 compatibility.\n*/\nInMemoryFileSystem.Create().then(fs => mount('/', fs));\n\n/**\n * Gets the file system mounted at `mountPoint`\n */\nexport function getMount(mountPoint: string): FileSystem {\n\treturn mounts.get(mountPoint);\n}\n\n/**\n * Gets an object of mount points (keys) and filesystems (values)\n */\nexport function getMounts(): MountMapping {\n\treturn Object.fromEntries(mounts.entries());\n}\n\n/**\n * Mounts the file system at the given mount point.\n */\nexport function mount(mountPoint: string, fs: FileSystem): void {\n\tif (mountPoint[0] !== '/') {\n\t\tmountPoint = '/' + mountPoint;\n\t}\n\tmountPoint = path.resolve(mountPoint);\n\tif (mounts.has(mountPoint)) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Mount point ' + mountPoint + ' is already in use.');\n\t}\n\tmounts.set(mountPoint, fs);\n}\n\n/**\n * Unmounts the file system at the given mount point.\n */\nexport function umount(mountPoint: string): void {\n\tif (mountPoint[0] !== '/') {\n\t\tmountPoint = `/${mountPoint}`;\n\t}\n\tmountPoint = path.resolve(mountPoint);\n\tif (!mounts.has(mountPoint)) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Mount point ' + mountPoint + ' is already unmounted.');\n\t}\n\tmounts.delete(mountPoint);\n}\n\n/**\n * Gets the internal FileSystem for the path, then returns it along with the path relative to the FS' root\n */\nexport function resolveFS(path: string): { fs: FileSystem; path: string; mountPoint: string } {\n\tconst sortedMounts = [...mounts].sort((a, b) => (a[0].length > b[0].length ? -1 : 1)); // decending order of the string length\n\tfor (const [mountPoint, fs] of sortedMounts) {\n\t\t// We know path is normalized, so it would be a substring of the mount point.\n\t\tif (mountPoint.length <= path.length && path.startsWith(mountPoint)) {\n\t\t\tpath = path.slice(mountPoint.length > 1 ? mountPoint.length : 0); // Resolve the path relative to the mount point\n\t\t\tif (path === '') {\n\t\t\t\tpath = '/';\n\t\t\t}\n\t\t\treturn { fs, path, mountPoint };\n\t\t}\n\t}\n\n\tthrow new ApiError(ErrorCode.EIO, 'ZenFS not initialized with a file system');\n}\n\n/**\n * Reverse maps the paths in text from the mounted FileSystem to the global path\n */\nexport function fixPaths(text: string, paths: { [from: string]: string }): string {\n\tfor (const [from, to] of Object.entries(paths)) {\n\t\ttext = text.replaceAll(from, to);\n\t}\n\treturn text;\n}\n\nexport function fixError<E extends Error>(e: E, paths: { [from: string]: string }): E {\n\te.stack = fixPaths(e.stack, paths);\n\te.message = fixPaths(e.message, paths);\n\treturn e;\n}\n\nexport function initialize(mountMapping: MountMapping): void {\n\tif (mountMapping['/']) {\n\t\tumount('/');\n\t}\n\tfor (const [point, fs] of Object.entries(mountMapping)) {\n\t\tconst FS = fs.constructor as unknown as BackendConstructor;\n\t\tif (!FS.isAvailable()) {\n\t\t\tthrow new ApiError(ErrorCode.EINVAL, `Can not mount \"${point}\" since the filesystem is unavailable.`);\n\t\t}\n\n\t\tmount(point, fs);\n\t}\n}\n", "import type { ReadStream, WriteStream, FSWatcher, symlink as _symlink } from 'node:fs';\nimport { ApiError, ErrorCode } from '../ApiError.js';\n\nimport * as constants from './constants.js';\nexport { constants };\n\nimport { File, FileFlag } from '../file.js';\nimport { normalizePath, normalizeMode, getFdForFile, normalizeOptions, fd2file, fdMap, normalizeTime, cred, nop, resolveFS, fixError, mounts } from './shared.js';\nimport { FileContents, FileSystem } from '../filesystem.js';\nimport { Stats } from '../stats.js';\n\ntype FileSystemMethod = {\n\t[K in keyof FileSystem]: FileSystem[K] extends (...args: any) => any\n\t\t? (name: K, resolveSymlinks: boolean, ...args: Parameters<FileSystem[K]>) => ReturnType<FileSystem[K]>\n\t\t: never;\n}[keyof FileSystem]; // https://stackoverflow.com/a/76335220/17637456\n\n/**\n * Utility for FS ops. It handles\n * - path normalization (for the first parameter to the FS op)\n * - path translation for errors\n * - FS/mount point resolution\n *\n * It can't be used for functions which may operate on multiple mounted FSs or paths (e.g. `rename`)\n * @param name the function name\n * @param resolveSymlinks whether to resolve symlinks\n * @param args the rest of the parameters are passed to the FS function. Note that the first parameter is required to be a path\n * @returns\n */\nasync function doOp<M extends FileSystemMethod, RT extends ReturnType<M>>(...[name, resolveSymlinks, path, ...args]: Parameters<M>): Promise<RT> {\n\tpath = normalizePath(path);\n\tconst { fs, path: resolvedPath } = resolveFS(resolveSymlinks && (await exists(path)) ? await realpath(path) : path);\n\ttry {\n\t\t// @ts-expect-error 2556 (since ...args is not correctly picked up as being a tuple)\n\t\treturn fs[name](resolvedPath, ...args) as Promise<RT>;\n\t} catch (e) {\n\t\tthrow fixError(e, { [resolvedPath]: path });\n\t}\n}\n\n// fs.promises\n\n/**\n * Renames a file\n * @param oldPath\n * @param newPath\n */\nexport async function rename(oldPath: string, newPath: string): Promise<void> {\n\toldPath = normalizePath(oldPath);\n\tnewPath = normalizePath(newPath);\n\tconst _old = resolveFS(oldPath);\n\tconst _new = resolveFS(newPath);\n\tconst paths = { [_old.path]: oldPath, [_new.path]: newPath };\n\ttry {\n\t\tif (_old === _new) {\n\t\t\treturn _old.fs.rename(_old.path, _new.path, cred);\n\t\t}\n\n\t\tconst data = await readFile(oldPath);\n\t\tawait writeFile(newPath, data);\n\t\tawait unlink(oldPath);\n\t} catch (e) {\n\t\tthrow fixError(e, paths);\n\t}\n}\n\n/**\n * Test whether or not the given path exists by checking with the file system.\n * @param path\n */\nexport async function exists(path: string): Promise<boolean> {\n\tpath = normalizePath(path);\n\ttry {\n\t\tconst { fs, path: resolvedPath } = resolveFS(path);\n\t\treturn fs.exists(resolvedPath, cred);\n\t} catch (e) {\n\t\tif ((e as ApiError).errno == ErrorCode.ENOENT) {\n\t\t\treturn false;\n\t\t}\n\n\t\tthrow e;\n\t}\n}\n\n/**\n * `stat`.\n * @param path\n * @returns Stats\n */\nexport async function stat(path: string): Promise<Stats> {\n\treturn doOp('stat', true, path, cred);\n}\n\n/**\n * `lstat`.\n * `lstat()` is identical to `stat()`, except that if path is a symbolic link,\n * then the link itself is stat-ed, not the file that it refers to.\n * @param path\n * @return [ZenFS.node.fs.Stats]\n */\nexport async function lstat(path: string): Promise<Stats> {\n\treturn doOp('stat', false, path, cred);\n}\n\n// FILE-ONLY METHODS\n\n/**\n * `truncate`.\n * @param path\n * @param len\n */\nexport async function truncate(path: string, len: number = 0): Promise<void> {\n\tif (len < 0) {\n\t\tthrow new ApiError(ErrorCode.EINVAL);\n\t}\n\treturn doOp('truncate', true, path, len, cred);\n}\n\n/**\n * `unlink`.\n * @param path\n */\nexport async function unlink(path: string): Promise<void> {\n\treturn doOp('unlink', false, path, cred);\n}\n\n/**\n * file open.\n * @see http://www.manpagez.com/man/2/open/\n * @param path\n * @param flags\n * @param mode defaults to `0644`\n */\nexport async function open(path: string, flag: string, mode: number | string = 0o644): Promise<number> {\n\tconst file: File = await doOp('open', true, path, FileFlag.getFileFlag(flag), normalizeMode(mode, 0o644), cred);\n\treturn getFdForFile(file);\n}\n\n/**\n * Synchronously reads the entire contents of a file.\n * @param filename\n * @param options\n * @option options [String] encoding The string encoding for the file contents. Defaults to `null`.\n * @option options [String] flag Defaults to `'r'`.\n * @return [String | ZenFS.node.Buffer]\n */\nexport async function readFile(filename: string, options?: { flag?: string }): Promise<Buffer>;\nexport async function readFile(filename: string, options: { encoding: string; flag?: string }): Promise<string>;\nexport async function readFile(filename: string, encoding: string): Promise<string>;\nexport async function readFile(filename: string, arg2: any = {}): Promise<Buffer | string> {\n\tconst options = normalizeOptions(arg2, null, 'r', null);\n\tconst flag = FileFlag.getFileFlag(options.flag);\n\tif (!flag.isReadable()) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Flag passed to readFile must allow for reading.');\n\t}\n\treturn doOp('readFile', true, filename, options.encoding, flag, cred);\n}\n\n/**\n * Synchronously writes data to a file, replacing the file if it already\n * exists.\n *\n * The encoding option is ignored if data is a buffer.\n * @param filename\n * @param data\n * @param options\n * @option options [String] encoding Defaults to `'utf8'`.\n * @option options [Number] mode Defaults to `0644`.\n * @option options [String] flag Defaults to `'w'`.\n */\nexport async function writeFile(filename: string, data: FileContents, options?: { encoding?: string; mode?: number | string; flag?: string }): Promise<void>;\nexport async function writeFile(filename: string, data: FileContents, encoding?: string): Promise<void>;\nexport async function writeFile(filename: string, data: FileContents, options?: { encoding?: string; mode?: number | string; flag?: string } | string): Promise<void>;\nexport async function writeFile(filename: string, data: FileContents, arg3?: { encoding?: string; mode?: number | string; flag?: string } | string): Promise<void> {\n\tconst options = normalizeOptions(arg3, 'utf8', 'w', 0o644);\n\tconst flag = FileFlag.getFileFlag(options.flag);\n\tif (!flag.isWriteable()) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Flag passed to writeFile must allow for writing.');\n\t}\n\treturn doOp('writeFile', true, filename, data, options.encoding, flag, options.mode, cred);\n}\n\n/**\n * Asynchronously append data to a file, creating the file if it not yet\n * exists.\n *\n * @example Usage example\n * fs.appendFile('message.txt', 'data to append', function (err) {\n * if (err) throw err;\n * console.log('The \"data to append\" was appended to file!');\n * });\n * @param filename\n * @param data\n * @param options\n * @option options [String] encoding Defaults to `'utf8'`.\n * @option options [Number] mode Defaults to `0644`.\n * @option options [String] flag Defaults to `'a'`.\n */\nexport async function appendFile(filename: string, data: FileContents, options?: { encoding?: string; mode?: number | string; flag?: string }): Promise<void>;\nexport async function appendFile(filename: string, data: FileContents, encoding?: string): Promise<void>;\nexport async function appendFile(filename: string, data: FileContents, arg3?: any): Promise<void> {\n\tconst options = normalizeOptions(arg3, 'utf8', 'a', 0o644);\n\tconst flag = FileFlag.getFileFlag(options.flag);\n\tif (!flag.isAppendable()) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Flag passed to appendFile must allow for appending.');\n\t}\n\treturn doOp('appendFile', true, filename, data, options.encoding, flag, options.mode, cred);\n}\n\n// FILE DESCRIPTOR METHODS\n\n/**\n * `fstat`.\n * `fstat()` is identical to `stat()`, except that the file to be stat-ed is\n * specified by the file descriptor `fd`.\n * @param fd\n * @return [ZenFS.node.fs.Stats]\n */\nexport async function fstat(fd: number): Promise<Stats> {\n\treturn fd2file(fd).stat();\n}\n\n/**\n * close.\n * @param fd\n */\nexport async function close(fd: number): Promise<void> {\n\tawait fd2file(fd).close();\n\tfdMap.delete(fd);\n\treturn;\n}\n\n/**\n * ftruncate.\n * @param fd\n * @param len\n */\nexport async function ftruncate(fd: number, len: number = 0): Promise<void> {\n\tconst file = fd2file(fd);\n\tif (len < 0) {\n\t\tthrow new ApiError(ErrorCode.EINVAL);\n\t}\n\treturn file.truncate(len);\n}\n\n/**\n * fsync.\n * @param fd\n */\nexport async function fsync(fd: number): Promise<void> {\n\treturn fd2file(fd).sync();\n}\n\n/**\n * fdatasync.\n * @param fd\n */\nexport async function fdatasync(fd: number): Promise<void> {\n\treturn fd2file(fd).datasync();\n}\n\n/**\n * Write buffer to the file specified by `fd`.\n * Note that it is unsafe to use fs.write multiple times on the same file\n * without waiting for it to return.\n * @param fd\n * @param buffer Buffer containing the data to write to\n * the file.\n * @param offset Offset in the buffer to start reading data from.\n * @param length The amount of bytes to write to the file.\n * @param position Offset from the beginning of the file where this\n * data should be written. If position is null, the data will be written at\n * the current position.\n */\nexport async function write(fd: number, buffer: Buffer, offset: number, length: number, position?: number): Promise<number>;\nexport async function write(fd: number, data: string, position?: number | null, encoding?: BufferEncoding): Promise<number>;\nexport async function write(fd: number, arg2: Buffer | string, arg3?: number, arg4?: BufferEncoding | number, arg5?: number): Promise<number> {\n\tlet buffer: Buffer,\n\t\toffset: number = 0,\n\t\tlength: number,\n\t\tposition: number | null;\n\tif (typeof arg2 === 'string') {\n\t\t// Signature 1: (fd, string, [position?, [encoding?]])\n\t\tposition = typeof arg3 === 'number' ? arg3 : null;\n\t\tconst encoding = (typeof arg4 === 'string' ? arg4 : 'utf8') as BufferEncoding;\n\t\toffset = 0;\n\t\tbuffer = Buffer.from(arg2, encoding);\n\t\tlength = buffer.length;\n\t} else {\n\t\t// Signature 2: (fd, buffer, offset, length, position?)\n\t\tbuffer = arg2;\n\t\toffset = arg3;\n\t\tlength = arg4 as number;\n\t\tposition = typeof arg5 === 'number' ? arg5 : null;\n\t}\n\n\tconst file = fd2file(fd);\n\tif (position === undefined || position === null) {\n\t\tposition = file.getPos()!;\n\t}\n\treturn file.write(buffer, offset, length, position);\n}\n\n/**\n * Read data from the file specified by `fd`.\n * @param fd\n * @param buffer The buffer that the data will be\n * written to.\n * @param offset The offset within the buffer where writing will\n * start.\n * @param length An integer specifying the number of bytes to read.\n * @param position An integer specifying where to begin reading from\n * in the file. If position is null, data will be read from the current file\n * position.\n */\nexport async function read(fd: number, buffer: Buffer, offset: number, length: number, position?: number): Promise<{ bytesRead: number; buffer: Buffer }> {\n\tconst file = fd2file(fd);\n\tif (isNaN(+position)) {\n\t\tposition = file.getPos()!;\n\t}\n\n\treturn file.read(buffer, offset, length, position);\n}\n\n/**\n * `fchown`.\n * @param fd\n * @param uid\n * @param gid\n */\nexport async function fchown(fd: number, uid: number, gid: number): Promise<void> {\n\treturn fd2file(fd).chown(uid, gid);\n}\n\n/**\n * `fchmod`.\n * @param fd\n * @param mode\n */\nexport async function fchmod(fd: number, mode: number | string): Promise<void> {\n\tconst numMode = typeof mode === 'string' ? parseInt(mode, 8) : mode;\n\treturn fd2file(fd).chmod(numMode);\n}\n\n/**\n * Change the file timestamps of a file referenced by the supplied file\n * descriptor.\n * @param fd\n * @param atime\n * @param mtime\n */\nexport async function futimes(fd: number, atime: number | Date, mtime: number | Date): Promise<void> {\n\treturn fd2file(fd).utimes(normalizeTime(atime), normalizeTime(mtime));\n}\n\n// DIRECTORY-ONLY METHODS\n\n/**\n * `rmdir`.\n * @param path\n */\nexport async function rmdir(path: string): Promise<void> {\n\treturn doOp('rmdir', true, path, cred);\n}\n\n/**\n * `mkdir`.\n * @param path\n * @param mode defaults to `0777`\n */\nexport async function mkdir(path: string, mode?: number | string): Promise<void> {\n\treturn doOp('mkdir', true, path, normalizeMode(mode, 0o777), cred);\n}\n\n/**\n * `readdir`. Reads the contents of a directory.\n * @param path\n * @return [String[]]\n */\nexport async function readdir(path: string): Promise<string[]> {\n\tpath = normalizePath(path);\n\tconst entries: string[] = await doOp('readdir', true, path, cred);\n\tconst points = [...mounts.keys()];\n\tfor (const point of points) {\n\t\tif (point.startsWith(path)) {\n\t\t\tconst entry = point.slice(path.length);\n\t\t\tif (entry.includes('/') || entry.length == 0) {\n\t\t\t\t// ignore FSs mounted in subdirectories and any FS mounted to `path`.\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tentries.push(entry);\n\t\t}\n\t}\n\treturn entries;\n}\n\n// SYMLINK METHODS\n\n/**\n * `link`.\n * @param srcpath\n * @param dstpath\n */\nexport async function link(srcpath: string, dstpath: string): Promise<void> {\n\tdstpath = normalizePath(dstpath);\n\treturn doOp('link', false, srcpath, dstpath, cred);\n}\n\n/**\n * `symlink`.\n * @param srcpath\n * @param dstpath\n * @param type can be either `'dir'` or `'file'` (default is `'file'`)\n */\nexport async function symlink(srcpath: string, dstpath: string, type: _symlink.Type = 'file'): Promise<void> {\n\tif (!['file', 'dir', 'junction'].includes(type)) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Invalid type: ' + type);\n\t}\n\tdstpath = normalizePath(dstpath);\n\treturn doOp('symlink', false, srcpath, dstpath, type, cred);\n}\n\n/**\n * readlink.\n * @param path\n * @return [String]\n */\nexport async function readlink(path: string): Promise<string> {\n\treturn doOp('readlink', false, path, cred);\n}\n\n// PROPERTY OPERATIONS\n\n/**\n * `chown`.\n * @param path\n * @param uid\n * @param gid\n */\nexport async function chown(path: string, uid: number, gid: number): Promise<void> {\n\treturn doOp('chown', true, path, uid, gid, cred);\n}\n\n/**\n * `lchown`.\n * @param path\n * @param uid\n * @param gid\n */\nexport async function lchown(path: string, uid: number, gid: number): Promise<void> {\n\treturn doOp('chown', false, path, uid, gid, cred);\n}\n\n/**\n * `chmod`.\n * @param path\n * @param mode\n */\nexport async function chmod(path: string, mode: string | number): Promise<void> {\n\tconst numMode = normalizeMode(mode, -1);\n\tif (numMode < 0) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, `Invalid mode.`);\n\t}\n\treturn doOp('chmod', true, path, numMode, cred);\n}\n\n/**\n * `lchmod`.\n * @param path\n * @param mode\n */\nexport async function lchmod(path: string, mode: number | string): Promise<void> {\n\tconst numMode = normalizeMode(mode, -1);\n\tif (numMode < 1) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, `Invalid mode.`);\n\t}\n\treturn doOp('chmod', false, normalizePath(path), numMode, cred);\n}\n\n/**\n * Change file timestamps of the file referenced by the supplied path.\n * @param path\n * @param atime\n * @param mtime\n */\nexport async function utimes(path: string, atime: number | Date, mtime: number | Date): Promise<void> {\n\treturn doOp('utimes', true, path, normalizeTime(atime), normalizeTime(mtime), cred);\n}\n\n/**\n * Change file timestamps of the file referenced by the supplied path.\n * @param path\n * @param atime\n * @param mtime\n */\nexport async function lutimes(path: string, atime: number | Date, mtime: number | Date): Promise<void> {\n\treturn doOp('utimes', false, path, normalizeTime(atime), normalizeTime(mtime), cred);\n}\n\n/**\n * `realpath`.\n * @param path\n * @param cache An object literal of mapped paths that can be used to\n * force a specific path resolution or avoid additional `fs.stat` calls for\n * known real paths.\n * @return [String]\n */\nexport async function realpath(path: string, cache: { [path: string]: string } = {}): Promise<string> {\n\tpath = normalizePath(path);\n\tconst { fs, path: resolvedPath, mountPoint } = resolveFS(path);\n\ttry {\n\t\tconst stats = await fs.stat(resolvedPath, cred);\n\t\tif (!stats.isSymbolicLink()) {\n\t\t\treturn path;\n\t\t}\n\t\tconst dst = mountPoint + normalizePath(await fs.readlink(resolvedPath, cred));\n\t\treturn realpath(dst);\n\t} catch (e) {\n\t\tthrow fixError(e, { [resolvedPath]: path });\n\t}\n}\n\nexport async function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): Promise<void>;\nexport async function watchFile(filename: string, options: { persistent?: boolean; interval?: number }, listener: (curr: Stats, prev: Stats) => void): Promise<void>;\nexport async function watchFile(filename: string, arg2: any, listener: (curr: Stats, prev: Stats) => void = nop): Promise<void> {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n\nexport async function unwatchFile(filename: string, listener: (curr: Stats, prev: Stats) => void = nop): Promise<void> {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n\nexport async function watch(filename: string, listener?: (event: string, filename: string) => any): Promise<FSWatcher>;\nexport async function watch(filename: string, options: { persistent?: boolean }, listener?: (event: string, filename: string) => any): Promise<FSWatcher>;\nexport async function watch(filename: string, arg2: any, listener: (event: string, filename: string) => any = nop): Promise<FSWatcher> {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n\n/**\n * `access`.\n * @param path\n * @param mode\n */\nexport async function access(path: string, mode: number = 0o600): Promise<void> {\n\treturn doOp('access', true, path, mode, cred);\n}\n\nexport async function createReadStream(\n\tpath: string,\n\toptions?: {\n\t\tflags?: string;\n\t\tencoding?: string;\n\t\tfd?: number;\n\t\tmode?: number;\n\t\tautoClose?: boolean;\n\t}\n): Promise<ReadStream> {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n\nexport async function createWriteStream(\n\tpath: string,\n\toptions?: {\n\t\tflags?: string;\n\t\tencoding?: string;\n\t\tfd?: number;\n\t\tmode?: number;\n\t}\n): Promise<WriteStream> {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n", "import type { FSWatcher, ReadStream, WriteStream, symlink as _symlink } from 'fs';\nimport { ApiError, ErrorCode } from '../ApiError.js';\nimport { BFSCallback, BFSOneArgCallback, BFSThreeArgCallback, FileContents } from '../filesystem.js';\nimport { Stats } from '../stats.js';\nimport { nop, normalizeMode } from './shared.js';\nimport * as promises from './promises.js';\nimport { R_OK } from './constants.js';\n\n/**\n * Asynchronous rename. No arguments other than a possible exception are given\n * to the completion callback.\n * @param oldPath\n * @param newPath\n * @param callback\n */\nexport function rename(oldPath: string, newPath: string, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.rename(oldPath, newPath)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Test whether or not the given path exists by checking with the file system.\n * Then call the callback argument with either true or false.\n * @example Sample invocation\n * fs.exists('/etc/passwd', function (exists) {\n * util.debug(exists ? \"it's there\" : \"no passwd!\");\n * });\n * @param path\n * @param callback\n */\nexport function exists(path: string, cb: (exists: boolean) => unknown = nop): void {\n\tpromises\n\t\t.exists(path)\n\t\t.then(cb)\n\t\t.catch(() => cb(false));\n}\n\n/**\n * Asynchronous `stat`.\n * @param path\n * @param callback\n */\nexport function stat(path: string, cb: BFSCallback<Stats> = nop): void {\n\tpromises\n\t\t.stat(path)\n\t\t.then(stats => cb(null, stats))\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `lstat`.\n * `lstat()` is identical to `stat()`, except that if path is a symbolic link,\n * then the link itself is stat-ed, not the file that it refers to.\n * @param path\n * @param callback\n */\nexport function lstat(path: string, cb: BFSCallback<Stats> = nop): void {\n\tpromises\n\t\t.lstat(path)\n\t\t.then(stats => cb(null, stats))\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `truncate`.\n * @param path\n * @param len\n * @param callback\n */\nexport function truncate(path: string, cb?: BFSOneArgCallback): void;\nexport function truncate(path: string, len: number, cb?: BFSOneArgCallback): void;\nexport function truncate(path: string, arg2: number | BFSOneArgCallback = 0, cb: BFSOneArgCallback = nop): void {\n\tcb = typeof arg2 === 'function' ? arg2 : cb;\n\tconst len = typeof arg2 === 'number' ? arg2 : 0;\n\tpromises\n\t\t.truncate(path, len)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `unlink`.\n * @param path\n * @param callback\n */\nexport function unlink(path: string, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.unlink(path)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous file open.\n * Exclusive mode ensures that path is newly created.\n *\n * `flags` can be:\n *\n * * `'r'` - Open file for reading. An exception occurs if the file does not exist.\n * * `'r+'` - Open file for reading and writing. An exception occurs if the file does not exist.\n * * `'rs'` - Open file for reading in synchronous mode. Instructs the filesystem to not cache writes.\n * * `'rs+'` - Open file for reading and writing, and opens the file in synchronous mode.\n * * `'w'` - Open file for writing. The file is created (if it does not exist) or truncated (if it exists).\n * * `'wx'` - Like 'w' but opens the file in exclusive mode.\n * * `'w+'` - Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).\n * * `'wx+'` - Like 'w+' but opens the file in exclusive mode.\n * * `'a'` - Open file for appending. The file is created if it does not exist.\n * * `'ax'` - Like 'a' but opens the file in exclusive mode.\n * * `'a+'` - Open file for reading and appending. The file is created if it does not exist.\n * * `'ax+'` - Like 'a+' but opens the file in exclusive mode.\n *\n * @see http://www.manpagez.com/man/2/open/\n * @param path\n * @param flags\n * @param mode defaults to `0644`\n * @param callback\n */\nexport function open(path: string, flag: string, cb?: BFSCallback<number>): void;\nexport function open(path: string, flag: string, mode: number | string, cb?: BFSCallback<number>): void;\nexport function open(path: string, flag: string, arg2?: number | string | BFSCallback<number>, cb: BFSCallback<number> = nop): void {\n\tconst mode = normalizeMode(arg2, 0o644);\n\tcb = typeof arg2 === 'function' ? arg2 : cb;\n\tpromises\n\t\t.open(path, flag, mode)\n\t\t.then(fd => cb(null, fd))\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronously reads the entire contents of a file.\n * @example Usage example\n * fs.readFile('/etc/passwd', function (err, data) {\n * if (err) throw err;\n * console.log(data);\n * });\n * @param filename\n * @param options\n * @option options [String] encoding The string encoding for the file contents. Defaults to `null`.\n * @option options [String] flag Defaults to `'r'`.\n * @param callback If no encoding is specified, then the raw buffer is returned.\n */\nexport function readFile(filename: string, cb: BFSCallback<Buffer>): void;\nexport function readFile(filename: string, options: { flag?: string }, callback?: BFSCallback<Buffer>): void;\nexport function readFile(filename: string, options: { encoding: string; flag?: string }, callback?: BFSCallback<string>): void;\nexport function readFile(filename: string, encoding: string, cb: BFSCallback<string>): void;\nexport function readFile(filename: string, arg2: any = {}, cb: BFSCallback<string> | BFSCallback<Buffer> = nop) {\n\tcb = typeof arg2 === 'function' ? arg2 : cb;\n\n\tpromises.readFile(filename, typeof arg2 === 'function' ? null : arg2);\n}\n\n/**\n * Asynchronously writes data to a file, replacing the file if it already\n * exists.\n *\n * The encoding option is ignored if data is a buffer.\n *\n * @example Usage example\n * fs.writeFile('message.txt', 'Hello Node', function (err) {\n * if (err) throw err;\n * console.log('It\\'s saved!');\n * });\n * @param filename\n * @param data\n * @param options\n * @option options [String] encoding Defaults to `'utf8'`.\n * @option options [Number] mode Defaults to `0644`.\n * @option options [String] flag Defaults to `'w'`.\n * @param callback\n */\nexport function writeFile(filename: string, data: FileContents, cb?: BFSOneArgCallback): void;\nexport function writeFile(filename: string, data: FileContents, encoding?: string, cb?: BFSOneArgCallback): void;\nexport function writeFile(filename: string, data: FileContents, options?: { encoding?: string; mode?: string | number; flag?: string }, cb?: BFSOneArgCallback): void;\nexport function writeFile(\n\tfilename: string,\n\tdata: FileContents,\n\targ3: { encoding?: string; mode?: string | number; flag?: string } | string | BFSOneArgCallback = {},\n\tcb: BFSOneArgCallback = nop\n): void {\n\tcb = typeof arg3 === 'function' ? arg3 : cb;\n\tpromises.writeFile(filename, data, typeof arg3 === 'function' ? undefined : arg3);\n}\n\n/**\n * Asynchronously append data to a file, creating the file if it not yet\n * exists.\n *\n * @example Usage example\n * fs.appendFile('message.txt', 'data to append', function (err) {\n * if (err) throw err;\n * console.log('The \"data to append\" was appended to file!');\n * });\n * @param filename\n * @param data\n * @param options\n * @option options [String] encoding Defaults to `'utf8'`.\n * @option options [Number] mode Defaults to `0644`.\n * @option options [String] flag Defaults to `'a'`.\n * @param callback\n */\nexport function appendFile(filename: string, data: FileContents, cb?: BFSOneArgCallback): void;\nexport function appendFile(filename: string, data: FileContents, options?: { encoding?: string; mode?: number | string; flag?: string }, cb?: BFSOneArgCallback): void;\nexport function appendFile(filename: string, data: FileContents, encoding?: string, cb?: BFSOneArgCallback): void;\nexport function appendFile(filename: string, data: FileContents, arg3?: any, cb: BFSOneArgCallback = nop): void {\n\tcb = typeof arg3 === 'function' ? arg3 : cb;\n\tpromises.appendFile(filename, data, typeof arg3 === 'function' ? null : arg3);\n}\n\n/**\n * Asynchronous `fstat`.\n * `fstat()` is identical to `stat()`, except that the file to be stat-ed is\n * specified by the file descriptor `fd`.\n * @param fd\n * @param callback\n */\nexport function fstat(fd: number, cb: BFSCallback<Stats> = nop): void {\n\tpromises\n\t\t.fstat(fd)\n\t\t.then(stats => cb(null, stats))\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous close.\n * @param fd\n * @param callback\n */\nexport function close(fd: number, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.close(fd)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous ftruncate.\n * @param fd\n * @param len\n * @param callback\n */\nexport function ftruncate(fd: number, cb?: BFSOneArgCallback): void;\nexport function ftruncate(fd: number, len?: number, cb?: BFSOneArgCallback): void;\nexport function ftruncate(fd: number, arg2?: any, cb: BFSOneArgCallback = nop): void {\n\tconst length = typeof arg2 === 'number' ? arg2 : 0;\n\tcb = typeof arg2 === 'function' ? arg2 : cb;\n\tpromises.ftruncate(fd, length);\n}\n\n/**\n * Asynchronous fsync.\n * @param fd\n * @param callback\n */\nexport function fsync(fd: number, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.fsync(fd)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous fdatasync.\n * @param fd\n * @param callback\n */\nexport function fdatasync(fd: number, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.fdatasync(fd)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Write buffer to the file specified by `fd`.\n * Note that it is unsafe to use fs.write multiple times on the same file\n * without waiting for the callback.\n * @param fd\n * @param buffer Buffer containing the data to write to\n * the file.\n * @param offset Offset in the buffer to start reading data from.\n * @param length The amount of bytes to write to the file.\n * @param position Offset from the beginning of the file where this\n * data should be written. If position is null, the data will be written at\n * the current position.\n * @param callback The number specifies the number of bytes written into the file.\n */\nexport function write(fd: number, buffer: Buffer, offset: number, length: number, cb?: BFSThreeArgCallback<number, Buffer>): void;\nexport function write(fd: number, buffer: Buffer, offset: number, length: number, position: number | null, cb?: BFSThreeArgCallback<number, Buffer>): void;\nexport function write(fd: number, data: FileContents, cb?: BFSThreeArgCallback<number, string>): void;\nexport function write(fd: number, data: FileContents, position: number | null, cb?: BFSThreeArgCallback<number, string>): void;\nexport function write(fd: number, data: FileContents, position: number | null, encoding: BufferEncoding, cb?: BFSThreeArgCallback<number, string>): void;\nexport function write(\n\tfd: number,\n\targ2: FileContents,\n\targ3?: any,\n\targ4?: any,\n\targ5?: any,\n\tcb: BFSThreeArgCallback<number, Buffer> | BFSThreeArgCallback<number, string> = nop\n): void {\n\tlet buffer: Buffer,\n\t\toffset: number,\n\t\tlength: number,\n\t\tposition: number | null = null,\n\t\tencoding: BufferEncoding;\n\tif (typeof arg2 === 'string') {\n\t\t// Signature 1: (fd, string, [position?, [encoding?]], cb?)\n\t\tencoding = 'utf8';\n\t\tswitch (typeof arg3) {\n\t\t\tcase 'function':\n\t\t\t\t// (fd, string, cb)\n\t\t\t\tcb = arg3;\n\t\t\t\tbreak;\n\t\t\tcase 'number':\n\t\t\t\t// (fd, string, position, encoding?, cb?)\n\t\t\t\tposition = arg3;\n\t\t\t\tencoding = (typeof arg4 === 'string' ? arg4 : 'utf8') as BufferEncoding;\n\t\t\t\tcb = typeof arg5 === 'function' ? arg5 : cb;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\t// ...try to find the callback and get out of here!\n\t\t\t\tcb = typeof arg4 === 'function' ? arg4 : typeof arg5 === 'function' ? arg5 : cb;\n\t\t\t\tcb(new ApiError(ErrorCode.EINVAL, 'Invalid arguments.'));\n\t\t\t\treturn;\n\t\t}\n\t\tbuffer = Buffer.from(arg2, encoding);\n\t\toffset = 0;\n\t\tlength = buffer.length;\n\t\tconst _cb = cb as BFSThreeArgCallback<number, string>;\n\t\tpromises\n\t\t\t.write(fd, buffer, offset, length, position)\n\t\t\t.then(bytesWritten => _cb(null, bytesWritten, buffer.toString(encoding)))\n\t\t\t.catch(_cb);\n\t} else {\n\t\t// Signature 2: (fd, buffer, offset, length, position?, cb?)\n\t\tbuffer = arg2;\n\t\toffset = arg3;\n\t\tlength = arg4;\n\t\tposition = typeof arg5 === 'number' ? arg5 : null;\n\t\tconst _cb = (typeof arg5 === 'function' ? arg5 : cb) as BFSThreeArgCallback<number, Buffer>;\n\t\tpromises\n\t\t\t.write(fd, buffer, offset, length, position)\n\t\t\t.then(bytesWritten => _cb(null, bytesWritten, buffer))\n\t\t\t.catch(_cb);\n\t}\n}\n\n/**\n * Read data from the file specified by `fd`.\n * @param buffer The buffer that the data will be\n * written to.\n * @param offset The offset within the buffer where writing will\n * start.\n * @param length An integer specifying the number of bytes to read.\n * @param position An integer specifying where to begin reading from\n * in the file. If position is null, data will be read from the current file\n * position.\n * @param callback The number is the number of bytes read\n */\nexport function read(fd: number, buffer: Buffer, offset: number, length: number, position?: number, cb: BFSThreeArgCallback<number, Buffer> = nop): void {\n\tpromises\n\t\t.read(fd, buffer, offset, length, position)\n\t\t.then(({ bytesRead, buffer }) => cb(null, bytesRead, buffer))\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `fchown`.\n * @param fd\n * @param uid\n * @param gid\n * @param callback\n */\nexport function fchown(fd: number, uid: number, gid: number, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.fchown(fd, uid, gid)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `fchmod`.\n * @param fd\n * @param mode\n * @param callback\n */\nexport function fchmod(fd: number, mode: string | number, cb: BFSOneArgCallback): void {\n\tpromises\n\t\t.fchmod(fd, mode)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Change the file timestamps of a file referenced by the supplied file\n * descriptor.\n * @param fd\n * @param atime\n * @param mtime\n * @param callback\n */\nexport function futimes(fd: number, atime: number | Date, mtime: number | Date, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.futimes(fd, atime, mtime)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `rmdir`.\n * @param path\n * @param callback\n */\nexport function rmdir(path: string, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.rmdir(path)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `mkdir`.\n * @param path\n * @param mode defaults to `0777`\n * @param callback\n */\nexport function mkdir(path: string, mode?: any, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.mkdir(path, mode)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `readdir`. Reads the contents of a directory.\n * The callback gets two arguments `(err, files)` where `files` is an array of\n * the names of the files in the directory excluding `'.'` and `'..'`.\n * @param path\n * @param callback\n */\nexport function readdir(path: string, cb: BFSCallback<string[]> = nop): void {\n\tpromises\n\t\t.readdir(path)\n\t\t.then(entries => cb(null, entries))\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `link`.\n * @param srcpath\n * @param dstpath\n * @param callback\n */\nexport function link(srcpath: string, dstpath: string, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.link(srcpath, dstpath)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `symlink`.\n * @param srcpath\n * @param dstpath\n * @param type can be either `'dir'` or `'file'` (default is `'file'`)\n * @param callback\n */\nexport function symlink(srcpath: string, dstpath: string, cb?: BFSOneArgCallback): void;\nexport function symlink(srcpath: string, dstpath: string, type?: _symlink.Type, cb?: BFSOneArgCallback): void;\nexport function symlink(srcpath: string, dstpath: string, arg3?: _symlink.Type | BFSOneArgCallback, cb: BFSOneArgCallback = nop): void {\n\tconst type = typeof arg3 === 'string' ? arg3 : 'file';\n\tcb = typeof arg3 === 'function' ? arg3 : cb;\n\tpromises\n\t\t.symlink(srcpath, dstpath, typeof arg3 === 'function' ? null : arg3)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous readlink.\n * @param path\n * @param callback\n */\nexport function readlink(path: string, cb: BFSCallback<string> = nop): void {\n\tpromises\n\t\t.readlink(path)\n\t\t.then(result => cb(null, result))\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `chown`.\n * @param path\n * @param uid\n * @param gid\n * @param callback\n */\nexport function chown(path: string, uid: number, gid: number, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.chown(path, uid, gid)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `lchown`.\n * @param path\n * @param uid\n * @param gid\n * @param callback\n */\nexport function lchown(path: string, uid: number, gid: number, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.lchown(path, uid, gid)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `chmod`.\n * @param path\n * @param mode\n * @param callback\n */\nexport function chmod(path: string, mode: number | string, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.chmod(path, mode)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `lchmod`.\n * @param path\n * @param mode\n * @param callback\n */\nexport function lchmod(path: string, mode: number | string, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.lchmod(path, mode)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Change file timestamps of the file referenced by the supplied path.\n * @param path\n * @param atime\n * @param mtime\n * @param callback\n */\nexport function utimes(path: string, atime: number | Date, mtime: number | Date, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.utimes(path, atime, mtime)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Change file timestamps of the file referenced by the supplied path.\n * @param path\n * @param atime\n * @param mtime\n * @param callback\n */\nexport function lutimes(path: string, atime: number | Date, mtime: number | Date, cb: BFSOneArgCallback = nop): void {\n\tpromises\n\t\t.lutimes(path, atime, mtime)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `realpath`. The callback gets two arguments\n * `(err, resolvedPath)`. May use `process.cwd` to resolve relative paths.\n *\n * @example Usage example\n * let cache = {'/etc':'/private/etc'};\n * fs.realpath('/etc/passwd', cache, function (err, resolvedPath) {\n * if (err) throw err;\n * console.log(resolvedPath);\n * });\n *\n * @param path\n * @param cache An object literal of mapped paths that can be used to\n * force a specific path resolution or avoid additional `fs.stat` calls for\n * known real paths.\n * @param callback\n */\nexport function realpath(path: string, cb?: BFSCallback<string>): void;\nexport function realpath(path: string, cache: { [path: string]: string }, cb: BFSCallback<string>): void;\nexport function realpath(path: string, arg2?: any, cb: BFSCallback<string> = nop): void {\n\tconst cache = typeof arg2 === 'object' ? arg2 : {};\n\tcb = typeof arg2 === 'function' ? arg2 : cb;\n\tpromises\n\t\t.realpath(path, typeof arg2 === 'function' ? null : arg2)\n\t\t.then(result => cb(null, result))\n\t\t.catch(cb);\n}\n\n/**\n * Asynchronous `access`.\n * @param path\n * @param mode\n * @param callback\n */\nexport function access(path: string, cb: BFSOneArgCallback): void;\nexport function access(path: string, mode: number, cb: BFSOneArgCallback): void;\nexport function access(path: string, arg2: any, cb: BFSOneArgCallback = nop): void {\n\tconst mode = typeof arg2 === 'number' ? arg2 : R_OK;\n\tcb = typeof arg2 === 'function' ? arg2 : cb;\n\tpromises\n\t\t.access(path, typeof arg2 === 'function' ? null : arg2)\n\t\t.then(() => cb())\n\t\t.catch(cb);\n}\n\nexport function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): void;\nexport function watchFile(filename: string, options: { persistent?: boolean; interval?: number }, listener: (curr: Stats, prev: Stats) => void): void;\nexport function watchFile(filename: string, arg2: any, listener: (curr: Stats, prev: Stats) => void = nop): void {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n\nexport function unwatchFile(filename: string, listener: (curr: Stats, prev: Stats) => void = nop): void {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n\nexport function watch(filename: string, listener?: (event: string, filename: string) => any): FSWatcher;\nexport function watch(filename: string, options: { persistent?: boolean }, listener?: (event: string, filename: string) => any): FSWatcher;\nexport function watch(filename: string, arg2: any, listener: (event: string, filename: string) => any = nop): FSWatcher {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n\nexport function createReadStream(\n\tpath: string,\n\toptions?: {\n\t\tflags?: string;\n\t\tencoding?: string;\n\t\tfd?: number;\n\t\tmode?: number;\n\t\tautoClose?: boolean;\n\t}\n): ReadStream {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n\nexport function createWriteStream(\n\tpath: string,\n\toptions?: {\n\t\tflags?: string;\n\t\tencoding?: string;\n\t\tfd?: number;\n\t\tmode?: number;\n\t}\n): WriteStream {\n\tthrow new ApiError(ErrorCode.ENOTSUP);\n}\n", "import { ApiError, ErrorCode } from '../ApiError.js';\nimport { File, FileFlag } from '../file.js';\nimport { FileContents, FileSystem } from '../filesystem.js';\nimport { Stats } from '../stats.js';\nimport type { symlink, ReadSyncOptions } from 'fs';\nimport { normalizePath, cred, getFdForFile, normalizeMode, normalizeOptions, fdMap, fd2file, normalizeTime, resolveFS, fixError, mounts } from './shared.js';\n\ntype FileSystemMethod = {\n\t[K in keyof FileSystem]: FileSystem[K] extends (...args: any) => any\n\t\t? (name: K, resolveSymlinks: boolean, ...args: Parameters<FileSystem[K]>) => ReturnType<FileSystem[K]>\n\t\t: never;\n}[keyof FileSystem]; // https://stackoverflow.com/a/76335220/17637456\n\nfunction doOp<M extends FileSystemMethod, RT extends ReturnType<M>>(...[name, resolveSymlinks, path, ...args]: Parameters<M>): RT {\n\tpath = normalizePath(path);\n\tconst { fs, path: resolvedPath } = resolveFS(resolveSymlinks && existsSync(path) ? realpathSync(path) : path);\n\ttry {\n\t\t// @ts-expect-error 2556 (since ...args is not correctly picked up as being a tuple)\n\t\treturn fs[name](resolvedPath, ...args) as RT;\n\t} catch (e) {\n\t\tthrow fixError(e, { [resolvedPath]: path });\n\t}\n}\n\n/**\n * Synchronous rename.\n * @param oldPath\n * @param newPath\n */\nexport function renameSync(oldPath: string, newPath: string): void {\n\toldPath = normalizePath(oldPath);\n\tnewPath = normalizePath(newPath);\n\tconst _old = resolveFS(oldPath);\n\tconst _new = resolveFS(newPath);\n\tconst paths = { [_old.path]: oldPath, [_new.path]: newPath };\n\ttry {\n\t\tif (_old === _new) {\n\t\t\treturn _old.fs.renameSync(_old.path, _new.path, cred);\n\t\t}\n\n\t\tconst data = readFileSync(oldPath);\n\t\twriteFileSync(newPath, data);\n\t\tunlinkSync(oldPath);\n\t} catch (e) {\n\t\tthrow fixError(e, paths);\n\t}\n}\n\n/**\n * Test whether or not the given path exists by checking with the file system.\n * @param path\n */\nexport function existsSync(path: string): boolean {\n\tpath = normalizePath(path);\n\ttry {\n\t\tconst { fs, path: resolvedPath } = resolveFS(path);\n\t\treturn fs.existsSync(resolvedPath, cred);\n\t} catch (e) {\n\t\tif ((e as ApiError).errno == ErrorCode.ENOENT) {\n\t\t\treturn false;\n\t\t}\n\n\t\tthrow e;\n\t}\n}\n\n/**\n * Synchronous `stat`.\n * @param path\n * @returns Stats\n */\nexport function statSync(path: string): Stats {\n\treturn doOp('statSync', true, path, cred);\n}\n\n/**\n * Synchronous `lstat`.\n * `lstat()` is identical to `stat()`, except that if path is a symbolic link,\n * then the link itself is stat-ed, not the file that it refers to.\n * @param path\n * @return [ZenFS.node.fs.Stats]\n */\nexport function lstatSync(path: string): Stats {\n\treturn doOp('statSync', false, path, cred);\n}\n\n/**\n * Synchronous `truncate`.\n * @param path\n * @param len\n */\nexport function truncateSync(path: string, len: number = 0): void {\n\tif (len < 0) {\n\t\tthrow new ApiError(ErrorCode.EINVAL);\n\t}\n\treturn doOp('truncateSync', true, path, len, cred);\n}\n\n/**\n * Synchronous `unlink`.\n * @param path\n */\nexport function unlinkSync(path: string): void {\n\treturn doOp('unlinkSync', false, path, cred);\n}\n\n/**\n * Synchronous file open.\n * @see http://www.manpagez.com/man/2/open/\n * @param path\n * @param flags\n * @param mode defaults to `0644`\n * @return [ZenFS.File]\n */\nexport function openSync(path: string, flag: string, mode: number | string = 0o644): number {\n\tconst file: File = doOp('openSync', true, path, FileFlag.getFileFlag(flag), normalizeMode(mode, 0o644), cred);\n\treturn getFdForFile(file);\n}\n\n/**\n * Synchronously reads the entire contents of a file.\n * @param filename\n * @param options\n * @option options [String] encoding The string encoding for the file contents. Defaults to `null`.\n * @option options [String] flag Defaults to `'r'`.\n * @return [String | ZenFS.node.Buffer]\n */\nexport function readFileSync(filename: string, options?: { flag?: string }): Buffer;\nexport function readFileSync(filename: string, options: { encoding: string; flag?: string }): string;\nexport function readFileSync(filename: string, encoding: string): string;\nexport function readFileSync(filename: string, arg2: { encoding: string; flag?: string } | { flag?: string } | string = {}): FileContents {\n\tconst options = normalizeOptions(arg2, null, 'r', null);\n\tconst flag = FileFlag.getFileFlag(options.flag);\n\tif (!flag.isReadable()) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Flag passed to readFile must allow for reading.');\n\t}\n\treturn doOp('readFileSync', true, filename, options.encoding, flag, cred);\n}\n\n/**\n * Synchronously writes data to a file, replacing the file if it already\n * exists.\n *\n * The encoding option is ignored if data is a buffer.\n * @param filename\n * @param data\n * @param options\n * @option options [String] encoding Defaults to `'utf8'`.\n * @option options [Number] mode Defaults to `0644`.\n * @option options [String] flag Defaults to `'w'`.\n */\nexport function writeFileSync(filename: string, data: FileContents, options?: { encoding?: string; mode?: number | string; flag?: string }): void;\nexport function writeFileSync(filename: string, data: FileContents, encoding?: string): void;\nexport function writeFileSync(filename: string, data: FileContents, arg3?: { encoding?: string; mode?: number | string; flag?: string } | string): void {\n\tconst options = normalizeOptions(arg3, 'utf8', 'w', 0o644);\n\tconst flag = FileFlag.getFileFlag(options.flag);\n\tif (!flag.isWriteable()) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Flag passed to writeFile must allow for writing.');\n\t}\n\treturn doOp('writeFileSync', true, filename, data, options.encoding, flag, options.mode, cred);\n}\n\n/**\n * Asynchronously append data to a file, creating the file if it not yet\n * exists.\n *\n * @example Usage example\n * fs.appendFile('message.txt', 'data to append', function (err) {\n * if (err) throw err;\n * console.log('The \"data to append\" was appended to file!');\n * });\n * @param filename\n * @param data\n * @param options\n * @option options [String] encoding Defaults to `'utf8'`.\n * @option options [Number] mode Defaults to `0644`.\n * @option options [String] flag Defaults to `'a'`.\n */\nexport function appendFileSync(filename: string, data: FileContents, options?: { encoding?: string; mode?: number | string; flag?: string }): void;\nexport function appendFileSync(filename: string, data: FileContents, encoding?: string): void;\nexport function appendFileSync(filename: string, data: FileContents, arg3?: { encoding?: string; mode?: number | string; flag?: string } | string): void {\n\tconst options = normalizeOptions(arg3, 'utf8', 'a', 0o644);\n\tconst flag = FileFlag.getFileFlag(options.flag);\n\tif (!flag.isAppendable()) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Flag passed to appendFile must allow for appending.');\n\t}\n\treturn doOp('appendFileSync', true, filename, data, options.encoding, flag, options.mode, cred);\n}\n\n/**\n * Synchronous `fstat`.\n * `fstat()` is identical to `stat()`, except that the file to be stat-ed is\n * specified by the file descriptor `fd`.\n * @param fd\n * @return [ZenFS.node.fs.Stats]\n */\nexport function fstatSync(fd: number): Stats {\n\treturn fd2file(fd).statSync();\n}\n\n/**\n * Synchronous close.\n * @param fd\n */\nexport function closeSync(fd: number): void {\n\tfd2file(fd).closeSync();\n\tfdMap.delete(fd);\n}\n\n/**\n * Synchronous ftruncate.\n * @param fd\n * @param len\n */\nexport function ftruncateSync(fd: number, len: number = 0): void {\n\tconst file = fd2file(fd);\n\tif (len < 0) {\n\t\tthrow new ApiError(ErrorCode.EINVAL);\n\t}\n\tfile.truncateSync(len);\n}\n\n/**\n * Synchronous fsync.\n * @param fd\n */\nexport function fsyncSync(fd: number): void {\n\tfd2file(fd).syncSync();\n}\n\n/**\n * Synchronous fdatasync.\n * @param fd\n */\nexport function fdatasyncSync(fd: number): void {\n\tfd2file(fd).datasyncSync();\n}\n\n/**\n * Write buffer to the file specified by `fd`.\n * Note that it is unsafe to use fs.write multiple times on the same file\n * without waiting for it to return.\n * @param fd\n * @param buffer Buffer containing the data to write to\n * the file.\n * @param offset Offset in the buffer to start reading data from.\n * @param length The amount of bytes to write to the file.\n * @param position Offset from the beginning of the file where this\n * data should be written. If position is null, the data will be written at\n * the current position.\n */\nexport function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position?: number | null): number;\nexport function writeSync(fd: number, data: string, position?: number | null, encoding?: BufferEncoding): number;\nexport function writeSync(fd: number, arg2: Buffer | string, arg3?: number, arg4?: BufferEncoding | number, arg5?: number): number {\n\tlet buffer: Buffer,\n\t\toffset: number = 0,\n\t\tlength: number,\n\t\tposition: number | null;\n\tif (typeof arg2 === 'string') {\n\t\t// Signature 1: (fd, string, [position?, [encoding?]])\n\t\tposition = typeof arg3 === 'number' ? arg3 : null;\n\t\tconst encoding = (typeof arg4 === 'string' ? arg4 : 'utf8') as BufferEncoding;\n\t\toffset = 0;\n\t\tbuffer = Buffer.from(arg2, encoding);\n\t\tlength = buffer.length;\n\t} else {\n\t\t// Signature 2: (fd, buffer, offset, length, position?)\n\t\tbuffer = arg2;\n\t\toffset = arg3;\n\t\tlength = arg4 as number;\n\t\tposition = typeof arg5 === 'number' ? arg5 : null;\n\t}\n\n\tconst file = fd2file(fd);\n\tif (position === undefined || position === null) {\n\t\tposition = file.getPos()!;\n\t}\n\treturn file.writeSync(buffer, offset, length, position);\n}\n\n/**\n * Read data from the file specified by `fd`.\n * @param fd\n * @param buffer The buffer that the data will be\n * written to.\n * @param offset The offset within the buffer where writing will\n * start.\n * @param length An integer specifying the number of bytes to read.\n * @param position An integer specifying where to begin reading from\n * in the file. If position is null, data will be read from the current file\n * position.\n */\nexport function readSync(fd: number, buffer: Buffer, opts?: ReadSyncOptions): number;\nexport function readSync(fd: number, buffer: Buffer, offset: number, length: number, position?: number): number;\nexport function readSync(fd: number, buffer: Buffer, opts?: ReadSyncOptions | number, length?: number, position?: number): number {\n\tconst file = fd2file(fd);\n\tlet offset = opts as number;\n\tif (typeof opts == 'object') {\n\t\t({ offset, length, position } = opts);\n\t}\n\n\tif (isNaN(+position)) {\n\t\tposition = file.getPos()!;\n\t}\n\n\treturn file.readSync(buffer, offset, length, position);\n}\n\n/**\n * Synchronous `fchown`.\n * @param fd\n * @param uid\n * @param gid\n */\nexport function fchownSync(fd: number, uid: number, gid: number): void {\n\tfd2file(fd).chownSync(uid, gid);\n}\n\n/**\n * Synchronous `fchmod`.\n * @param fd\n * @param mode\n */\nexport function fchmodSync(fd: number, mode: number | string): void {\n\tconst numMode = typeof mode === 'string' ? parseInt(mode, 8) : mode;\n\tfd2file(fd).chmodSync(numMode);\n}\n\n/**\n * Change the file timestamps of a file referenced by the supplied file\n * descriptor.\n * @param fd\n * @param atime\n * @param mtime\n */\nexport function futimesSync(fd: number, atime: number | Date, mtime: number | Date): void {\n\tfd2file(fd).utimesSync(normalizeTime(atime), normalizeTime(mtime));\n}\n\n// DIRECTORY-ONLY METHODS\n\n/**\n * Synchronous `rmdir`.\n * @param path\n */\nexport function rmdirSync(path: string): void {\n\treturn doOp('rmdirSync', true, path, cred);\n}\n\n/**\n * Synchronous `mkdir`.\n * @param path\n * @param mode defaults to `0777`\n */\nexport function mkdirSync(path: string, mode?: number | string): void {\n\tdoOp('mkdirSync', true, path, normalizeMode(mode, 0o777), cred);\n}\n\n/**\n * Synchronous `readdir`. Reads the contents of a directory.\n * @param path\n * @return [String[]]\n */\nexport function readdirSync(path: string): string[] {\n\tpath = normalizePath(path);\n\tconst entries: string[] = doOp('readdirSync', true, path, cred);\n\tconst points = [...mounts.keys()];\n\tfor (const point of points) {\n\t\tif (point.startsWith(path)) {\n\t\t\tconst entry = point.slice(path.length);\n\t\t\tif (entry.includes('/') || entry.length == 0) {\n\t\t\t\t// ignore FSs mounted in subdirectories and any FS mounted to `path`.\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tentries.push(entry);\n\t\t}\n\t}\n\treturn entries;\n}\n\n// SYMLINK METHODS\n\n/**\n * Synchronous `link`.\n * @param srcpath\n * @param dstpath\n */\nexport function linkSync(srcpath: string, dstpath: string): void {\n\tdstpath = normalizePath(dstpath);\n\treturn doOp('linkSync', false, srcpath, dstpath, cred);\n}\n\n/**\n * Synchronous `symlink`.\n * @param srcpath\n * @param dstpath\n * @param type can be either `'dir'` or `'file'` (default is `'file'`)\n */\nexport function symlinkSync(srcpath: string, dstpath: string, type?: symlink.Type): void {\n\tif (!['file', 'dir', 'junction'].includes(type)) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, 'Invalid type: ' + type);\n\t}\n\tdstpath = normalizePath(dstpath);\n\treturn doOp('symlinkSync', false, srcpath, dstpath, type, cred);\n}\n\n/**\n * Synchronous readlink.\n * @param path\n * @return [String]\n */\nexport function readlinkSync(path: string): string {\n\treturn doOp('readlinkSync', false, path, cred);\n}\n\n// PROPERTY OPERATIONS\n\n/**\n * Synchronous `chown`.\n * @param path\n * @param uid\n * @param gid\n */\nexport function chownSync(path: string, uid: number, gid: number): void {\n\tdoOp('chownSync', true, path, uid, gid, cred);\n}\n\n/**\n * Synchronous `lchown`.\n * @param path\n * @param uid\n * @param gid\n */\nexport function lchownSync(path: string, uid: number, gid: number): void {\n\tdoOp('chownSync', false, path, uid, gid, cred);\n}\n\n/**\n * Synchronous `chmod`.\n * @param path\n * @param mode\n */\nexport function chmodSync(path: string, mode: string | number): void {\n\tconst numMode = normalizeMode(mode, -1);\n\tif (numMode < 0) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, `Invalid mode.`);\n\t}\n\tdoOp('chmodSync', true, path, numMode, cred);\n}\n\n/**\n * Synchronous `lchmod`.\n * @param path\n * @param mode\n */\nexport function lchmodSync(path: string, mode: number | string): void {\n\tconst numMode = normalizeMode(mode, -1);\n\tif (numMode < 1) {\n\t\tthrow new ApiError(ErrorCode.EINVAL, `Invalid mode.`);\n\t}\n\tdoOp('chmodSync', false, path, numMode, cred);\n}\n\n/**\n * Change file timestamps of the file referenced by the supplied path.\n * @param path\n * @param atime\n * @param mtime\n */\nexport function utimesSync(path: string, atime: number | Date, mtime: number | Date): void {\n\tdoOp('utimesSync', true, path, normalizeTime(atime), normalizeTime(mtime), cred);\n}\n\n/**\n * Change file timestamps of the file referenced by the supplied path.\n * @param path\n * @param atime\n * @param mtime\n */\nexport function lutimesSync(path: string, atime: number | Date, mtime: number | Date): void {\n\tdoOp('utimesSync', false, path, normalizeTime(atime), normalizeTime(mtime), cred);\n}\n\n/**\n * Synchronous `realpath`.\n * @param path\n * @param cache An object literal of mapped paths that can be used to\n * force a specific path resolution or avoid additional `fs.stat` calls for\n * known real paths.\n * @return [String]\n */\nexport function realpathSync(path: string, cache: { [path: string]: string } = {}): string {\n\tpath = normalizePath(path);\n\tconst { fs, path: resolvedPath, mountPoint } = resolveFS(path);\n\ttry {\n\t\tconst stats = fs.statSync(resolvedPath, cred);\n\t\tif (!stats.isSymbolicLink()) {\n\t\t\treturn path;\n\t\t}\n\t\tconst dst = normalizePath(mountPoint + fs.readlinkSync(resolvedPath, cred));\n\t\treturn realpathSync(dst);\n\t} catch (e) {\n\t\tthrow fixError(e, { [resolvedPath]: path });\n\t}\n}\n\n/**\n * Synchronous `access`.\n * @param path\n * @param mode\n */\nexport function accessSync(path: string, mode: number = 0o600): void {\n\treturn doOp('accessSync', true, path, mode, cred);\n}\n", "import * as fs_mock from './index.js';\nimport type * as fs_node from 'node:fs';\n\ntype ZenFSModule = typeof fs_node & typeof fs_mock;\n// @ts-expect-error 2322\nconst fs: ZenFSModule = fs_mock;\n\nexport * from './index.js';\nexport default fs;\n", "import { type FileSystem, SynchronousFileSystem, FileSystemMetadata } from '../filesystem.js';\nimport { ApiError, ErrorCode } from '../ApiError.js';\nimport { File, FileFlag, PreloadFile } from '../file.js';\nimport { Stats } from '../stats.js';\nimport * as path from 'path';\nimport { Cred } from '../cred.js';\nimport { CreateBackend, type BackendOptions } from './backend.js';\n\n/**\n * @internal\n */\ninterface AsyncOperation {\n\tapiMethod: string;\n\targuments: any[];\n}\n\n/**\n * We define our own file to interpose on syncSync() for mirroring purposes.\n */\nclass MirrorFile extends PreloadFile<AsyncMirror> implements File {\n\tconstructor(fs: AsyncMirror, path: string, flag: FileFlag, stat: Stats, data: Buffer) {\n\t\tsuper(fs, path, flag, stat, data);\n\t}\n\n\tpublic syncSync(): void {\n\t\tif (this.isDirty()) {\n\t\t\tthis._fs._syncSync(this);\n\t\t\tthis.resetDirty();\n\t\t}\n\t}\n\n\tpublic closeSync(): void {\n\t\tthis.syncSync();\n\t}\n}\n\nexport namespace AsyncMirror {\n\t/**\n\t * Configuration options for the AsyncMirror file system.\n\t */\n\texport interface Options {\n\t\t/**\n\t\t * The synchronous file system to mirror the asynchronous file system to.\n\t\t */\n\t\tsync: FileSystem;\n\t\t/**\n\t\t * The asynchronous file system to mirror.\n\t\t */\n\t\tasync: FileSystem;\n\t}\n}\n\n/**\n * AsyncMirrorFS mirrors a synchronous filesystem into an asynchronous filesystem\n * by:\n *\n * * Performing operations over the in-memory copy, while asynchronously pipelining them\n * to the backing store.\n * * During application loading, the contents of the async file system can be reloaded into\n * the synchronous store, if desired.\n *\n * The two stores will be kept in sync. The most common use-case is to pair a synchronous\n * in-memory filesystem with an asynchronous backing store.\n *\n * Example: Mirroring an IndexedDB file system to an in memory file system. Now, you can use\n * IndexedDB synchronously.\n *\n * ```javascript\n * ZenFS.configure({\n * fs: \"AsyncMirror\",\n * options: {\n * sync: { fs: \"InMemory\" },\n * async: { fs: \"IndexedDB\" }\n * }\n * }, function(e) {\n * // ZenFS is initialized and ready-to-use!\n * });\n * ```\n *\n * Or, alternatively:\n *\n * ```javascript\n * ZenFS.Backend.IndexedDB.Create(function(e, idbfs) {\n * ZenFS.Backend.InMemory.Create(function(e, inMemory) {\n * ZenFS.Backend.AsyncMirror({\n * sync: inMemory, async: idbfs\n * }, function(e, mirrored) {\n * ZenFS.initialize(mirrored);\n * });\n * });\n * });\n * ```\n */\nexport class AsyncMirror extends SynchronousFileSystem {\n\tpublic static readonly Name = 'AsyncMirror';\n\n\tpublic static Create = CreateBackend.bind(this);\n\n\tpublic static readonly Options: BackendOptions = {\n\t\tsync: {\n\t\t\ttype: 'object',\n\t\t\tdescription: 'The synchronous file system to mirror the asynchronous file system to.',\n\t\t\tvalidator: async (v: FileSystem): Promise<void> => {\n\t\t\t\tif (!v?.metadata.synchronous) {\n\t\t\t\t\tthrow new ApiError(ErrorCode.EINVAL, `'sync' option must be a file system that supports synchronous operations`);\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\tasync: {\n\t\t\ttype: 'object',\n\t\t\tdescription: 'The asynchronous file system to mirror.',\n\t\t},\n\t};\n\n\tpublic static isAvailable(): boolean {\n\t\treturn true;\n\t}\n\n\t/**\n\t * Queue of pending asynchronous operations.\n\t */\n\tprivate _queue: AsyncOperation[] = [];\n\tprivate _queueRunning: boolean = false;\n\tprivate _sync: FileSystem;\n\tprivate _async: FileSystem;\n\tprivate _isInitialized: boolean = false;\n\tprivate _initializeCallbacks: ((e?: ApiError) => void)[] = [];\n\n\t/**\n\t *\n\t * Mirrors the synchronous file system into the asynchronous file system.\n\t *\n\t * @param sync The synchronous file system to mirror the asynchronous file system to.\n\t * @param async The asynchronous file system to mirror.\n\t */\n\tconstructor({ sync, async }: AsyncMirror.Options) {\n\t\tsuper();\n\t\tthis._sync = sync;\n\t\tthis._async = async;\n\t\tthis._ready = this._initialize();\n\t}\n\n\tpublic get metadata(): FileSystemMetadata {\n\t\treturn {\n\t\t\t...super.metadata,\n\t\t\tname: AsyncMirror.Name,\n\t\t\tsynchronous: true,\n\t\t\tsupportsProperties: this._sync.metadata.supportsProperties && this._async.metadata.supportsProperties,\n\t\t};\n\t}\n\n\tpublic _syncSync(fd: PreloadFile<AsyncMirror>) {\n\t\tconst stats = fd.getStats();\n\t\tthis._sync.writeFileSync(fd.getPath(), fd.getBuffer(), null, FileFlag.getFileFlag('w'), stats.mode, stats.getCred(0, 0));\n\t\tthis.enqueueOp({\n\t\t\tapiMethod: 'writeFile',\n\t\t\targuments: [fd.getPath(), fd.getBuffer(), null, fd.getFlag(), stats.mode, stats.getCred(0, 0)],\n\t\t});\n\t}\n\n\tpublic renameSync(oldPath: string, newPath: string, cred: Cred): void {\n\t\tthis._sync.renameSync(oldPath, newPath, cred);\n\t\tthis.enqueueOp({\n\t\t\tapiMethod: 'rename',\n\t\t\targuments: [oldPath, newPath, cred],\n\t\t});\n\t}\n\n\tpublic statSync(p: string, cred: Cred): Stats {\n\t\treturn this._sync.statSync(p, cred);\n\t}\n\n\tpublic openSync(p: string, flag: FileFlag, mode: number, cred: Cred): File {\n\t\t// Sanity check: Is this open/close permitted?\n\t\tconst fd = this._sync.openSync(p, flag, mode, cred);\n\t\tfd.closeSync();\n\t\treturn new MirrorFile(this, p, flag, this._sync.statSync(p, cred), <Buffer>this._sync.readFileSync(p, null, FileFlag.getFileFlag('r'), cred));\n\t}\n\n\tpublic unlinkSync(p: string, cred: Cred): void {\n\t\tthis._sync.unlinkSync(p, cred);\n\t\tthis.enqueueOp({\n\t\t\tapiMethod: 'unlink',\n\t\t\targuments: [p, cred],\n\t\t});\n\t}\n\n\tpublic rmdirSync(p: string, cred: Cred): void {\n\t\tthis._sync.rmdirSync(p, cred);\n\t\tthis.enqueueOp({\n\t\t\tapiMethod: 'rmdir',\n\t\t\targuments: [p, cred],\n\t\t});\n\t}\n\n\tpublic mkdirSync(p: string, mode: number, cred: Cred): void {\n\t\tthis._sync.mkdirSync(p, mode, cred);\n\t\tthis.enqueueOp({\n\t\t\tapiMethod: 'mkdir',\n\t\t\targuments: [p, mode, cred],\n\t\t});\n\t}\n\n\tpublic readdirSync(p: string, cred: Cred): string[] {\n\t\treturn this._sync.readdirSync(p, cred);\n\t}\n\n\tpublic existsSync(p: string, cred: Cred): boolean {\n\t\treturn this._sync.existsSync(p, cred);\n\t}\n\n\tpublic chmodSync(p: string, mode: number, cred: Cred): void {\n\t\tthis._sync.chmodSync(p, mode, cred);\n\t\tthis.enqueueOp({\n\t\t\tapiMethod: 'chmod',\n\t\t\targuments: [p, mode, cred],\n\t\t});\n\t}\n\n\tpublic chownSync(p: string, new_uid: number, new_gid: number, cred: Cred): void {\n\t\tthis._sync.chownSync(p, new_uid, new_gid, cred);\n\t\tthis.enqueueOp({\n\t\t\tapiMethod: 'chown',\n\t\t\targuments: [p, new_uid, new_gid, cred],\n\t\t});\n\t}\n\n\tpublic utimesSync(p: string, atime: Date, mtime: Date, cred: Cred): void {\n\t\tthis._sync.utimesSync(p, atime, mtime, cred);\n\t\tthis.enqueueOp({\n\t\t\tapiMethod: 'utimes',\n\t\t\targuments: [p, atime, mtime, cred],\n\t\t});\n\t}\n\n\t/**\n\t * Called once to load up files from async storage into sync storage.\n\t */\n\tprivate async _initialize(): Promise<this> {\n\t\tif (!this._isInitialized) {\n\t\t\t// First call triggers initialization, the rest wait.\n\t\t\tconst copyDirectory = async (p: string, mode: number): Promise<void> => {\n\t\t\t\t\tif (p !== '/') {\n\t\t\t\t\t\tconst stats = await this._async.stat(p, Cred.Root);\n\t\t\t\t\t\tthis._sync.mkdirSync(p, mode, stats.getCred());\n\t\t\t\t\t}\n\t\t\t\t\tconst files = await this._async.readdir(p, Cred.Root);\n\t\t\t\t\tfor (const file of files) {\n\t\t\t\t\t\tawait copyItem(path.join(p, file));\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tcopyFile = async (p: string, mode: number): Promise<void> => {\n\t\t\t\t\tconst data = await this._async.readFile(p, null, FileFlag.getFileFlag('r'), Cred.Root);\n\t\t\t\t\tthis._sync.writeFileSync(p, data, null, FileFlag.getFileFlag('w'), mode, Cred.Root);\n\t\t\t\t},\n\t\t\t\tcopyItem = async (p: string): Promise<void> => {\n\t\t\t\t\tconst stats = await this._async.stat(p, Cred.Root);\n\t\t\t\t\tif (stats.isDirectory()) {\n\t\t\t\t\t\tawait copyDirectory(p, stats.mode);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tawait copyFile(p, stats.mode);\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\ttry {\n\t\t\t\tawait copyDirectory('/', 0);\n\t\t\t\tthis._isInitialized = true;\n\t\t\t} catch (e) {\n\t\t\t\tthis._isInitialized = false;\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\tprivate enqueueOp(op: AsyncOperation) {\n\t\tthis._queue.push(op);\n\t\tif (!this._queueRunning) {\n\t\t\tthis._queueRunning = true;\n\t\t\tconst doNextOp = (err?: ApiError) => {\n\t\t\t\tif (err) {\n\t\t\t\t\tthrow new Error(`WARNING: File system has desynchronized. Received following error: ${err}\\n$`);\n\t\t\t\t}\n\t\t\t\tif (this._queue.length > 0) {\n\t\t\t\t\tconst op = this._queue.shift()!;\n\t\t\t\t\top.arguments.push(doNextOp);\n\t\t\t\t\t(<Function>this._async[op.apiMethod]).apply(this._async, op.arguments);\n\t\t\t\t} else {\n\t\t\t\t\tthis._queueRunning = false;\n\t\t\t\t}\n\t\t\t};\n\t\t\tdoNextOp();\n\t\t}\n\t}\n}\n", "import { BaseFileSystem, type FileSystem } from '../filesystem.js';\nimport * as path from 'path';\nimport { ApiError } from '../ApiError.js';\nimport { Cred } from '../cred.js';\nimport { CreateBackend, type BackendOptions } from './backend.js';\n\nexport namespace FolderAdapter {\n\t/**\n\t * Configuration options for a FolderAdapter file system.\n\t */\n\texport interface Options {\n\t\t// The folder to use as the root directory.\n\t\tfolder: string;\n\t\t// The file system to wrap.\n\t\twrapped: FileSystem;\n\t}\n}\n\n/**\n * The FolderAdapter file system wraps a file system, and scopes all interactions to a subfolder of that file system.\n *\n * Example: Given a file system `foo` with folder `bar` and file `bar/baz`...\n *\n * ```javascript\n * ZenFS.configure({\n * fs: \"FolderAdapter\",\n * options: {\n * folder: \"bar\",\n * wrapped: foo\n * }\n * }, function(e) {\n * var fs = ZenFS.BFSRequire('fs');\n * fs.readdirSync('/'); // ['baz']\n * });\n * ```\n */\nexport class FolderAdapter extends BaseFileSystem {\n\tpublic static readonly Name = 'FolderAdapter';\n\n\tpublic static Create = CreateBackend.bind(this);\n\n\tpublic static readonly Options: BackendOptions = {\n\t\tfolder: {\n\t\t\ttype: 'string',\n\t\t\tdescription: 'The folder to use as the root directory',\n\t\t},\n\t\twrapped: {\n\t\t\ttype: 'object',\n\t\t\tdescription: 'The file system to wrap',\n\t\t},\n\t};\n\n\tpublic static isAvailable(): boolean {\n\t\treturn true;\n\t}\n\n\tpublic _wrapped: FileSystem;\n\tpublic _folder: string;\n\n\tpublic constructor({ folder, wrapped }: FolderAdapter.Options) {\n\t\tsuper();\n\t\tthis._folder = folder;\n\t\tthis._wrapped = wrapped;\n\t\tthis._ready = this._initialize();\n\t}\n\n\tpublic get metadata() {\n\t\treturn { ...super.metadata, ...this._wrapped.metadata, supportsLinks: false };\n\t}\n\n\t/**\n\t * Initialize the file system. Ensures that the wrapped file system\n\t * has the given folder.\n\t */\n\tprivate async _initialize(): Promise<this> {\n\t\tconst exists = await this._wrapped.exists(this._folder, Cred.Root);\n\t\tif (!exists && this._wrapped.metadata.readonly) {\n\t\t\tthrow ApiError.ENOENT(this._folder);\n\t\t}\n\t\tawait this._wrapped.mkdir(this._folder, 0o777, Cred.Root);\n\t\treturn this;\n\t}\n}\n\n/**\n * @internal\n */\nfunction translateError(folder: string, e: any): any {\n\tif (e !== null && typeof e === 'object') {\n\t\tconst err = <ApiError>e;\n\t\tlet p = err.path;\n\t\tif (p) {\n\t\t\tp = '/' + path.relative(folder, p);\n\t\t\terr.message = err.message.replace(err.path!, p);\n\t\t\terr.path = p;\n\t\t}\n\t}\n\treturn e;\n}\n\n/**\n * @internal\n */\nfunction wrapCallback(folder: string, cb: any): any {\n\tif (typeof cb === 'function') {\n\t\treturn function (err: ApiError) {\n\t\t\tif (arguments.length > 0) {\n\t\t\t\targuments[0] = translateError(folder, err);\n\t\t\t}\n\t\t\t(<Function>cb).apply(null, arguments);\n\t\t};\n\t} else {\n\t\treturn cb;\n\t}\n}\n\n/**\n * @internal\n */\nfunction wrapFunction(name: string, wrapFirst: boolean, wrapSecond: boolean): Function {\n\tif (name.slice(name.length - 4) !== 'Sync') {\n\t\t// Async function. Translate error in callback.\n\t\treturn function (this: FolderAdapter) {\n\t\t\tif (arguments.length > 0) {\n\t\t\t\tif (wrapFirst) {\n\t\t\t\t\targuments[0] = path.join(this._folder, arguments[0]);\n\t\t\t\t}\n\t\t\t\tif (wrapSecond) {\n\t\t\t\t\targuments[1] = path.join(this._folder, arguments[1]);\n\t\t\t\t}\n\t\t\t\targuments[arguments.length - 1] = wrapCallback(this._folder, arguments[arguments.length - 1]);\n\t\t\t}\n\t\t\treturn (<any>this._wrapped)[name].apply(this._wrapped, arguments);\n\t\t};\n\t} else {\n\t\t// Sync function. Translate error in catch.\n\t\treturn function (this: FolderAdapter) {\n\t\t\ttry {\n\t\t\t\tif (wrapFirst) {\n\t\t\t\t\targuments[0] = path.join(this._folder, arguments[0]);\n\t\t\t\t}\n\t\t\t\tif (wrapSecond) {\n\t\t\t\t\targuments[1] = path.join(this._folder, arguments[1]);\n\t\t\t\t}\n\t\t\t\treturn (<any>this._wrapped)[name].apply(this._wrapped, arguments);\n\t\t\t} catch (e) {\n\t\t\t\tthrow translateError(this._folder, e);\n\t\t\t}\n\t\t};\n\t}\n}\n\n// First argument is a path.\n[\n\t'diskSpace',\n\t'stat',\n\t'statSync',\n\t'open',\n\t'openSync',\n\t'unlink',\n\t'unlinkSync',\n\t'rmdir',\n\t'rmdirSync',\n\t'mkdir',\n\t'mkdirSync',\n\t'readdir',\n\t'readdirSync',\n\t'exists',\n\t'existsSync',\n\t'realpath',\n\t'realpathSync',\n\t'truncate',\n\t'truncateSync',\n\t'readFile',\n\t'readFileSync',\n\t'writeFile',\n\t'writeFileSync',\n\t'appendFile',\n\t'appendFileSync',\n\t'chmod',\n\t'chmodSync',\n\t'chown',\n\t'chownSync',\n\t'utimes',\n\t'utimesSync',\n\t'readlink',\n\t'readlinkSync',\n].forEach((name: string) => {\n\t(<any>FolderAdapter.prototype)[name] = wrapFunction(name, true, false);\n});\n\n// First and second arguments are paths.\n['rename', 'renameSync', 'link', 'linkSync', 'symlink', 'symlinkSync'].forEach((name: string) => {\n\t(<any>FolderAdapter.prototype)[name] = wrapFunction(name, true, true);\n});\n", "export type MutexCallback = () => void;\n\n/**\n * Non-recursive mutex\n * @internal\n */\nexport default class Mutex {\n\tprivate _locks: Map<string, MutexCallback[]> = new Map();\n\n\tpublic lock(path: string): Promise<void> {\n\t\treturn new Promise(resolve => {\n\t\t\tif (this._locks.has(path)) {\n\t\t\t\tthis._locks.get(path).push(resolve);\n\t\t\t} else {\n\t\t\t\tthis._locks.set(path, []);\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic unlock(path: string): void {\n\t\tif (!this._locks.has(path)) {\n\t\t\tthrow new Error('unlock of a non-locked mutex');\n\t\t}\n\n\t\tconst next = this._locks.get(path).shift();\n\t\t/* \n\t\t\tdon't unlock - we want to queue up next for the\n\t\t\tend of the current task execution, but we don't\n\t\t\twant it to be called inline with whatever the\n\t\t\tcurrent stack is. This way we still get the nice\n\t\t\tbehavior that an unlock immediately followed by a\n\t\t\tlock won't cause starvation.\n\t\t*/\n\t\tif (next) {\n\t\t\tsetTimeout(next, 0);\n\t\t\treturn;\n\t\t}\n\n\t\tthis._locks.delete(path);\n\t}\n\n\tpublic tryLock(path: string): boolean {\n\t\tif (this._locks.has(path)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tthis._locks.set(path, []);\n\t\treturn true;\n\t}\n\n\tpublic isLocked(path: string): boolean {\n\t\treturn this._locks.has(path);\n\t}\n}\n", "import Mutex from '../mutex.js';\nimport { FileContents, FileSystem, FileSystemMetadata } from '../filesystem.js';\nimport { FileFlag } from '../file.js';\nimport { Stats } from '../stats.js';\nimport { File } from '../file.js';\nimport { Cred } from '../cred.js';\n\n/**\n * This class serializes access to an underlying async filesystem.\n * For example, on an OverlayFS instance with an async lower\n * directory operations like rename and rmdir may involve multiple\n * requests involving both the upper and lower filesystems -- they\n * are not executed in a single atomic step. OverlayFS uses this\n * LockedFS to avoid having to reason about the correctness of\n * multiple requests interleaving.\n */\nexport default class LockedFS<T extends FileSystem> implements FileSystem {\n\tprivate _fs: T;\n\tprivate _mu: Mutex;\n\n\tprotected _ready: Promise<this> = Promise.resolve(this);\n\n\tconstructor(fs: T) {\n\t\tthis._fs = fs;\n\t\tthis._mu = new Mutex();\n\t}\n\n\twhenReady(): Promise<this> {\n\t\treturn this._ready;\n\t}\n\n\tpublic get metadata(): FileSystemMetadata {\n\t\treturn {\n\t\t\t...this._fs.metadata,\n\t\t\tname: 'LockedFS<' + this._fs.metadata.name + '>',\n\t\t};\n\t}\n\n\tpublic get fs(): T {\n\t\treturn this._fs;\n\t}\n\n\tpublic async rename(oldPath: string, newPath: string, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(oldPath);\n\t\tawait this._fs.rename(oldPath, newPath, cred);\n\t\tthis._mu.unlock(oldPath);\n\t}\n\n\tpublic renameSync(oldPath: string, newPath: string, cred: Cred): void {\n\t\tif (this._mu.isLocked(oldPath)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.renameSync(oldPath, newPath, cred);\n\t}\n\n\tpublic async stat(p: string, cred: Cred): Promise<Stats> {\n\t\tawait this._mu.lock(p);\n\t\tconst stats = await this._fs.stat(p, cred);\n\t\tthis._mu.unlock(p);\n\t\treturn stats;\n\t}\n\n\tpublic statSync(p: string, cred: Cred): Stats {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.statSync(p, cred);\n\t}\n\n\tpublic async access(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(p);\n\t\tawait this._fs.access(p, mode, cred);\n\t\tthis._mu.unlock(p);\n\t}\n\n\tpublic accessSync(p: string, mode: number, cred: Cred): void {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.accessSync(p, mode, cred);\n\t}\n\n\tpublic async open(p: string, flag: FileFlag, mode: number, cred: Cred): Promise<File> {\n\t\tawait this._mu.lock(p);\n\t\tconst fd = await this._fs.open(p, flag, mode, cred);\n\t\tthis._mu.unlock(p);\n\t\treturn fd;\n\t}\n\n\tpublic openSync(p: string, flag: FileFlag, mode: number, cred: Cred): File {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.openSync(p, flag, mode, cred);\n\t}\n\n\tpublic async unlink(p: string, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(p);\n\t\tawait this._fs.unlink(p, cred);\n\t\tthis._mu.unlock(p);\n\t}\n\n\tpublic unlinkSync(p: string, cred: Cred): void {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.unlinkSync(p, cred);\n\t}\n\n\tpublic async rmdir(p: string, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(p);\n\t\tawait this._fs.rmdir(p, cred);\n\t\tthis._mu.unlock(p);\n\t}\n\n\tpublic rmdirSync(p: string, cred: Cred): void {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.rmdirSync(p, cred);\n\t}\n\n\tpublic async mkdir(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(p);\n\t\tawait this._fs.mkdir(p, mode, cred);\n\t\tthis._mu.unlock(p);\n\t}\n\n\tpublic mkdirSync(p: string, mode: number, cred: Cred): void {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.mkdirSync(p, mode, cred);\n\t}\n\n\tpublic async readdir(p: string, cred: Cred): Promise<string[]> {\n\t\tawait this._mu.lock(p);\n\t\tconst files = await this._fs.readdir(p, cred);\n\t\tthis._mu.unlock(p);\n\t\treturn files;\n\t}\n\n\tpublic readdirSync(p: string, cred: Cred): string[] {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.readdirSync(p, cred);\n\t}\n\n\tpublic async exists(p: string, cred: Cred): Promise<boolean> {\n\t\tawait this._mu.lock(p);\n\t\tconst exists = await this._fs.exists(p, cred);\n\t\tthis._mu.unlock(p);\n\t\treturn exists;\n\t}\n\n\tpublic existsSync(p: string, cred: Cred): boolean {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.existsSync(p, cred);\n\t}\n\n\tpublic async realpath(p: string, cred: Cred): Promise<string> {\n\t\tawait this._mu.lock(p);\n\t\tconst resolvedPath = await this._fs.realpath(p, cred);\n\t\tthis._mu.unlock(p);\n\t\treturn resolvedPath;\n\t}\n\n\tpublic realpathSync(p: string, cred: Cred): string {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.realpathSync(p, cred);\n\t}\n\n\tpublic async truncate(p: string, len: number, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(p);\n\t\tawait this._fs.truncate(p, len, cred);\n\t\tthis._mu.unlock(p);\n\t}\n\n\tpublic truncateSync(p: string, len: number, cred: Cred): void {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.truncateSync(p, len, cred);\n\t}\n\n\tpublic async readFile(fname: string, encoding: BufferEncoding, flag: FileFlag, cred: Cred): Promise<FileContents> {\n\t\tawait this._mu.lock(fname);\n\t\tconst data = await this._fs.readFile(fname, encoding, flag, cred);\n\t\tthis._mu.unlock(fname);\n\t\treturn data;\n\t}\n\n\tpublic readFileSync(fname: string, encoding: BufferEncoding, flag: FileFlag, cred: Cred): FileContents {\n\t\tif (this._mu.isLocked(fname)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.readFileSync(fname, encoding, flag, cred);\n\t}\n\n\tpublic async writeFile(fname: string, data: FileContents, encoding: BufferEncoding, flag: FileFlag, mode: number, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(fname);\n\t\tawait this._fs.writeFile(fname, data, encoding, flag, mode, cred);\n\t\tthis._mu.unlock(fname);\n\t}\n\n\tpublic writeFileSync(fname: string, data: FileContents, encoding: BufferEncoding, flag: FileFlag, mode: number, cred: Cred): void {\n\t\tif (this._mu.isLocked(fname)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.writeFileSync(fname, data, encoding, flag, mode, cred);\n\t}\n\n\tpublic async appendFile(fname: string, data: FileContents, encoding: BufferEncoding, flag: FileFlag, mode: number, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(fname);\n\t\tawait this._fs.appendFile(fname, data, encoding, flag, mode, cred);\n\t\tthis._mu.unlock(fname);\n\t}\n\n\tpublic appendFileSync(fname: string, data: FileContents, encoding: BufferEncoding, flag: FileFlag, mode: number, cred: Cred): void {\n\t\tif (this._mu.isLocked(fname)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.appendFileSync(fname, data, encoding, flag, mode, cred);\n\t}\n\n\tpublic async chmod(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(p);\n\t\tawait this._fs.chmod(p, mode, cred);\n\t\tthis._mu.unlock(p);\n\t}\n\n\tpublic chmodSync(p: string, mode: number, cred: Cred): void {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.chmodSync(p, mode, cred);\n\t}\n\n\tpublic async chown(p: string, new_uid: number, new_gid: number, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(p);\n\t\tawait this._fs.chown(p, new_uid, new_gid, cred);\n\t\tthis._mu.unlock(p);\n\t}\n\n\tpublic chownSync(p: string, new_uid: number, new_gid: number, cred: Cred): void {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.chownSync(p, new_uid, new_gid, cred);\n\t}\n\n\tpublic async utimes(p: string, atime: Date, mtime: Date, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(p);\n\t\tawait this._fs.utimes(p, atime, mtime, cred);\n\t\tthis._mu.unlock(p);\n\t}\n\n\tpublic utimesSync(p: string, atime: Date, mtime: Date, cred: Cred): void {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.utimesSync(p, atime, mtime, cred);\n\t}\n\n\tpublic async link(srcpath: string, dstpath: string, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(srcpath);\n\t\tawait this._fs.link(srcpath, dstpath, cred);\n\t\tthis._mu.unlock(srcpath);\n\t}\n\n\tpublic linkSync(srcpath: string, dstpath: string, cred: Cred): void {\n\t\tif (this._mu.isLocked(srcpath)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.linkSync(srcpath, dstpath, cred);\n\t}\n\n\tpublic async symlink(srcpath: string, dstpath: string, type: string, cred: Cred): Promise<void> {\n\t\tawait this._mu.lock(srcpath);\n\t\tawait this._fs.symlink(srcpath, dstpath, type, cred);\n\t\tthis._mu.unlock(srcpath);\n\t}\n\n\tpublic symlinkSync(srcpath: string, dstpath: string, type: string, cred: Cred): void {\n\t\tif (this._mu.isLocked(srcpath)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.symlinkSync(srcpath, dstpath, type, cred);\n\t}\n\n\tpublic async readlink(p: string, cred: Cred): Promise<string> {\n\t\tawait this._mu.lock(p);\n\t\tconst linkString = await this._fs.readlink(p, cred);\n\t\tthis._mu.unlock(p);\n\t\treturn linkString;\n\t}\n\n\tpublic readlinkSync(p: string, cred: Cred): string {\n\t\tif (this._mu.isLocked(p)) {\n\t\t\tthrow new Error('invalid sync call');\n\t\t}\n\t\treturn this._fs.readlinkSync(p, cred);\n\t}\n}\n", "import { type FileSystem, BaseFileSystem, FileSystemMetadata } from '../filesystem.js';\nimport { ApiError, ErrorCode } from '../ApiError.js';\nimport { File, FileFlag, ActionType, PreloadFile } from '../file.js';\nimport { Stats } from '../stats.js';\nimport LockedFS from './Locked.js';\nimport * as path from 'path';\nimport { Cred } from '../cred.js';\nimport type { Buffer } from 'buffer';\nimport { CreateBackend, type BackendOptions } from './backend.js';\n/**\n * @internal\n */\nconst deletionLogPath = '/.deletedFiles.log';\n\n/**\n * Given a read-only mode, makes it writable.\n * @internal\n */\nfunction makeModeWritable(mode: number): number {\n\treturn 0o222 | mode;\n}\n\n/**\n * @internal\n */\nfunction getFlag(f: string): FileFlag {\n\treturn FileFlag.getFileFlag(f);\n}\n\n/**\n * Overlays a RO file to make it writable.\n */\nclass OverlayFile extends PreloadFile<UnlockedOverlayFS> implements File {\n\tconstructor(fs: UnlockedOverlayFS, path: string, flag: FileFlag, stats: Stats, data: Buffer) {\n\t\tsuper(fs, path, flag, stats, data);\n\t}\n\n\tpublic async sync(): Promise<void> {\n\t\tif (!this.isDirty()) {\n\t\t\treturn;\n\t\t}\n\n\t\tawait this._fs._syncAsync(this);\n\t\tthis.resetDirty();\n\t}\n\n\tpublic syncSync(): void {\n\t\tif (this.isDirty()) {\n\t\t\tthis._fs._syncSync(this);\n\t\t\tthis.resetDirty();\n\t\t}\n\t}\n\n\tpublic async close(): Promise<void> {\n\t\tawait this.sync();\n\t}\n\n\tpublic closeSync(): void {\n\t\tthis.syncSync();\n\t}\n}\n\nexport namespace OverlayFS {\n\t/**\n\t * Configuration options for OverlayFS instances.\n\t */\n\texport interface Options {\n\t\t/**\n\t\t * The file system to write modified files to.\n\t\t */\n\t\twritable: FileSystem;\n\t\t/**\n\t\t * The file system that initially populates this file system.\n\t\t */\n\t\treadable: FileSystem;\n\t}\n}\n\n/**\n * *INTERNAL, DO NOT USE DIRECTLY!*\n *\n * Core OverlayFS class that contains no locking whatsoever. We wrap these objects\n * in a LockedFS to prevent races.\n */\nexport class UnlockedOverlayFS extends BaseFileSystem {\n\tpublic static isAvailable(): boolean {\n\t\treturn true;\n\t}\n\n\tprivate _writable: FileSystem;\n\tprivate _readable: FileSystem;\n\tprivate _isInitialized: boolean = false;\n\tprivate _deletedFiles: { [path: string]: boolean } = {};\n\tprivate _deleteLog: string = '';\n\t// If 'true', we have scheduled a delete log update.\n\tprivate _deleteLogUpdatePending: boolean = false;\n\t// If 'true', a delete log update is needed after the scheduled delete log\n\t// update finishes.\n\tprivate _deleteLogUpdateNeeded: boolean = false;\n\t// If there was an error updating the delete log...\n\tprivate _deleteLogError: ApiError | null = null;\n\n\tconstructor({ writable, readable }: OverlayFS.Options) {\n\t\tsuper();\n\t\tthis._writable = writable;\n\t\tthis._readable = readable;\n\t\tif (this._writable.metadata.readonly) {\n\t\t\tthrow new ApiError(ErrorCode.EINVAL, 'Writable file system must be writable.');\n\t\t}\n\t}\n\n\tpublic get metadata(): FileSystemMetadata {\n\t\treturn {\n\t\t\t...super.metadata,\n\t\t\tname: OverlayFS.Name,\n\t\t\tsynchronous: this._readable.metadata.synchronous && this._writable.metadata.synchronous,\n\t\t\tsupportsProperties: this._readable.metadata.supportsProperties && this._writable.metadata.supportsProperties,\n\t\t};\n\t}\n\n\tpublic getOverlayedFileSystems(): { readable: FileSystem; writable: FileSystem } {\n\t\treturn {\n\t\t\treadable: this._readable,\n\t\t\twritable: this._writable,\n\t\t};\n\t}\n\n\tpublic async _syncAsync(file: PreloadFile<UnlockedOverlayFS>): Promise<void> {\n\t\tconst stats = file.getStats();\n\t\tawait this.createParentDirectoriesAsync(file.getPath(), stats.getCred(0, 0));\n\t\treturn this._writable.writeFile(file.getPath(), file.getBuffer(), null, getFlag('w'), stats.mode, stats.getCred(0, 0));\n\t}\n\n\tpublic _syncSync(file: PreloadFile<UnlockedOverlayFS>): void {\n\t\tconst stats = file.getStats();\n\t\tthis.createParentDirectories(file.getPath(), stats.getCred(0, 0));\n\t\tthis._writable.writeFileSync(file.getPath(), file.getBuffer(), null, getFlag('w'), stats.mode, stats.getCred(0, 0));\n\t}\n\n\t/**\n\t * **INTERNAL METHOD**\n\t *\n\t * Called once to load up metadata stored on the writable file system.\n\t */\n\tpublic async _initialize(): Promise<void> {\n\t\t// if we're already initialized, immediately invoke the callback\n\t\tif (this._isInitialized) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Read deletion log, process into metadata.\n\t\ttry {\n\t\t\tconst data = (await this._writable.readFile(deletionLogPath, 'utf8', getFlag('r'), Cred.Root)) as string;\n\t\t\tthis._deleteLog = data;\n\t\t} catch (err) {\n\t\t\tif (err.errno !== ErrorCode.ENOENT) {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t}\n\t\tthis._isInitialized = true;\n\t\tthis._reparseDeletionLog();\n\t}\n\n\tpublic getDeletionLog(): string {\n\t\treturn this._deleteLog;\n\t}\n\n\tpublic restoreDeletionLog(log: string, cred: Cred): void {\n\t\tthis._deleteLog = log;\n\t\tthis._reparseDeletionLog();\n\t\tthis.updateLog('', cred);\n\t}\n\n\tpublic async rename(oldPath: string, newPath: string, cred: Cred): Promise<void> {\n\t\tthis.checkInitialized();\n\t\tthis.checkPath(oldPath);\n\t\tthis.checkPath(newPath);\n\t\tif (oldPath === deletionLogPath || newPath === deletionLogPath) {\n\t\t\tthrow ApiError.EPERM('Cannot rename deletion log.');\n\t\t}\n\t\t// Write newPath using oldPath's contents, delete oldPath.\n\t\tconst oldStats = await this.stat(oldPath, cred);\n\t\tif (oldStats.isDirectory()) {\n\t\t\t// Optimization: Don't bother moving if old === new.\n\t\t\tif (oldPath === newPath) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet mode = 0o777;\n\t\t\tif (await this.exists(newPath, cred)) {\n\t\t\t\tconst stats = await this.stat(newPath, cred);\n\t\t\t\tmode = stats.mode;\n\t\t\t\tif (stats.isDirectory()) {\n\t\t\t\t\tif ((await this.readdir(newPath, cred)).length > 0) {\n\t\t\t\t\t\tthrow ApiError.ENOTEMPTY(newPath);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tthrow ApiError.ENOTDIR(newPath);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Take care of writable first. Move any files there, or create an empty directory\n\t\t\t// if it doesn't exist.\n\t\t\tif (await this._writable.exists(oldPath, cred)) {\n\t\t\t\tawait this._writable.rename(oldPath, newPath, cred);\n\t\t\t} else if (!(await this._writable.exists(newPath, cred))) {\n\t\t\t\tawait this._writable.mkdir(newPath, mode, cred);\n\t\t\t}\n\n\t\t\t// Need to move *every file/folder* currently stored on readable to its new location\n\t\t\t// on writable.\n\t\t\tif (await this._readable.exists(oldPath, cred)) {\n\t\t\t\tfor (const name of await this._readable.readdir(oldPath, cred)) {\n\t\t\t\t\t// Recursion! Should work for any nested files / folders.\n\t\t\t\t\tawait this.rename(path.resolve(oldPath, name), path.resolve(newPath, name), cred);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ((await this.exists(newPath, cred)) && (await this.stat(newPath, cred)).isDirectory()) {\n\t\t\t\tthrow ApiError.EISDIR(newPath);\n\t\t\t}\n\n\t\t\tawait this.writeFile(newPath, await this.readFile(oldPath, null, getFlag('r'), cred), null, getFlag('w'), oldStats.mode, cred);\n\t\t}\n\n\t\tif (oldPath !== newPath && (await this.exists(oldPath, cred))) {\n\t\t\tawait this.unlink(oldPath, cred);\n\t\t}\n\t}\n\n\tpublic renameSync(oldPath: string, newPath: string, cred: Cred): void {\n\t\tthis.checkInitialized();\n\t\tthis.checkPath(oldPath);\n\t\tthis.checkPath(newPath);\n\t\tif (oldPath === deletionLogPath || newPath === deletionLogPath) {\n\t\t\tthrow ApiError.EPERM('Cannot rename deletion log.');\n\t\t}\n\t\t// Write newPath using oldPath's contents, delete oldPath.\n\t\tconst oldStats = this.statSync(oldPath, cred);\n\t\tif (oldStats.isDirectory()) {\n\t\t\t// Optimization: Don't bother moving if old === new.\n\t\t\tif (oldPath === newPath) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet mode = 0o777;\n\t\t\tif (this.existsSync(newPath, cred)) {\n\t\t\t\tconst stats = this.statSync(newPath, cred);\n\t\t\t\tmode = stats.mode;\n\t\t\t\tif (stats.isDirectory()) {\n\t\t\t\t\tif (this.readdirSync(newPath, cred).length > 0) {\n\t\t\t\t\t\tthrow ApiError.ENOTEMPTY(newPath);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tthrow ApiError.ENOTDIR(newPath);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Take care of writable first. Move any files there, or create an empty directory\n\t\t\t// if it doesn't exist.\n\t\t\tif (this._writable.existsSync(oldPath, cred)) {\n\t\t\t\tthis._writable.renameSync(oldPath, newPath, cred);\n\t\t\t} else if (!this._writable.existsSync(newPath, cred)) {\n\t\t\t\tthis._writable.mkdirSync(newPath, mode, cred);\n\t\t\t}\n\n\t\t\t// Need to move *every file/folder* currently stored on readable to its new location\n\t\t\t// on writable.\n\t\t\tif (this._readable.existsSync(oldPath, cred)) {\n\t\t\t\tthis._readable.readdirSync(oldPath, cred).forEach(name => {\n\t\t\t\t\t// Recursion! Should work for any nested files / folders.\n\t\t\t\t\tthis.renameSync(path.resolve(oldPath, name), path.resolve(newPath, name), cred);\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tif (this.existsSync(newPath, cred) && this.statSync(newPath, cred).isDirectory()) {\n\t\t\t\tthrow ApiError.EISDIR(newPath);\n\t\t\t}\n\n\t\t\tthis.writeFileSync(newPath, this.readFileSync(oldPath, null, getFlag('r'), cred), null, getFlag('w'), oldStats.mode, cred);\n\t\t}\n\n\t\tif (oldPath !== newPath && this.existsSync(oldPath, cred)) {\n\t\t\tthis.unlinkSync(oldPath, cred);\n\t\t}\n\t}\n\n\tpublic async stat(p: string, cred: Cred): Promise<Stats> {\n\t\tthis.checkInitialized();\n\t\ttry {\n\t\t\treturn this._writable.stat(p, cred);\n\t\t} catch (e) {\n\t\t\tif (this._deletedFiles[p]) {\n\t\t\t\tthrow ApiError.ENOENT(p);\n\t\t\t}\n\t\t\tconst oldStat = Stats.clone(await this._readable.stat(p, cred));\n\t\t\t// Make the oldStat's mode writable. Preserve the topmost part of the\n\t\t\t// mode, which specifies if it is a file or a directory.\n\t\t\toldStat.mode = makeModeWritable(oldStat.mode);\n\t\t\treturn oldStat;\n\t\t}\n\t}\n\n\tpublic statSync(p: string, cred: Cred): Stats {\n\t\tthis.checkInitialized();\n\t\ttry {\n\t\t\treturn this._writable.statSync(p, cred);\n\t\t} catch (e) {\n\t\t\tif (this._deletedFiles[p]) {\n\t\t\t\tthrow ApiError.ENOENT(p);\n\t\t\t}\n\t\t\tconst oldStat = Stats.clone(this._readable.statSync(p, cred));\n\t\t\t// Make the oldStat's mode writable. Preserve the topmost part of the\n\t\t\t// mode, which specifies if it is a file or a directory.\n\t\t\toldStat.mode = makeModeWritable(oldStat.mode);\n\t\t\treturn oldStat;\n\t\t}\n\t}\n\n\tpublic async open(p: string, flag: FileFlag, mode: number, cred: Cred): Promise<File> {\n\t\tthis.checkInitialized();\n\t\tthis.checkPath(p);\n\t\tif (p === deletionLogPath) {\n\t\t\tthrow ApiError.EPERM('Cannot open deletion log.');\n\t\t}\n\t\tif (await this.exists(p, cred)) {\n\t\t\tswitch (flag.pathExistsAction()) {\n\t\t\t\tcase ActionType.TRUNCATE_FILE:\n\t\t\t\t\tawait this.createParentDirectoriesAsync(p, cred);\n\t\t\t\t\treturn this._writable.open(p, flag, mode, cred);\n\t\t\t\tcase ActionType.NOP:\n\t\t\t\t\tif (await this._writable.exists(p, cred)) {\n\t\t\t\t\t\treturn this._writable.open(p, flag, mode, cred);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Create an OverlayFile.\n\t\t\t\t\t\tconst buf = await this._readable.readFile(p, null, getFlag('r'), cred);\n\t\t\t\t\t\tconst stats = Stats.clone(await this._readable.stat(p, cred));\n\t\t\t\t\t\tstats.mode = mode;\n\t\t\t\t\t\treturn new OverlayFile(this, p, flag, stats, buf as Buffer);\n\t\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tthrow ApiError.EEXIST(p);\n\t\t\t}\n\t\t} else {\n\t\t\tswitch (flag.pathNotExistsAction()) {\n\t\t\t\tcase ActionType.CREATE_FILE:\n\t\t\t\t\tawait this.createParentDirectoriesAsync(p, cred);\n\t\t\t\t\treturn this._writable.open(p, flag, mode, cred);\n\t\t\t\tdefault:\n\t\t\t\t\tthrow ApiError.ENOENT(p);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic openSync(p: string, flag: FileFlag, mode: number, cred: Cred): File {\n\t\tthis.checkInitialized();\n\t\tthis.checkPath(p);\n\t\tif (p === deletionLogPath) {\n\t\t\tthrow ApiError.EPERM('Cannot open deletion log.');\n\t\t}\n\t\tif (this.existsSync(p, cred)) {\n\t\t\tswitch (flag.pathExistsAction()) {\n\t\t\t\tcase ActionType.TRUNCATE_FILE:\n\t\t\t\t\tthis.createParentDirectories(p, cred);\n\t\t\t\t\treturn this._writable.openSync(p, flag, mode, cred);\n\t\t\t\tcase ActionType.NOP:\n\t\t\t\t\tif (this._writable.existsSync(p, cred)) {\n\t\t\t\t\t\treturn this._writable.openSync(p, flag, mode, cred);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Create an OverlayFile.\n\t\t\t\t\t\tconst buf = <Buffer>this._readable.readFileSync(p, null, getFlag('r'), cred);\n\t\t\t\t\t\tconst stats = Stats.clone(this._readable.statSync(p, cred));\n\t\t\t\t\t\tstats.mode = mode;\n\t\t\t\t\t\treturn new OverlayFile(this, p, flag, stats, buf);\n\t\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tthrow ApiError.EEXIST(p);\n\t\t\t}\n\t\t} else {\n\t\t\tswitch (flag.pathNotExistsAction()) {\n\t\t\t\tcase ActionType.CREATE_FILE:\n\t\t\t\t\tthis.createParentDirectories(p, cred);\n\t\t\t\t\treturn this._writable.openSync(p, flag, mode, cred);\n\t\t\t\tdefault:\n\t\t\t\t\tthrow ApiError.ENOENT(p);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async unlink(p: string, cred: Cred): Promise<void> {\n\t\tthis.checkInitialized();\n\t\tthis.checkPath(p);\n\t\tif (await this.exists(p, cred)) {\n\t\t\tif (await this._writable.exists(p, cred)) {\n\t\t\t\tawait this._writable.unlink(p, cred);\n\t\t\t}\n\n\t\t\t// if it still exists add to the delete log\n\t\t\tif (await this.exists(p, cred)) {\n\t\t\t\tthis.deletePath(p, cred);\n\t\t\t}\n\t\t} else {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t}\n\n\tpublic unlinkSync(p: string, cred: Cred): void {\n\t\tthis.checkInitialized();\n\t\tthis.checkPath(p);\n\t\tif (this.existsSync(p, cred)) {\n\t\t\tif (this._writable.existsSync(p, cred)) {\n\t\t\t\tthis._writable.unlinkSync(p, cred);\n\t\t\t}\n\n\t\t\t// if it still exists add to the delete log\n\t\t\tif (this.existsSync(p, cred)) {\n\t\t\t\tthis.deletePath(p, cred);\n\t\t\t}\n\t\t} else {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t}\n\n\tpublic async rmdir(p: string, cred: Cred): Promise<void> {\n\t\tthis.checkInitialized();\n\t\tif (await this.exists(p, cred)) {\n\t\t\tif (await this._writable.exists(p, cred)) {\n\t\t\t\tawait this._writable.rmdir(p, cred);\n\t\t\t}\n\t\t\tif (await this.exists(p, cred)) {\n\t\t\t\t// Check if directory is empty.\n\t\t\t\tif ((await this.readdir(p, cred)).length > 0) {\n\t\t\t\t\tthrow ApiError.ENOTEMPTY(p);\n\t\t\t\t} else {\n\t\t\t\t\tthis.deletePath(p, cred);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t}\n\n\tpublic rmdirSync(p: string, cred: Cred): void {\n\t\tthis.checkInitialized();\n\t\tif (this.existsSync(p, cred)) {\n\t\t\tif (this._writable.existsSync(p, cred)) {\n\t\t\t\tthis._writable.rmdirSync(p, cred);\n\t\t\t}\n\t\t\tif (this.existsSync(p, cred)) {\n\t\t\t\t// Check if directory is empty.\n\t\t\t\tif (this.readdirSync(p, cred).length > 0) {\n\t\t\t\t\tthrow ApiError.ENOTEMPTY(p);\n\t\t\t\t} else {\n\t\t\t\t\tthis.deletePath(p, cred);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t}\n\n\tpublic async mkdir(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tthis.checkInitialized();\n\t\tif (await this.exists(p, cred)) {\n\t\t\tthrow ApiError.EEXIST(p);\n\t\t} else {\n\t\t\t// The below will throw should any of the parent directories fail to exist\n\t\t\t// on _writable.\n\t\t\tawait this.createParentDirectoriesAsync(p, cred);\n\t\t\tawait this._writable.mkdir(p, mode, cred);\n\t\t}\n\t}\n\n\tpublic mkdirSync(p: string, mode: number, cred: Cred): void {\n\t\tthis.checkInitialized();\n\t\tif (this.existsSync(p, cred)) {\n\t\t\tthrow ApiError.EEXIST(p);\n\t\t} else {\n\t\t\t// The below will throw should any of the parent directories fail to exist\n\t\t\t// on _writable.\n\t\t\tthis.createParentDirectories(p, cred);\n\t\t\tthis._writable.mkdirSync(p, mode, cred);\n\t\t}\n\t}\n\n\tpublic async readdir(p: string, cred: Cred): Promise<string[]> {\n\t\tthis.checkInitialized();\n\t\tconst dirStats = await this.stat(p, cred);\n\t\tif (!dirStats.isDirectory()) {\n\t\t\tthrow ApiError.ENOTDIR(p);\n\t\t}\n\n\t\t// Readdir in both, check delete log on RO file system's listing, merge, return.\n\t\tlet contents: string[] = [];\n\t\ttry {\n\t\t\tcontents = contents.concat(await this._writable.readdir(p, cred));\n\t\t} catch (e) {\n\t\t\t// NOP.\n\t\t}\n\t\ttry {\n\t\t\tcontents = contents.concat((await this._readable.readdir(p, cred)).filter((fPath: string) => !this._deletedFiles[`${p}/${fPath}`]));\n\t\t} catch (e) {\n\t\t\t// NOP.\n\t\t}\n\t\tconst seenMap: { [name: string]: boolean } = {};\n\t\treturn contents.filter((fileP: string) => {\n\t\t\tconst result = !seenMap[fileP];\n\t\t\tseenMap[fileP] = true;\n\t\t\treturn result;\n\t\t});\n\t}\n\n\tpublic readdirSync(p: string, cred: Cred): string[] {\n\t\tthis.checkInitialized();\n\t\tconst dirStats = this.statSync(p, cred);\n\t\tif (!dirStats.isDirectory()) {\n\t\t\tthrow ApiError.ENOTDIR(p);\n\t\t}\n\n\t\t// Readdir in both, check delete log on RO file system's listing, merge, return.\n\t\tlet contents: string[] = [];\n\t\ttry {\n\t\t\tcontents = contents.concat(this._writable.readdirSync(p, cred));\n\t\t} catch (e) {\n\t\t\t// NOP.\n\t\t}\n\t\ttry {\n\t\t\tcontents = contents.concat(this._readable.readdirSync(p, cred).filter((fPath: string) => !this._deletedFiles[`${p}/${fPath}`]));\n\t\t} catch (e) {\n\t\t\t// NOP.\n\t\t}\n\t\tconst seenMap: { [name: string]: boolean } = {};\n\t\treturn contents.filter((fileP: string) => {\n\t\t\tconst result = !seenMap[fileP];\n\t\t\tseenMap[fileP] = true;\n\t\t\treturn result;\n\t\t});\n\t}\n\n\tpublic async exists(p: string, cred: Cred): Promise<boolean> {\n\t\tthis.checkInitialized();\n\t\treturn (await this._writable.exists(p, cred)) || ((await this._readable.exists(p, cred)) && this._deletedFiles[p] !== true);\n\t}\n\n\tpublic existsSync(p: string, cred: Cred): boolean {\n\t\tthis.checkInitialized();\n\t\treturn this._writable.existsSync(p, cred) || (this._readable.existsSync(p, cred) && this._deletedFiles[p] !== true);\n\t}\n\n\tpublic async chmod(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tthis.checkInitialized();\n\t\tawait this.operateOnWritableAsync(p, cred);\n\t\tawait this._writable.chmod(p, mode, cred);\n\t}\n\n\tpublic chmodSync(p: string, mode: number, cred: Cred): void {\n\t\tthis.checkInitialized();\n\t\tthis.operateOnWritable(p, cred);\n\t\tthis._writable.chmodSync(p, mode, cred);\n\t}\n\n\tpublic async chown(p: string, new_uid: number, new_gid: number, cred: Cred): Promise<void> {\n\t\tthis.checkInitialized();\n\t\tawait this.operateOnWritableAsync(p, cred);\n\t\tawait this._writable.chown(p, new_uid, new_gid, cred);\n\t}\n\n\tpublic chownSync(p: string, new_uid: number, new_gid: number, cred: Cred): void {\n\t\tthis.checkInitialized();\n\t\tthis.operateOnWritable(p, cred);\n\t\tthis._writable.chownSync(p, new_uid, new_gid, cred);\n\t}\n\n\tpublic async utimes(p: string, atime: Date, mtime: Date, cred: Cred): Promise<void> {\n\t\tthis.checkInitialized();\n\t\tawait this.operateOnWritableAsync(p, cred);\n\t\tawait this._writable.utimes(p, atime, mtime, cred);\n\t}\n\n\tpublic utimesSync(p: string, atime: Date, mtime: Date, cred: Cred): void {\n\t\tthis.checkInitialized();\n\t\tthis.operateOnWritable(p, cred);\n\t\tthis._writable.utimesSync(p, atime, mtime, cred);\n\t}\n\n\tprivate deletePath(p: string, cred: Cred): void {\n\t\tthis._deletedFiles[p] = true;\n\t\tthis.updateLog(`d${p}\\n`, cred);\n\t}\n\n\tprivate updateLog(addition: string, cred: Cred) {\n\t\tthis._deleteLog += addition;\n\t\tif (this._deleteLogUpdatePending) {\n\t\t\tthis._deleteLogUpdateNeeded = true;\n\t\t} else {\n\t\t\tthis._deleteLogUpdatePending = true;\n\t\t\tthis._writable\n\t\t\t\t.writeFile(deletionLogPath, this._deleteLog, 'utf8', FileFlag.getFileFlag('w'), 0o644, cred)\n\t\t\t\t.then(() => {\n\t\t\t\t\tif (this._deleteLogUpdateNeeded) {\n\t\t\t\t\t\tthis._deleteLogUpdateNeeded = false;\n\t\t\t\t\t\tthis.updateLog('', cred);\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(e => {\n\t\t\t\t\tthis._deleteLogError = e;\n\t\t\t\t})\n\t\t\t\t.finally(() => {\n\t\t\t\t\tthis._deleteLogUpdatePending = false;\n\t\t\t\t});\n\t\t}\n\t}\n\n\tprivate _reparseDeletionLog(): void {\n\t\tthis._deletedFiles = {};\n\t\tthis._deleteLog.split('\\n').forEach((path: string) => {\n\t\t\t// If the log entry begins w/ 'd', it's a deletion.\n\t\t\tthis._deletedFiles[path.slice(1)] = path.slice(0, 1) === 'd';\n\t\t});\n\t}\n\n\tprivate checkInitialized(): void {\n\t\tif (!this._isInitialized) {\n\t\t\tthrow new ApiError(ErrorCode.EPERM, 'OverlayFS is not initialized. Please initialize OverlayFS using its initialize() method before using it.');\n\t\t} else if (this._deleteLogError !== null) {\n\t\t\tconst e = this._deleteLogError;\n\t\t\tthis._deleteLogError = null;\n\t\t\tthrow e;\n\t\t}\n\t}\n\n\tprivate checkPath(p: string): void {\n\t\tif (p === deletionLogPath) {\n\t\t\tthrow ApiError.EPERM(p);\n\t\t}\n\t}\n\n\t/**\n\t * With the given path, create the needed parent directories on the writable storage\n\t * should they not exist. Use modes from the read-only storage.\n\t */\n\tprivate createParentDirectories(p: string, cred: Cred): void {\n\t\tlet parent = path.dirname(p),\n\t\t\ttoCreate: string[] = [];\n\t\twhile (!this._writable.existsSync(parent, cred)) {\n\t\t\ttoCreate.push(parent);\n\t\t\tparent = path.dirname(parent);\n\t\t}\n\t\ttoCreate = toCreate.reverse();\n\n\t\tfor (const p of toCreate) {\n\t\t\tthis._writable.mkdirSync(p, this.statSync(p, cred).mode, cred);\n\t\t}\n\t}\n\n\tprivate async createParentDirectoriesAsync(p: string, cred: Cred): Promise<void> {\n\t\tlet parent = path.dirname(p),\n\t\t\ttoCreate: string[] = [];\n\t\twhile (!(await this._writable.exists(parent, cred))) {\n\t\t\ttoCreate.push(parent);\n\t\t\tparent = path.dirname(parent);\n\t\t}\n\t\ttoCreate = toCreate.reverse();\n\n\t\tfor (const p of toCreate) {\n\t\t\tconst stats = await this.stat(p, cred);\n\t\t\tawait this._writable.mkdir(p, stats.mode, cred);\n\t\t}\n\t}\n\n\t/**\n\t * Helper function:\n\t * - Ensures p is on writable before proceeding. Throws an error if it doesn't exist.\n\t * - Calls f to perform operation on writable.\n\t */\n\tprivate operateOnWritable(p: string, cred: Cred): void {\n\t\tif (!this.existsSync(p, cred)) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t\tif (!this._writable.existsSync(p, cred)) {\n\t\t\t// File is on readable storage. Copy to writable storage before\n\t\t\t// changing its mode.\n\t\t\tthis.copyToWritable(p, cred);\n\t\t}\n\t}\n\n\tprivate async operateOnWritableAsync(p: string, cred: Cred): Promise<void> {\n\t\tif (!(await this.exists(p, cred))) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\n\t\tif (!(await this._writable.exists(p, cred))) {\n\t\t\treturn this.copyToWritableAsync(p, cred);\n\t\t}\n\t}\n\n\t/**\n\t * Copy from readable to writable storage.\n\t * PRECONDITION: File does not exist on writable storage.\n\t */\n\tprivate copyToWritable(p: string, cred: Cred): void {\n\t\tconst pStats = this.statSync(p, cred);\n\t\tif (pStats.isDirectory()) {\n\t\t\tthis._writable.mkdirSync(p, pStats.mode, cred);\n\t\t} else {\n\t\t\tthis.writeFileSync(p, this._readable.readFileSync(p, null, getFlag('r'), cred), null, getFlag('w'), pStats.mode, cred);\n\t\t}\n\t}\n\n\tprivate async copyToWritableAsync(p: string, cred: Cred): Promise<void> {\n\t\tconst pStats = await this.stat(p, cred);\n\t\tif (pStats.isDirectory()) {\n\t\t\tawait this._writable.mkdir(p, pStats.mode, cred);\n\t\t} else {\n\t\t\tawait this.writeFile(p, await this._readable.readFile(p, null, getFlag('r'), cred), null, getFlag('w'), pStats.mode, cred);\n\t\t}\n\t}\n}\n\n/**\n * OverlayFS makes a read-only filesystem writable by storing writes on a second,\n * writable file system. Deletes are persisted via metadata stored on the writable\n * file system.\n */\nexport class OverlayFS extends LockedFS<UnlockedOverlayFS> {\n\tpublic static readonly Name = 'OverlayFS';\n\n\tpublic static Create = CreateBackend.bind(this);\n\n\tpublic static readonly Options: BackendOptions = {\n\t\twritable: {\n\t\t\ttype: 'object',\n\t\t\tdescription: 'The file system to write modified files to.',\n\t\t},\n\t\treadable: {\n\t\t\ttype: 'object',\n\t\t\tdescription: 'The file system that initially populates this file system.',\n\t\t},\n\t};\n\n\tpublic static isAvailable(): boolean {\n\t\treturn UnlockedOverlayFS.isAvailable();\n\t}\n\n\t/**\n\t * @param options The options to initialize the OverlayFS with\n\t */\n\tconstructor(options: OverlayFS.Options) {\n\t\tsuper(new UnlockedOverlayFS(options));\n\t\tthis._ready = this._initialize();\n\t}\n\n\tpublic getOverlayedFileSystems(): OverlayFS.Options {\n\t\treturn super.fs.getOverlayedFileSystems();\n\t}\n\n\tpublic getDeletionLog(): string {\n\t\treturn super.fs.getDeletionLog();\n\t}\n\n\tpublic resDeletionLog(): string {\n\t\treturn super.fs.getDeletionLog();\n\t}\n\n\tpublic unwrap(): UnlockedOverlayFS {\n\t\treturn super.fs;\n\t}\n\n\tprivate async _initialize(): Promise<this> {\n\t\tawait super.fs._initialize();\n\t\treturn this;\n\t}\n}\n", "import { AsyncMirror } from './AsyncMirror.js';\nimport { FolderAdapter } from './FolderAdapter.js';\nimport { InMemoryFileSystem as InMemory } from './InMemory.js';\nimport { OverlayFS } from './OverlayFS.js';\nimport { BackendConstructor } from './backend.js';\n\nexport const backends: { [backend: string]: BackendConstructor } = {};\nexport default backends;\nexport { AsyncMirror, FolderAdapter, InMemory, OverlayFS };\n\nexport function registerBackend(..._backends: BackendConstructor[]) {\n\tfor (const backend of _backends) {\n\t\tbackends[backend.Name] = backend;\n\t}\n}\n\nregisterBackend(AsyncMirror, FolderAdapter, InMemory, OverlayFS);\n", "import * as path from 'path';\nimport { ApiError, ErrorCode } from '../ApiError.js';\nimport { Cred } from '../cred.js';\nimport { W_OK, R_OK } from '../emulation/constants.js';\nimport { PreloadFile, File, FileFlag } from '../file.js';\nimport { BaseFileSystem } from '../filesystem.js';\nimport Inode from '../inode.js';\nimport { Stats, FileType } from '../stats.js';\nimport { ROOT_NODE_ID, randomUUID, getEmptyDirNode } from '../utils.js';\n\nclass LRUNode {\n\tpublic prev: LRUNode | null = null;\n\tpublic next: LRUNode | null = null;\n\tconstructor(public key: string, public value: string) {}\n}\n\n// Adapted from https://chrisrng.svbtle.com/lru-cache-in-javascript\nclass LRUCache {\n\tprivate size = 0;\n\tprivate map: { [id: string]: LRUNode } = {};\n\tprivate head: LRUNode | null = null;\n\tprivate tail: LRUNode | null = null;\n\tconstructor(public readonly limit: number) {}\n\n\t/**\n\t * Change or add a new value in the cache\n\t * We overwrite the entry if it already exists\n\t */\n\tpublic set(key: string, value: string): void {\n\t\tconst node = new LRUNode(key, value);\n\t\tif (this.map[key]) {\n\t\t\tthis.map[key].value = node.value;\n\t\t\tthis.remove(node.key);\n\t\t} else {\n\t\t\tif (this.size >= this.limit) {\n\t\t\t\tdelete this.map[this.tail!.key];\n\t\t\t\tthis.size--;\n\t\t\t\tthis.tail = this.tail!.prev;\n\t\t\t\tthis.tail!.next = null;\n\t\t\t}\n\t\t}\n\t\tthis.setHead(node);\n\t}\n\n\t/* Retrieve a single entry from the cache */\n\tpublic get(key: string): string | null {\n\t\tif (this.map[key]) {\n\t\t\tconst value = this.map[key].value;\n\t\t\tconst node = new LRUNode(key, value);\n\t\t\tthis.remove(key);\n\t\t\tthis.setHead(node);\n\t\t\treturn value;\n\t\t} else {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/* Remove a single entry from the cache */\n\tpublic remove(key: string): void {\n\t\tconst node = this.map[key];\n\t\tif (!node) {\n\t\t\treturn;\n\t\t}\n\t\tif (node.prev !== null) {\n\t\t\tnode.prev.next = node.next;\n\t\t} else {\n\t\t\tthis.head = node.next;\n\t\t}\n\t\tif (node.next !== null) {\n\t\t\tnode.next.prev = node.prev;\n\t\t} else {\n\t\t\tthis.tail = node.prev;\n\t\t}\n\t\tdelete this.map[key];\n\t\tthis.size--;\n\t}\n\n\t/* Resets the entire cache - Argument limit is optional to be reset */\n\tpublic removeAll() {\n\t\tthis.size = 0;\n\t\tthis.map = {};\n\t\tthis.head = null;\n\t\tthis.tail = null;\n\t}\n\n\tprivate setHead(node: LRUNode): void {\n\t\tnode.next = this.head;\n\t\tnode.prev = null;\n\t\tif (this.head !== null) {\n\t\t\tthis.head.prev = node;\n\t\t}\n\t\tthis.head = node;\n\t\tif (this.tail === null) {\n\t\t\tthis.tail = node;\n\t\t}\n\t\tthis.size++;\n\t\tthis.map[node.key] = node;\n\t}\n}\n\n/**\n * Represents an *asynchronous* key-value store.\n */\nexport interface AsyncKeyValueStore {\n\t/**\n\t * The name of the key-value store.\n\t */\n\tname(): string;\n\t/**\n\t * Empties the key-value store completely.\n\t */\n\tclear(): Promise<void>;\n\t/**\n\t * Begins a read-write transaction.\n\t */\n\tbeginTransaction(type: 'readwrite'): AsyncKeyValueRWTransaction;\n\t/**\n\t * Begins a read-only transaction.\n\t */\n\tbeginTransaction(type: 'readonly'): AsyncKeyValueROTransaction;\n\tbeginTransaction(type: string): AsyncKeyValueROTransaction;\n}\n\n/**\n * Represents an asynchronous read-only transaction.\n */\nexport interface AsyncKeyValueROTransaction {\n\t/**\n\t * Retrieves the data at the given key.\n\t * @param key The key to look under for data.\n\t */\n\tget(key: string): Promise<Buffer>;\n}\n\n/**\n * Represents an asynchronous read-write transaction.\n */\nexport interface AsyncKeyValueRWTransaction extends AsyncKeyValueROTransaction {\n\t/**\n\t * Adds the data to the store under the given key. Overwrites any existing\n\t * data.\n\t * @param key The key to add the data under.\n\t * @param data The data to add to the store.\n\t * @param overwrite If 'true', overwrite any existing data. If 'false',\n\t * avoids writing the data if the key exists.\n\t */\n\tput(key: string, data: Buffer, overwrite: boolean): Promise<boolean>;\n\t/**\n\t * Deletes the data at the given key.\n\t * @param key The key to delete from the store.\n\t */\n\tdel(key: string): Promise<void>;\n\t/**\n\t * Commits the transaction.\n\t */\n\tcommit(): Promise<void>;\n\t/**\n\t * Aborts and rolls back the transaction.\n\t */\n\tabort(): Promise<void>;\n}\n\nexport class AsyncKeyValueFile extends PreloadFile<AsyncKeyValueFileSystem> implements File {\n\tconstructor(_fs: AsyncKeyValueFileSystem, _path: string, _flag: FileFlag, _stat: Stats, contents?: Buffer) {\n\t\tsuper(_fs, _path, _flag, _stat, contents);\n\t}\n\n\tpublic async sync(): Promise<void> {\n\t\tif (!this.isDirty()) {\n\t\t\treturn;\n\t\t}\n\n\t\tawait this._fs._sync(this.getPath(), this.getBuffer(), this.getStats());\n\n\t\tthis.resetDirty();\n\t}\n\n\tpublic async close(): Promise<void> {\n\t\tthis.sync();\n\t}\n}\n\n/**\n * An \"Asynchronous key-value file system\". Stores data to/retrieves data from\n * an underlying asynchronous key-value store.\n */\nexport class AsyncKeyValueFileSystem extends BaseFileSystem {\n\tpublic static isAvailable(): boolean {\n\t\treturn true;\n\t}\n\n\tprotected store: AsyncKeyValueStore;\n\tprivate _cache: LRUCache | null = null;\n\n\tconstructor(cacheSize: number) {\n\t\tsuper();\n\t\tif (cacheSize > 0) {\n\t\t\tthis._cache = new LRUCache(cacheSize);\n\t\t}\n\t}\n\n\t/**\n\t * Initializes the file system. Typically called by subclasses' async\n\t * constructors.\n\t */\n\tpublic async init(store: AsyncKeyValueStore) {\n\t\tthis.store = store;\n\t\t// INVARIANT: Ensure that the root exists.\n\t\tawait this.makeRootDirectory();\n\t}\n\tpublic getName(): string {\n\t\treturn this.store.name();\n\t}\n\tpublic isReadOnly(): boolean {\n\t\treturn false;\n\t}\n\tpublic supportsSymlinks(): boolean {\n\t\treturn false;\n\t}\n\tpublic supportsProps(): boolean {\n\t\treturn true;\n\t}\n\tpublic supportsSynch(): boolean {\n\t\treturn false;\n\t}\n\n\t/**\n\t * Delete all contents stored in the file system.\n\t */\n\tpublic async empty(): Promise<void> {\n\t\tif (this._cache) {\n\t\t\tthis._cache.removeAll();\n\t\t}\n\t\tawait this.store.clear();\n\t\t// INVARIANT: Root always exists.\n\t\tawait this.makeRootDirectory();\n\t}\n\n\tpublic async access(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tconst tx = this.store.beginTransaction('readonly');\n\t\tconst inode = await this.findINode(tx, p);\n\t\tif (!inode) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t\tif (!inode.toStats().hasAccess(mode, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\t}\n\n\t/**\n\t * @todo Make rename compatible with the cache.\n\t */\n\tpublic async rename(oldPath: string, newPath: string, cred: Cred): Promise<void> {\n\t\tconst c = this._cache;\n\t\tif (this._cache) {\n\t\t\t// Clear and disable cache during renaming process.\n\t\t\tthis._cache = null;\n\t\t\tc.removeAll();\n\t\t}\n\n\t\ttry {\n\t\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\t\toldParent = path.dirname(oldPath),\n\t\t\t\toldName = path.basename(oldPath),\n\t\t\t\tnewParent = path.dirname(newPath),\n\t\t\t\tnewName = path.basename(newPath),\n\t\t\t\t// Remove oldPath from parent's directory listing.\n\t\t\t\toldDirNode = await this.findINode(tx, oldParent),\n\t\t\t\toldDirList = await this.getDirListing(tx, oldParent, oldDirNode);\n\n\t\t\tif (!oldDirNode.toStats().hasAccess(W_OK, cred)) {\n\t\t\t\tthrow ApiError.EACCES(oldPath);\n\t\t\t}\n\n\t\t\tif (!oldDirList[oldName]) {\n\t\t\t\tthrow ApiError.ENOENT(oldPath);\n\t\t\t}\n\t\t\tconst nodeId: string = oldDirList[oldName];\n\t\t\tdelete oldDirList[oldName];\n\n\t\t\t// Invariant: Can't move a folder inside itself.\n\t\t\t// This funny little hack ensures that the check passes only if oldPath\n\t\t\t// is a subpath of newParent. We append '/' to avoid matching folders that\n\t\t\t// are a substring of the bottom-most folder in the path.\n\t\t\tif ((newParent + '/').indexOf(oldPath + '/') === 0) {\n\t\t\t\tthrow new ApiError(ErrorCode.EBUSY, oldParent);\n\t\t\t}\n\n\t\t\t// Add newPath to parent's directory listing.\n\t\t\tlet newDirNode: Inode, newDirList: typeof oldDirList;\n\t\t\tif (newParent === oldParent) {\n\t\t\t\t// Prevent us from re-grabbing the same directory listing, which still\n\t\t\t\t// contains oldName.\n\t\t\t\tnewDirNode = oldDirNode;\n\t\t\t\tnewDirList = oldDirList;\n\t\t\t} else {\n\t\t\t\tnewDirNode = await this.findINode(tx, newParent);\n\t\t\t\tnewDirList = await this.getDirListing(tx, newParent, newDirNode);\n\t\t\t}\n\n\t\t\tif (newDirList[newName]) {\n\t\t\t\t// If it's a file, delete it.\n\t\t\t\tconst newNameNode = await this.getINode(tx, newPath, newDirList[newName]);\n\t\t\t\tif (newNameNode.isFile()) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait tx.del(newNameNode.id);\n\t\t\t\t\t\tawait tx.del(newDirList[newName]);\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tawait tx.abort();\n\t\t\t\t\t\tthrow e;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// If it's a directory, throw a permissions error.\n\t\t\t\t\tthrow ApiError.EPERM(newPath);\n\t\t\t\t}\n\t\t\t}\n\t\t\tnewDirList[newName] = nodeId;\n\n\t\t\t// Commit the two changed directory listings.\n\t\t\ttry {\n\t\t\t\tawait tx.put(oldDirNode.id, Buffer.from(JSON.stringify(oldDirList)), true);\n\t\t\t\tawait tx.put(newDirNode.id, Buffer.from(JSON.stringify(newDirList)), true);\n\t\t\t} catch (e) {\n\t\t\t\tawait tx.abort();\n\t\t\t\tthrow e;\n\t\t\t}\n\n\t\t\tawait tx.commit();\n\t\t} finally {\n\t\t\tif (c) {\n\t\t\t\tthis._cache = c;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async stat(p: string, cred: Cred): Promise<Stats> {\n\t\tconst tx = this.store.beginTransaction('readonly');\n\t\tconst inode = await this.findINode(tx, p);\n\t\tconst stats = inode!.toStats();\n\t\tif (!stats.hasAccess(R_OK, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\t\treturn stats;\n\t}\n\n\tpublic async createFile(p: string, flag: FileFlag, mode: number, cred: Cred): Promise<File> {\n\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\tdata = Buffer.alloc(0),\n\t\t\tnewFile = await this.commitNewFile(tx, p, FileType.FILE, mode, cred, data);\n\t\t// Open the file.\n\t\treturn new AsyncKeyValueFile(this, p, flag, newFile.toStats(), data);\n\t}\n\n\tpublic async openFile(p: string, flag: FileFlag, cred: Cred): Promise<File> {\n\t\tconst tx = this.store.beginTransaction('readonly'),\n\t\t\tnode = await this.findINode(tx, p),\n\t\t\tdata = await tx.get(node.id);\n\t\tif (!node.toStats().hasAccess(flag.getMode(), cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\t\tif (data === undefined) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t\treturn new AsyncKeyValueFile(this, p, flag, node.toStats(), data);\n\t}\n\n\tpublic async unlink(p: string, cred: Cred): Promise<void> {\n\t\treturn this.removeEntry(p, false, cred);\n\t}\n\n\tpublic async rmdir(p: string, cred: Cred): Promise<void> {\n\t\t// Check first if directory is empty.\n\t\tconst list = await this.readdir(p, cred);\n\t\tif (list.length > 0) {\n\t\t\tthrow ApiError.ENOTEMPTY(p);\n\t\t}\n\t\tawait this.removeEntry(p, true, cred);\n\t}\n\n\tpublic async mkdir(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\tdata = Buffer.from('{}');\n\t\tawait this.commitNewFile(tx, p, FileType.DIRECTORY, mode, cred, data);\n\t}\n\n\tpublic async readdir(p: string, cred: Cred): Promise<string[]> {\n\t\tconst tx = this.store.beginTransaction('readonly');\n\t\tconst node = await this.findINode(tx, p);\n\t\tif (!node.toStats().hasAccess(R_OK, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\t\treturn Object.keys(await this.getDirListing(tx, p, node));\n\t}\n\n\tpublic async chmod(p: string, mode: number, cred: Cred): Promise<void> {\n\t\tconst fd = await this.openFile(p, FileFlag.getFileFlag('r+'), cred);\n\t\tawait fd.chmod(mode);\n\t}\n\n\tpublic async chown(p: string, new_uid: number, new_gid: number, cred: Cred): Promise<void> {\n\t\tconst fd = await this.openFile(p, FileFlag.getFileFlag('r+'), cred);\n\t\tawait fd.chown(new_uid, new_gid);\n\t}\n\n\tpublic async _sync(p: string, data: Buffer, stats: Stats): Promise<void> {\n\t\t// @todo Ensure mtime updates properly, and use that to determine if a data\n\t\t// update is required.\n\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\t// We use the _findInode helper because we actually need the INode id.\n\t\t\tfileInodeId = await this._findINode(tx, path.dirname(p), path.basename(p)),\n\t\t\tfileInode = await this.getINode(tx, p, fileInodeId),\n\t\t\tinodeChanged = fileInode.update(stats);\n\n\t\ttry {\n\t\t\t// Sync data.\n\t\t\tawait tx.put(fileInode.id, data, true);\n\t\t\t// Sync metadata.\n\t\t\tif (inodeChanged) {\n\t\t\t\tawait tx.put(fileInodeId, fileInode.toBuffer(), true);\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tawait tx.abort();\n\t\t\tthrow e;\n\t\t}\n\t\tawait tx.commit();\n\t}\n\n\t/**\n\t * Checks if the root directory exists. Creates it if it doesn't.\n\t */\n\tprivate async makeRootDirectory(): Promise<void> {\n\t\tconst tx = this.store.beginTransaction('readwrite');\n\t\tif ((await tx.get(ROOT_NODE_ID)) === undefined) {\n\t\t\t// Create new inode.\n\t\t\tconst currTime = new Date().getTime(),\n\t\t\t\t// Mode 0666, owned by root:root\n\t\t\t\tdirInode = new Inode(randomUUID(), 4096, 511 | FileType.DIRECTORY, currTime, currTime, currTime, 0, 0);\n\t\t\t// If the root doesn't exist, the first random ID shouldn't exist,\n\t\t\t// either.\n\t\t\tawait tx.put(dirInode.id, getEmptyDirNode(), false);\n\t\t\tawait tx.put(ROOT_NODE_ID, dirInode.toBuffer(), false);\n\t\t\tawait tx.commit();\n\t\t}\n\t}\n\n\t/**\n\t * Helper function for findINode.\n\t * @param parent The parent directory of the file we are attempting to find.\n\t * @param filename The filename of the inode we are attempting to find, minus\n\t * the parent.\n\t */\n\tprivate async _findINode(tx: AsyncKeyValueROTransaction, parent: string, filename: string, visited: Set<string> = new Set<string>()): Promise<string> {\n\t\tconst currentPath = path.posix.join(parent, filename);\n\t\tif (visited.has(currentPath)) {\n\t\t\tthrow new ApiError(ErrorCode.EIO, 'Infinite loop detected while finding inode', currentPath);\n\t\t}\n\n\t\tvisited.add(currentPath);\n\t\tif (this._cache) {\n\t\t\tconst id = this._cache.get(currentPath);\n\t\t\tif (id) {\n\t\t\t\treturn id;\n\t\t\t}\n\t\t}\n\n\t\tif (parent === '/') {\n\t\t\tif (filename === '') {\n\t\t\t\t// BASE CASE #1: Return the root's ID.\n\t\t\t\tif (this._cache) {\n\t\t\t\t\tthis._cache.set(currentPath, ROOT_NODE_ID);\n\t\t\t\t}\n\t\t\t\treturn ROOT_NODE_ID;\n\t\t\t} else {\n\t\t\t\t// BASE CASE #2: Find the item in the root node.\n\t\t\t\tconst inode = await this.getINode(tx, parent, ROOT_NODE_ID);\n\t\t\t\tconst dirList = await this.getDirListing(tx, parent, inode!);\n\t\t\t\tif (dirList![filename]) {\n\t\t\t\t\tconst id = dirList![filename];\n\t\t\t\t\tif (this._cache) {\n\t\t\t\t\t\tthis._cache.set(currentPath, id);\n\t\t\t\t\t}\n\t\t\t\t\treturn id;\n\t\t\t\t} else {\n\t\t\t\t\tthrow ApiError.ENOENT(path.resolve(parent, filename));\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Get the parent directory's INode, and find the file in its directory\n\t\t\t// listing.\n\t\t\tconst inode = await this.findINode(tx, parent, visited);\n\t\t\tconst dirList = await this.getDirListing(tx, parent, inode!);\n\t\t\tif (dirList![filename]) {\n\t\t\t\tconst id = dirList![filename];\n\t\t\t\tif (this._cache) {\n\t\t\t\t\tthis._cache.set(currentPath, id);\n\t\t\t\t}\n\t\t\t\treturn id;\n\t\t\t} else {\n\t\t\t\tthrow ApiError.ENOENT(path.resolve(parent, filename));\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Finds the Inode of the given path.\n\t * @param p The path to look up.\n\t * @todo memoize/cache\n\t */\n\tprivate async findINode(tx: AsyncKeyValueROTransaction, p: string, visited: Set<string> = new Set<string>()): Promise<Inode> {\n\t\tconst id = await this._findINode(tx, path.dirname(p), path.basename(p), visited);\n\t\treturn this.getINode(tx, p, id!);\n\t}\n\n\t/**\n\t * Given the ID of a node, retrieves the corresponding Inode.\n\t * @param tx The transaction to use.\n\t * @param p The corresponding path to the file (used for error messages).\n\t * @param id The ID to look up.\n\t */\n\tprivate async getINode(tx: AsyncKeyValueROTransaction, p: string, id: string): Promise<Inode> {\n\t\tconst data = await tx.get(id);\n\t\tif (!data) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t\treturn Inode.fromBuffer(data);\n\t}\n\n\t/**\n\t * Given the Inode of a directory, retrieves the corresponding directory\n\t * listing.\n\t */\n\tprivate async getDirListing(tx: AsyncKeyValueROTransaction, p: string, inode: Inode): Promise<{ [fileName: string]: string }> {\n\t\tif (!inode.isDirectory()) {\n\t\t\tthrow ApiError.ENOTDIR(p);\n\t\t}\n\t\tconst data = await tx.get(inode.id);\n\t\ttry {\n\t\t\treturn JSON.parse(data!.toString());\n\t\t} catch (e) {\n\t\t\t// Occurs when data is undefined, or corresponds to something other\n\t\t\t// than a directory listing. The latter should never occur unless\n\t\t\t// the file system is corrupted.\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\t}\n\n\t/**\n\t * Adds a new node under a random ID. Retries 5 times before giving up in\n\t * the exceedingly unlikely chance that we try to reuse a random GUID.\n\t */\n\tprivate async addNewNode(tx: AsyncKeyValueRWTransaction, data: Buffer): Promise<string> {\n\t\tlet retries = 0;\n\t\tconst reroll = async () => {\n\t\t\tif (++retries === 5) {\n\t\t\t\t// Max retries hit. Return with an error.\n\t\t\t\tthrow new ApiError(ErrorCode.EIO, 'Unable to commit data to key-value store.');\n\t\t\t} else {\n\t\t\t\t// Try again.\n\t\t\t\tconst currId = randomUUID();\n\t\t\t\tconst committed = await tx.put(currId, data, false);\n\t\t\t\tif (!committed) {\n\t\t\t\t\treturn reroll();\n\t\t\t\t} else {\n\t\t\t\t\treturn currId;\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\treturn reroll();\n\t}\n\n\t/**\n\t * Commits a new file (well, a FILE or a DIRECTORY) to the file system with\n\t * the given mode.\n\t * Note: This will commit the transaction.\n\t * @param p The path to the new file.\n\t * @param type The type of the new file.\n\t * @param mode The mode to create the new file with.\n\t * @param cred The UID/GID to create the file with\n\t * @param data The data to store at the file's data node.\n\t */\n\tprivate async commitNewFile(tx: AsyncKeyValueRWTransaction, p: string, type: FileType, mode: number, cred: Cred, data: Buffer): Promise<Inode> {\n\t\tconst parentDir = path.dirname(p),\n\t\t\tfname = path.basename(p),\n\t\t\tparentNode = await this.findINode(tx, parentDir),\n\t\t\tdirListing = await this.getDirListing(tx, parentDir, parentNode),\n\t\t\tcurrTime = new Date().getTime();\n\n\t\t//Check that the creater has correct access\n\t\tif (!parentNode.toStats().hasAccess(W_OK, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\n\t\t// Invariant: The root always exists.\n\t\t// If we don't check this prior to taking steps below, we will create a\n\t\t// file with name '' in root should p == '/'.\n\t\tif (p === '/') {\n\t\t\tthrow ApiError.EEXIST(p);\n\t\t}\n\n\t\t// Check if file already exists.\n\t\tif (dirListing[fname]) {\n\t\t\tawait tx.abort();\n\t\t\tthrow ApiError.EEXIST(p);\n\t\t}\n\t\ttry {\n\t\t\t// Commit data.\n\t\t\tconst dataId = await this.addNewNode(tx, data);\n\t\t\tconst fileNode = new Inode(dataId, data.length, mode | type, currTime, currTime, currTime, cred.uid, cred.gid);\n\t\t\t// Commit file node.\n\t\t\tconst fileNodeId = await this.addNewNode(tx, fileNode.toBuffer());\n\t\t\t// Update and commit parent directory listing.\n\t\t\tdirListing[fname] = fileNodeId;\n\t\t\tawait tx.put(parentNode.id, Buffer.from(JSON.stringify(dirListing)), true);\n\t\t\tawait tx.commit();\n\t\t\treturn fileNode;\n\t\t} catch (e) {\n\t\t\ttx.abort();\n\t\t\tthrow e;\n\t\t}\n\t}\n\n\t/**\n\t * Remove all traces of the given path from the file system.\n\t * @param p The path to remove from the file system.\n\t * @param isDir Does the path belong to a directory, or a file?\n\t * @todo Update mtime.\n\t */\n\t/**\n\t * Remove all traces of the given path from the file system.\n\t * @param p The path to remove from the file system.\n\t * @param isDir Does the path belong to a directory, or a file?\n\t * @todo Update mtime.\n\t */\n\tprivate async removeEntry(p: string, isDir: boolean, cred: Cred): Promise<void> {\n\t\tif (this._cache) {\n\t\t\tthis._cache.remove(p);\n\t\t}\n\t\tconst tx = this.store.beginTransaction('readwrite'),\n\t\t\tparent: string = path.dirname(p),\n\t\t\tparentNode = await this.findINode(tx, parent),\n\t\t\tparentListing = await this.getDirListing(tx, parent, parentNode),\n\t\t\tfileName: string = path.basename(p);\n\n\t\tif (!parentListing[fileName]) {\n\t\t\tthrow ApiError.ENOENT(p);\n\t\t}\n\n\t\tconst fileNodeId = parentListing[fileName];\n\n\t\t// Get file inode.\n\t\tconst fileNode = await this.getINode(tx, p, fileNodeId);\n\n\t\tif (!fileNode.toStats().hasAccess(W_OK, cred)) {\n\t\t\tthrow ApiError.EACCES(p);\n\t\t}\n\n\t\t// Remove from directory listing of parent.\n\t\tdelete parentListing[fileName];\n\n\t\tif (!isDir && fileNode.isDirectory()) {\n\t\t\tthrow ApiError.EISDIR(p);\n\t\t} else if (isDir && !fileNode.isDirectory()) {\n\t\t\tthrow ApiError.ENOTDIR(p);\n\t\t}\n\n\t\ttry {\n\t\t\t// Delete data.\n\t\t\tawait tx.del(fileNode.id);\n\t\t\t// Delete node.\n\t\t\tawait tx.del(fileNodeId);\n\t\t\t// Update directory listing.\n\t\t\tawait tx.put(parentNode.id, Buffer.from(JSON.stringify(parentListing)), true);\n\t\t} catch (e) {\n\t\t\tawait tx.abort();\n\t\t\tthrow e;\n\t\t}\n\t\t// Success.\n\t\tawait tx.commit();\n\t}\n}\n"],
5
5
  "mappings": "+mCAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,gBAAAE,GAAA,aAAAC,EAAA,sBAAAC,GAAA,4BAAAC,GAAA,gBAAAC,GAAA,aAAAC,GAAA,mBAAAC,GAAA,SAAAC,EAAA,cAAAC,GAAA,iBAAAC,EAAA,aAAAC,EAAA,eAAAC,GAAA,aAAAC,EAAA,kBAAAC,GAAA,aAAAC,GAAA,eAAAC,GAAA,cAAAC,GAAA,gBAAAC,GAAA,iBAAAC,GAAA,4BAAAC,GAAA,UAAAC,EAAA,qBAAAC,GAAA,2BAAAC,GAAA,0BAAAC,GAAA,aAAAC,GAAA,oBAAAC,GAAA,iBAAAC,GAAA,cAAAC,GAAA,iBAAAC,GAAA,YAAAC,GAAA,OAAAC,GAAA,oBAAAC,GAAA,kBAAAC,GAAA,eAAAC,GAAA,eAAAC,GAAA,eAAAC,GAAA,oBAAAC,GAAA,iBAAAC,GAAA,cAAAC,GAAA,SAAAC,KCAA,IAAAC,EAAA,GAAAC,GAAAD,EAAA,eAA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,GAAcL,EAAiCO,EAA0D,CAExH,GAAI,OAAOA,GAAM,WAChB,OAAOE,GAAeT,CAAM,EAI7BS,GAAeT,CAAM,EACnB,KAAKkB,GAAMX,EAAG,KAAMW,CAAE,CAAC,EACvB,MAAMV,GAAOD,EAAGC,CAAG,CAAC,CAEvB,CAXgBV,EAAAO,GAAA,iBAyBhB,IAAOgB,GAAQC",
6
6
  "names": ["src_exports", "__export", "ActionType", "ApiError", "AsyncKeyValueFile", "AsyncKeyValueFileSystem", "AsyncMirror", "BaseFile", "BaseFileSystem", "Cred", "ErrorCode", "ErrorStrings", "FileFlag", "FileSystem", "FileType", "FolderAdapter", "InMemoryFileSystem", "NoSyncFile", "OverlayFS", "PreloadFile", "ROOT_NODE_ID", "SimpleSyncRWTransaction", "Stats", "SyncKeyValueFile", "SyncKeyValueFileSystem", "SynchronousFileSystem", "backends", "bufferValidator", "checkOptions", "configure", "copyingSlice", "src_default", "fs_default", "getEmptyDirNode", "getFileSystem", "initialize", "mkdirpSync", "randomUUID", "registerBackend", "setImmediate", "toPromise", "wait", "process_exports", "__export", "_debugEnd", "_debugProcess", "_events", "_eventsCount", "_exiting", "_fatalExceptions", "_getActiveHandles", "_getActiveRequests", "_kill", "_linkedBinding", "_maxListeners", "_preload_modules", "_rawDebug", "_startProfilerIdleNotifier", "_stopProfilerIdleNotifier", "_tickCallback", "abort", "addListener", "allowedNodeEnvironmentFlags", "arch", "argv", "argv0", "assert", "binding", "chdir", "config", "cpuUsage", "cwd", "debugPort", "process", "dlopen", "domain", "emit", "emitWarning", "env", "execArgv", "execPath", "exit", "features", "hasUncaughtExceptionCaptureCallback", "hrtime", "kill", "listeners", "memoryUsage", "moduleLoadList", "nextTick", "off", "on", "once", "openStdin", "pid", "platform", "ppid", "prependListener", "prependOnceListener", "reallyExit", "release", "removeAllListeners", "removeListener", "resourceUsage", "setSourceMapsEnabled", "setUncaughtExceptionCaptureCallback", "stderr", "stdin", "stdout", "title", "umask", "uptime", "version", "versions", "unimplemented", "name", "__name", "queue", "draining", "currentQueue", "queueIndex", "cleanUpNextTick", "drainQueue", "timeout", "len", "nextTick", "fun", "args", "i", "Item", "array", "title", "arch", "platform", "env", "argv", "execArgv", "version", "versions", "emitWarning", "message", "type", "binding", "umask", "mask", "cwd", "chdir", "dir", "release", "noop", "_rawDebug", "moduleLoadList", "_linkedBinding", "domain", "_exiting", "config", "dlopen", "_getActiveRequests", "_getActiveHandles", "reallyExit", "_kill", "cpuUsage", "resourceUsage", "memoryUsage", "kill", "exit", "openStdin", "allowedNodeEnvironmentFlags", "assert", "condition", "features", "_fatalExceptions", "setUncaughtExceptionCaptureCallback", "hasUncaughtExceptionCaptureCallback", "_tickCallback", "_debugProcess", "_debugEnd", "_startProfilerIdleNotifier", "_stopProfilerIdleNotifier", "stdout", "stderr", "stdin", "abort", "pid", "ppid", "execPath", "debugPort", "argv0", "_preload_modules", "setSourceMapsEnabled", "_performance", "nowOffset", "uptime", "nanoPerSec", "hrtime", "previousTimestamp", "baseNow", "clocktime", "seconds", "nanoseconds", "time", "diff", "_maxListeners", "_events", "_eventsCount", "on", "process", "addListener", "once", "off", "removeListener", "removeAllListeners", "emit", "prependListener", "prependOnceListener", "listeners", "exports$3", "_dewExec$2", "dew$2", "byteLength", "toByteArray", "fromByteArray", "lookup", "revLookup", "Arr", "code", "i", "len", "getLens", "b64", "validLen", "placeHoldersLen", "__name", "lens", "_byteLength", "tmp", "arr", "curByte", "tripletToBase64", "num", "encodeChunk", "uint8", "start", "end", "output", "extraBytes", "parts", "maxChunkLength", "len2", "exports$2", "_dewExec$1", "dew$1", "buffer", "offset", "isLE", "mLen", "nBytes", "e", "m", "eLen", "eMax", "eBias", "nBits", "d", "s", "value", "c", "rt", "exports$1", "_dewExec", "dew", "base64", "ieee754", "customInspectSymbol", "Buffer", "SlowBuffer", "K_MAX_LENGTH", "typedArraySupport", "proto", "createBuffer", "length", "buf", "arg", "encodingOrOffset", "allocUnsafe", "from", "fromString", "fromArrayView", "isInstance", "fromArrayBuffer", "valueOf", "b", "fromObject", "assertSize", "size", "alloc", "fill", "encoding", "checked", "string", "actual", "fromArrayLike", "array", "arrayView", "copy", "byteOffset", "obj", "numberIsNaN", "a", "x", "y", "list", "pos", "mustMatch", "loweredCase", "utf8ToBytes", "base64ToBytes", "slowToString", "hexSlice", "utf8Slice", "asciiSlice", "latin1Slice", "base64Slice", "utf16leSlice", "swap", "n", "str", "max", "target", "thisStart", "thisEnd", "thisCopy", "targetCopy", "bidirectionalIndexOf", "val", "dir", "arrayIndexOf", "indexSize", "arrLength", "valLength", "read", "foundIndex", "found", "j", "hexWrite", "remaining", "strLen", "parsed", "utf8Write", "blitBuffer", "asciiWrite", "asciiToBytes", "base64Write", "ucs2Write", "utf16leToBytes", "res", "firstByte", "codePoint", "bytesPerSequence", "secondByte", "thirdByte", "fourthByte", "tempCodePoint", "decodeCodePointsArray", "MAX_ARGUMENTS_LENGTH", "codePoints", "ret", "out", "hexSliceLookupTable", "bytes", "newBuf", "checkOffset", "ext", "noAssert", "mul", "defineBigIntMethod", "validateNumber", "first", "last", "boundsError", "lo", "__pow", "hi", "checkInt", "min", "maxBytes", "wrtBigUInt64LE", "checkIntBI", "wrtBigUInt64BE", "limit", "sub", "checkIEEE754", "writeFloat", "littleEndian", "writeDouble", "targetStart", "errors", "E", "sym", "getMessage", "Base", "name", "range", "input", "msg", "received", "addNumericalSeparator", "checkBounds", "type", "INVALID_BASE64_RE", "base64clean", "units", "leadSurrogate", "byteArray", "src", "dst", "alphabet", "table", "i16", "fn", "BufferBigIntNotDefined", "exports", "INSPECT_MAX_BYTES", "kMaxLength", "emulation_exports", "__export", "_toUnixTimestamp", "access", "accessSync", "appendFile", "appendFileSync", "chmod", "chmodSync", "chown", "chownSync", "close", "closeSync", "constants_exports", "createReadStream", "createWriteStream", "exists", "existsSync", "fchmod", "fchmodSync", "fchown", "fchownSync", "fdatasync", "fdatasyncSync", "fstat", "fstatSync", "fsync", "fsyncSync", "ftruncate", "ftruncateSync", "futimes", "futimesSync", "getMount", "getMounts", "initialize", "lchmod", "lchmodSync", "lchown", "lchownSync", "link", "linkSync", "lstat", "lstatSync", "lutimes", "lutimesSync", "mkdir", "mkdirSync", "mount", "open", "openSync", "promises_exports", "read", "readFile", "readFileSync", "readSync", "readdir", "readdirSync", "readlink", "readlinkSync", "realpath", "realpathSync", "rename", "renameSync", "rmdir", "rmdirSync", "stat", "statSync", "symlink", "symlinkSync", "truncate", "truncateSync", "umount", "unlink", "unlinkSync", "unwatchFile", "utimes", "utimesSync", "watch", "watchFile", "write", "writeFile", "writeFileSync", "writeSync", "ErrorCode", "ErrorStrings", "ApiError", "type", "message", "path", "json", "err", "buffer", "code", "p", "Buffer", "bytesWritten", "__name", "exports", "_dewExec", "_global", "dew", "process", "cachedSetTimeout", "cachedClearTimeout", "defaultSetTimout", "__name", "defaultClearTimeout", "e", "runTimeout", "fun", "runClearTimeout", "marker", "queue", "draining", "currentQueue", "queueIndex", "cleanUpNextTick", "drainQueue", "timeout", "len", "args", "i", "Item", "array", "noop", "name", "dir", "exports$1", "_dewExec", "dew", "process$1", "process", "assertPath", "path", "__name", "normalizeStringPosix", "allowAboveRoot", "res", "lastSegmentLength", "lastSlash", "dots", "code", "i", "lastSlashIndex", "_format", "sep", "pathObject", "dir", "base", "posix", "resolvedPath", "resolvedAbsolute", "cwd", "isAbsolute", "trailingSeparator", "joined", "arg", "from", "to", "fromStart", "fromEnd", "fromLen", "toStart", "toEnd", "toLen", "length", "lastCommonSep", "fromCode", "toCode", "out", "hasRoot", "end", "matchedSlash", "ext", "start", "extIdx", "firstNonSlashEnd", "startDot", "startPart", "preDotState", "ret", "exports", "_makeLong", "exports", "basename", "delimiter", "dirname", "extname", "format", "isAbsolute", "join", "normalize", "parse", "posix", "relative", "resolve", "sep", "win32", "constants_exports", "__export", "COPYFILE_EXCL", "COPYFILE_FICLONE", "COPYFILE_FICLONE_FORCE", "F_OK", "O_APPEND", "O_CREAT", "O_DIRECT", "O_DIRECTORY", "O_DSYNC", "O_EXCL", "O_NOATIME", "O_NOCTTY", "O_NOFOLLOW", "O_NONBLOCK", "O_RDONLY", "O_RDWR", "O_SYMLINK", "O_SYNC", "O_TRUNC", "O_WRONLY", "R_OK", "S_IFBLK", "S_IFCHR", "S_IFDIR", "S_IFIFO", "S_IFLNK", "S_IFMT", "S_IFREG", "S_IFSOCK", "S_IRGRP", "S_IROTH", "S_IRUSR", "S_IRWXG", "S_IRWXO", "S_IRWXU", "S_IWGRP", "S_IWOTH", "S_IWUSR", "S_IXGRP", "S_IXOTH", "S_IXUSR", "W_OK", "X_OK", "F_OK", "R_OK", "W_OK", "X_OK", "COPYFILE_EXCL", "COPYFILE_FICLONE", "COPYFILE_FICLONE_FORCE", "O_RDONLY", "O_WRONLY", "O_RDWR", "O_CREAT", "O_EXCL", "O_NOCTTY", "O_TRUNC", "O_APPEND", "O_DIRECTORY", "O_NOATIME", "O_NOFOLLOW", "O_SYNC", "O_DSYNC", "O_SYMLINK", "O_DIRECT", "O_NONBLOCK", "S_IFMT", "S_IFREG", "S_IFDIR", "S_IFCHR", "S_IFBLK", "S_IFIFO", "S_IFLNK", "S_IFSOCK", "S_IRWXU", "S_IRUSR", "S_IWUSR", "S_IXUSR", "S_IRWXG", "S_IRGRP", "S_IWGRP", "S_IXGRP", "S_IRWXO", "S_IROTH", "S_IWOTH", "S_IXOTH", "_Cred", "uid", "gid", "suid", "sgid", "euid", "egid", "Cred", "__name", "FileType", "Stats", "itemType", "size", "mode", "atimeMs", "mtimeMs", "ctimeMs", "uid", "gid", "birthtimeMs", "currentTime", "buffer", "atime", "mtime", "ctime", "s", "Buffer", "cred", "perms", "uMode", "gMode", "wMode", "uPerms", "gPerms", "wPerms", "Cred", "__pow", "__name", "ActionType", "_FileFlag", "flagStr", "ApiError", "mode", "FileFlag", "__name", "BaseFile", "__async", "uid", "gid", "atime", "mtime", "PreloadFile", "_fs", "_path", "_flag", "_stat", "contents", "Buffer", "delta", "newPos", "Stats", "len", "getMount", "buf", "newBuff", "buffer", "offset", "length", "position", "endFp", "rv", "NoSyncFile", "FileSystem", "options", "__name", "_BaseFileSystem", "p", "flag", "cred", "__async", "ApiError", "mode", "stats", "fd", "e", "parentStats", "dirname", "oldPath", "newPath", "splitPath", "sep", "i", "addPaths", "join", "len", "FileFlag", "fname", "encoding", "stat", "buf", "Buffer", "data", "new_uid", "new_gid", "atime", "mtime", "srcpath", "dstpath", "type", "BaseFileSystem", "SynchronousFileSystem", "__spreadProps", "__spreadValues", "flags", "Inode", "id", "size", "mode", "atime", "mtime", "ctime", "uid", "gid", "buffer", "Stats", "FileType", "buff", "Buffer", "stats", "hasChanged", "atimeMs", "mtimeMs", "ctimeMs", "__name", "mkdirpSync", "p", "mode", "cred", "fs", "dirname", "__name", "copyingSlice", "buff", "start", "end", "Buffer", "bufferValidator", "v", "__async", "ApiError", "_min", "d0", "d1", "d2", "bx", "ay", "levenshtein", "a", "b", "la", "lb", "offset", "vector", "y", "x", "d3", "bx0", "bx1", "bx2", "bx3", "dd", "dy", "checkOptions", "backend", "opts", "optsInfo", "fsName", "pendingValidators", "callbackCalled", "loopEnded", "optName", "opt", "providedValue", "incorrectOptions", "o", "typeMatches", "e", "wait", "ms", "resolve", "toPromise", "fn", "args", "reject", "cbArgs", "setImmediate", "cb", "ROOT_NODE_ID", "getEmptyDirNode", "randomUUID", "c", "r", "SimpleSyncRWTransaction", "store", "key", "val", "data", "overwrite", "value", "__name", "SyncKeyValueFile", "PreloadFile", "_fs", "_path", "_flag", "_stat", "contents", "SyncKeyValueFileSystem", "SynchronousFileSystem", "options", "p", "mode", "cred", "tx", "ApiError", "oldPath", "newPath", "oldParent", "dirname", "oldName", "basename", "newParent", "newName", "oldDirNode", "oldDirList", "nodeId", "newDirNode", "newDirList", "newNameNode", "e", "Buffer", "stats", "flag", "newFile", "FileType", "node", "FileFlag", "new_uid", "new_gid", "fileInodeId", "fileInode", "inodeChanged", "ROOT_NODE_ID", "currTime", "dirInode", "Inode", "randomUUID", "getEmptyDirNode", "parent", "filename", "visited", "currentPath", "posix", "readDirectory", "inode", "dirList", "resolve", "process_exports", "sep", "id", "currId", "type", "parentDir", "fname", "parentNode", "dirListing", "fileNode", "dataId", "fileNodeId", "isDir", "parentListing", "fileName", "CreateBackend", "options", "cb", "checkOptions", "fs", "err", "__name", "InMemoryStore", "InMemoryFileSystem", "type", "SimpleSyncRWTransaction", "key", "data", "overwrite", "__name", "_InMemoryFileSystem", "SyncKeyValueFileSystem", "CreateBackend", "_toUnixTimestamp", "time", "__name", "normalizeMode", "mode", "def", "trueMode", "normalizeTime", "ApiError", "normalizePath", "p", "posix", "normalizeOptions", "options", "defEnc", "defFlag", "defMode", "nop", "cred", "setCred", "val", "fdMap", "nextFd", "getFdForFile", "file", "fd", "fd2file", "mounts", "InMemoryFileSystem", "fs", "mount", "getMount", "mountPoint", "getMounts", "umount", "resolveFS", "path", "sortedMounts", "a", "b", "fixPaths", "text", "paths", "from", "to", "fixError", "e", "initialize", "mountMapping", "point", "promises_exports", "__export", "access", "appendFile", "chmod", "chown", "close", "constants_exports", "createReadStream", "createWriteStream", "exists", "fchmod", "fchown", "fdatasync", "fstat", "fsync", "ftruncate", "futimes", "lchmod", "lchown", "link", "lstat", "lutimes", "mkdir", "open", "read", "readFile", "readdir", "readlink", "realpath", "rename", "rmdir", "stat", "symlink", "truncate", "unlink", "unwatchFile", "utimes", "watch", "watchFile", "write", "writeFile", "doOp", "__async", "name", "resolveSymlinks", "path", "args", "normalizePath", "fs", "resolvedPath", "resolveFS", "exists", "realpath", "e", "fixError", "__name", "rename", "oldPath", "newPath", "_old", "_new", "paths", "cred", "data", "readFile", "writeFile", "unlink", "stat", "lstat", "truncate", "len", "ApiError", "open", "flag", "mode", "file", "FileFlag", "normalizeMode", "getFdForFile", "_0", "filename", "arg2", "options", "normalizeOptions", "arg3", "appendFile", "fstat", "fd", "fd2file", "close", "fdMap", "ftruncate", "fsync", "fdatasync", "write", "arg4", "arg5", "buffer", "offset", "length", "position", "encoding", "Buffer", "read", "fchown", "uid", "gid", "fchmod", "numMode", "futimes", "atime", "mtime", "normalizeTime", "rmdir", "mkdir", "readdir", "entries", "points", "mounts", "point", "entry", "link", "srcpath", "dstpath", "symlink", "type", "readlink", "chown", "lchown", "chmod", "lchmod", "utimes", "lutimes", "cache", "mountPoint", "dst", "watchFile", "_1", "listener", "nop", "unwatchFile", "watch", "access", "createReadStream", "createWriteStream", "rename", "oldPath", "newPath", "cb", "nop", "__name", "exists", "path", "stat", "stats", "lstat", "truncate", "arg2", "unlink", "open", "flag", "mode", "normalizeMode", "fd", "readFile", "filename", "writeFile", "data", "arg3", "appendFile", "fstat", "close", "ftruncate", "length", "fsync", "fdatasync", "write", "arg4", "arg5", "buffer", "offset", "position", "encoding", "ApiError", "Buffer", "_cb", "bytesWritten", "read", "bytesRead", "fchown", "uid", "gid", "fchmod", "futimes", "atime", "mtime", "rmdir", "mkdir", "readdir", "entries", "link", "srcpath", "dstpath", "symlink", "type", "readlink", "result", "chown", "lchown", "chmod", "lchmod", "utimes", "lutimes", "realpath", "cache", "access", "watchFile", "listener", "unwatchFile", "watch", "createReadStream", "options", "createWriteStream", "doOp", "name", "resolveSymlinks", "path", "args", "normalizePath", "fs", "resolvedPath", "resolveFS", "existsSync", "realpathSync", "e", "fixError", "__name", "renameSync", "oldPath", "newPath", "_old", "_new", "paths", "cred", "data", "readFileSync", "writeFileSync", "unlinkSync", "statSync", "lstatSync", "truncateSync", "len", "ApiError", "openSync", "flag", "mode", "file", "FileFlag", "normalizeMode", "getFdForFile", "filename", "arg2", "options", "normalizeOptions", "arg3", "appendFileSync", "fstatSync", "fd", "fd2file", "closeSync", "fdMap", "ftruncateSync", "fsyncSync", "fdatasyncSync", "writeSync", "arg4", "arg5", "buffer", "offset", "length", "position", "encoding", "Buffer", "readSync", "opts", "fchownSync", "uid", "gid", "fchmodSync", "numMode", "futimesSync", "atime", "mtime", "normalizeTime", "rmdirSync", "mkdirSync", "readdirSync", "entries", "points", "mounts", "point", "entry", "linkSync", "srcpath", "dstpath", "symlinkSync", "type", "readlinkSync", "chownSync", "lchownSync", "chmodSync", "lchmodSync", "utimesSync", "lutimesSync", "cache", "mountPoint", "dst", "accessSync", "fs", "emulation_exports", "fs_default", "MirrorFile", "PreloadFile", "fs", "path", "flag", "stat", "data", "__name", "_AsyncMirror", "SynchronousFileSystem", "sync", "async", "__spreadProps", "__spreadValues", "fd", "stats", "FileFlag", "oldPath", "newPath", "cred", "p", "mode", "new_uid", "new_gid", "atime", "mtime", "__async", "copyDirectory", "Cred", "files", "file", "copyItem", "join", "copyFile", "e", "op", "doNextOp", "err", "AsyncMirror", "CreateBackend", "v", "ApiError", "_FolderAdapter", "BaseFileSystem", "folder", "wrapped", "__spreadProps", "__spreadValues", "__async", "Cred", "ApiError", "FolderAdapter", "__name", "CreateBackend", "translateError", "e", "err", "p", "relative", "wrapCallback", "cb", "wrapFunction", "name", "wrapFirst", "wrapSecond", "join", "Mutex", "path", "resolve", "next", "__name", "LockedFS", "fs", "Mutex", "__spreadProps", "__spreadValues", "oldPath", "newPath", "cred", "__async", "p", "stats", "mode", "flag", "fd", "files", "exists", "resolvedPath", "len", "fname", "encoding", "data", "new_uid", "new_gid", "atime", "mtime", "srcpath", "dstpath", "type", "linkString", "__name", "deletionLogPath", "makeModeWritable", "mode", "__name", "getFlag", "f", "FileFlag", "OverlayFile", "PreloadFile", "fs", "path", "flag", "stats", "data", "__async", "UnlockedOverlayFS", "BaseFileSystem", "writable", "readable", "ApiError", "__spreadProps", "__spreadValues", "OverlayFS", "file", "Cred", "err", "log", "cred", "oldPath", "newPath", "oldStats", "name", "resolve", "p", "e", "oldStat", "Stats", "buf", "contents", "fPath", "seenMap", "fileP", "result", "new_uid", "new_gid", "atime", "mtime", "addition", "parent", "dirname", "toCreate", "pStats", "_OverlayFS", "LockedFS", "options", "__superGet", "CreateBackend", "backends", "registerBackend", "_backends", "backend", "backends", "__name", "AsyncMirror", "FolderAdapter", "InMemoryFileSystem", "OverlayFS", "LRUNode", "key", "value", "__name", "LRUCache", "limit", "node", "AsyncKeyValueFile", "PreloadFile", "_fs", "_path", "_flag", "_stat", "contents", "__async", "AsyncKeyValueFileSystem", "BaseFileSystem", "cacheSize", "store", "p", "mode", "cred", "tx", "inode", "ApiError", "oldPath", "newPath", "oldParent", "dirname", "oldName", "basename", "newParent", "newName", "oldDirNode", "oldDirList", "nodeId", "newDirNode", "newDirList", "newNameNode", "e", "Buffer", "stats", "flag", "data", "newFile", "FileType", "FileFlag", "new_uid", "new_gid", "fileInodeId", "fileInode", "inodeChanged", "ROOT_NODE_ID", "currTime", "dirInode", "Inode", "randomUUID", "getEmptyDirNode", "_0", "_1", "_2", "parent", "filename", "visited", "currentPath", "posix", "id", "dirList", "resolve", "retries", "reroll", "currId", "type", "parentDir", "fname", "parentNode", "dirListing", "dataId", "fileNode", "fileNodeId", "isDir", "parentListing", "fileName", "process_exports", "initialize", "mounts", "uid", "gid", "setCred", "Cred", "fs_default", "__name", "_configure", "config", "__async", "FileSystem", "point", "value", "getFileSystem", "configure", "cb", "err", "_getFileSystem", "_0", "fsName", "options", "ApiError", "props", "k", "prop", "opt", "fs", "fsc", "backends", "src_default", "fs_default"]
7
7
  }