browserfs
Version:
A filesystem in your browser!
1,632 lines (1,580 loc) • 842 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["BrowserFS"] = factory();
else
root["BrowserFS"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(Buffer, global, module, process) {'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var buffer = __webpack_require__(2);
var path = __webpack_require__(9);
/**
* Standard libc error codes. Add more to this enum and ErrorStrings as they are
* needed.
* @url http://www.gnu.org/software/libc/manual/html_node/Error-Codes.html
*/
/**
* Standard libc error codes. Add more to this enum and ErrorStrings as they are
* needed.
* @url http://www.gnu.org/software/libc/manual/html_node/Error-Codes.html
*/ var ErrorCode;
(function (ErrorCode) {
ErrorCode[ErrorCode["EPERM"] = 1] = "EPERM";
ErrorCode[ErrorCode["ENOENT"] = 2] = "ENOENT";
ErrorCode[ErrorCode["EIO"] = 5] = "EIO";
ErrorCode[ErrorCode["EBADF"] = 9] = "EBADF";
ErrorCode[ErrorCode["EACCES"] = 13] = "EACCES";
ErrorCode[ErrorCode["EBUSY"] = 16] = "EBUSY";
ErrorCode[ErrorCode["EEXIST"] = 17] = "EEXIST";
ErrorCode[ErrorCode["ENOTDIR"] = 20] = "ENOTDIR";
ErrorCode[ErrorCode["EISDIR"] = 21] = "EISDIR";
ErrorCode[ErrorCode["EINVAL"] = 22] = "EINVAL";
ErrorCode[ErrorCode["EFBIG"] = 27] = "EFBIG";
ErrorCode[ErrorCode["ENOSPC"] = 28] = "ENOSPC";
ErrorCode[ErrorCode["EROFS"] = 30] = "EROFS";
ErrorCode[ErrorCode["ENOTEMPTY"] = 39] = "ENOTEMPTY";
ErrorCode[ErrorCode["ENOTSUP"] = 95] = "ENOTSUP";
})(ErrorCode || (ErrorCode = {}));
/* tslint:disable:variable-name */
/**
* Strings associated with each error code.
* @hidden
*/
var ErrorStrings = {};
ErrorStrings[ErrorCode.EPERM] = 'Operation not permitted.';
ErrorStrings[ErrorCode.ENOENT] = 'No such file or directory.';
ErrorStrings[ErrorCode.EIO] = 'Input/output error.';
ErrorStrings[ErrorCode.EBADF] = 'Bad file descriptor.';
ErrorStrings[ErrorCode.EACCES] = 'Permission denied.';
ErrorStrings[ErrorCode.EBUSY] = 'Resource busy or locked.';
ErrorStrings[ErrorCode.EEXIST] = 'File exists.';
ErrorStrings[ErrorCode.ENOTDIR] = 'File is not a directory.';
ErrorStrings[ErrorCode.EISDIR] = 'File is a directory.';
ErrorStrings[ErrorCode.EINVAL] = 'Invalid argument.';
ErrorStrings[ErrorCode.EFBIG] = 'File is too big.';
ErrorStrings[ErrorCode.ENOSPC] = 'No space left on disk.';
ErrorStrings[ErrorCode.EROFS] = 'Cannot modify a read-only file system.';
ErrorStrings[ErrorCode.ENOTEMPTY] = 'Directory is not empty.';
ErrorStrings[ErrorCode.ENOTSUP] = 'Operation is not supported.';
/* tslint:enable:variable-name */
/**
* Represents a BrowserFS error. Passed back to applications after a failed
* call to the BrowserFS API.
*/
var ApiError = (function (Error) {
function ApiError(type, message, path$$1) {
if ( message === void 0 ) message = ErrorStrings[type];
Error.call(this, message);
// Unsupported.
this.syscall = "";
this.errno = type;
this.code = ErrorCode[type];
this.path = path$$1;
this.stack = new Error().stack;
this.message = "Error: " + (this.code) + ": " + message + (this.path ? (", '" + (this.path) + "'") : '');
}
if ( Error ) ApiError.__proto__ = Error;
ApiError.prototype = Object.create( Error && Error.prototype );
ApiError.prototype.constructor = ApiError;
ApiError.fromJSON = function fromJSON (json) {
var err = new ApiError(0);
err.errno = json.errno;
err.code = json.code;
err.path = json.path;
err.stack = json.stack;
err.message = json.message;
return err;
};
/**
* Creates an ApiError object from a buffer.
*/
ApiError.fromBuffer = function fromBuffer (buffer$$1, i) {
if ( i === void 0 ) i = 0;
return ApiError.fromJSON(JSON.parse(buffer$$1.toString('utf8', i + 4, i + 4 + buffer$$1.readUInt32LE(i))));
};
ApiError.FileError = function FileError (code, p) {
return new ApiError(code, ErrorStrings[code], p);
};
ApiError.ENOENT = function ENOENT (path$$1) {
return this.FileError(ErrorCode.ENOENT, path$$1);
};
ApiError.EEXIST = function EEXIST (path$$1) {
return this.FileError(ErrorCode.EEXIST, path$$1);
};
ApiError.EISDIR = function EISDIR (path$$1) {
return this.FileError(ErrorCode.EISDIR, path$$1);
};
ApiError.ENOTDIR = function ENOTDIR (path$$1) {
return this.FileError(ErrorCode.ENOTDIR, path$$1);
};
ApiError.EPERM = function EPERM (path$$1) {
return this.FileError(ErrorCode.EPERM, path$$1);
};
ApiError.ENOTEMPTY = function ENOTEMPTY (path$$1) {
return this.FileError(ErrorCode.ENOTEMPTY, path$$1);
};
/**
* @return A friendly error message.
*/
ApiError.prototype.toString = function toString () {
return this.message;
};
ApiError.prototype.toJSON = function toJSON () {
return {
errno: this.errno,
code: this.code,
path: this.path,
stack: this.stack,
message: this.message
};
};
/**
* Writes the API error into a buffer.
*/
ApiError.prototype.writeToBuffer = function writeToBuffer (buffer$$1, i) {
if ( buffer$$1 === void 0 ) buffer$$1 = Buffer.alloc(this.bufferSize());
if ( i === void 0 ) i = 0;
var bytesWritten = buffer$$1.write(JSON.stringify(this.toJSON()), i + 4);
buffer$$1.writeUInt32LE(bytesWritten, i);
return buffer$$1;
};
/**
* The size of the API error in buffer-form in bytes.
*/
ApiError.prototype.bufferSize = function bufferSize () {
// 4 bytes for string length.
return 4 + Buffer.byteLength(JSON.stringify(this.toJSON()));
};
return ApiError;
}(Error));
var api_error = Object.freeze({
get ErrorCode () { return ErrorCode; },
ErrorStrings: ErrorStrings,
ApiError: ApiError
});
var ActionType;
(function (ActionType) {
// Indicates that the code should not do anything.
ActionType[ActionType["NOP"] = 0] = "NOP";
// Indicates that the code should throw an exception.
ActionType[ActionType["THROW_EXCEPTION"] = 1] = "THROW_EXCEPTION";
// Indicates that the code should truncate the file, but only if it is a file.
ActionType[ActionType["TRUNCATE_FILE"] = 2] = "TRUNCATE_FILE";
// Indicates that the code should create the file.
ActionType[ActionType["CREATE_FILE"] = 3] = "CREATE_FILE";
})(ActionType || (ActionType = {}));
/**
* Represents one of the following file flags. A convenience object.
*
* * `'r'` - Open file for reading. An exception occurs if the file does not exist.
* * `'r+'` - Open file for reading and writing. An exception occurs if the file does not exist.
* * `'rs'` - Open file for reading in synchronous mode. Instructs the filesystem to not cache writes.
* * `'rs+'` - Open file for reading and writing, and opens the file in synchronous mode.
* * `'w'` - Open file for writing. The file is created (if it does not exist) or truncated (if it exists).
* * `'wx'` - Like 'w' but opens the file in exclusive mode.
* * `'w+'` - Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).
* * `'wx+'` - Like 'w+' but opens the file in exclusive mode.
* * `'a'` - Open file for appending. The file is created if it does not exist.
* * `'ax'` - Like 'a' but opens the file in exclusive mode.
* * `'a+'` - Open file for reading and appending. The file is created if it does not exist.
* * `'ax+'` - Like 'a+' but opens the file in exclusive mode.
*
* Exclusive mode ensures that the file path is newly created.
*/
var FileFlag = function FileFlag(flagStr) {
this.flagStr = flagStr;
if (FileFlag.validFlagStrs.indexOf(flagStr) < 0) {
throw new ApiError(ErrorCode.EINVAL, "Invalid flag: " + flagStr);
}
};
/**
* Get an object representing the given file flag.
* @param modeStr The string representing the flag
* @return The FileFlag object representing the flag
* @throw when the flag string is invalid
*/
FileFlag.getFileFlag = function getFileFlag (flagStr) {
// Check cache first.
if (FileFlag.flagCache.hasOwnProperty(flagStr)) {
return FileFlag.flagCache[flagStr];
}
return FileFlag.flagCache[flagStr] = new FileFlag(flagStr);
};
/**
* Get the underlying flag string for this flag.
*/
FileFlag.prototype.getFlagString = function getFlagString () {
return this.flagStr;
};
/**
* Returns true if the file is readable.
*/
FileFlag.prototype.isReadable = function isReadable () {
return this.flagStr.indexOf('r') !== -1 || this.flagStr.indexOf('+') !== -1;
};
/**
* Returns true if the file is writeable.
*/
FileFlag.prototype.isWriteable = function isWriteable () {
return this.flagStr.indexOf('w') !== -1 || this.flagStr.indexOf('a') !== -1 || this.flagStr.indexOf('+') !== -1;
};
/**
* Returns true if the file mode should truncate.
*/
FileFlag.prototype.isTruncating = function isTruncating () {
return this.flagStr.indexOf('w') !== -1;
};
/**
* Returns true if the file is appendable.
*/
FileFlag.prototype.isAppendable = function isAppendable () {
return this.flagStr.indexOf('a') !== -1;
};
/**
* Returns true if the file is open in synchronous mode.
*/
FileFlag.prototype.isSynchronous = function isSynchronous () {
return this.flagStr.indexOf('s') !== -1;
};
/**
* Returns true if the file is open in exclusive mode.
*/
FileFlag.prototype.isExclusive = function isExclusive () {
return this.flagStr.indexOf('x') !== -1;
};
/**
* Returns one of the static fields on this object that indicates the
* appropriate response to the path existing.
*/
FileFlag.prototype.pathExistsAction = function pathExistsAction () {
if (this.isExclusive()) {
return ActionType.THROW_EXCEPTION;
}
else if (this.isTruncating()) {
return ActionType.TRUNCATE_FILE;
}
else {
return ActionType.NOP;
}
};
/**
* Returns one of the static fields on this object that indicates the
* appropriate response to the path not existing.
*/
FileFlag.prototype.pathNotExistsAction = function pathNotExistsAction () {
if ((this.isWriteable() || this.isAppendable()) && this.flagStr !== 'r+') {
return ActionType.CREATE_FILE;
}
else {
return ActionType.THROW_EXCEPTION;
}
};
// Contains cached FileMode instances.
FileFlag.flagCache = {};
// Array of valid mode strings.
FileFlag.validFlagStrs = ['r', 'r+', 'rs', 'rs+', 'w', 'wx', 'w+', 'wx+', 'a', 'ax', 'a+', 'ax+'];
/**
* Indicates the type of the given file. Applied to 'mode'.
*/
var FileType;
(function (FileType) {
FileType[FileType["FILE"] = 32768] = "FILE";
FileType[FileType["DIRECTORY"] = 16384] = "DIRECTORY";
FileType[FileType["SYMLINK"] = 40960] = "SYMLINK";
})(FileType || (FileType = {}));
/**
* Emulation of Node's `fs.Stats` object.
*
* Attribute descriptions are from `man 2 stat'
* @see http://nodejs.org/api/fs.html#fs_class_fs_stats
* @see http://man7.org/linux/man-pages/man2/stat.2.html
*/
var Stats = function Stats(itemType, size, mode, atime, mtime, ctime) {
if ( atime === void 0 ) atime = new Date();
if ( mtime === void 0 ) mtime = new Date();
if ( ctime === void 0 ) ctime = new Date();
this.size = size;
this.atime = atime;
this.mtime = mtime;
this.ctime = ctime;
/**
* UNSUPPORTED ATTRIBUTES
* I assume no one is going to need these details, although we could fake
* appropriate values if need be.
*/
// ID of device containing file
this.dev = 0;
// inode number
this.ino = 0;
// device ID (if special file)
this.rdev = 0;
// number of hard links
this.nlink = 1;
// blocksize for file system I/O
this.blksize = 4096;
// @todo Maybe support these? atm, it's a one-user filesystem.
// user ID of owner
this.uid = 0;
// group ID of owner
this.gid = 0;
// time file was created (currently unsupported)
this.birthtime = new Date(0);
// XXX: Some file systems stash data on stats objects.
this.fileData = null;
if (!mode) {
switch (itemType) {
case FileType.FILE:
this.mode = 0x1a4;
break;
case FileType.DIRECTORY:
default:
this.mode = 0x1ff;
}
}
else {
this.mode = mode;
}
// number of 512B blocks allocated
this.blocks = Math.ceil(size / 512);
// Check if mode also includes top-most bits, which indicate the file's
// type.
if (this.mode < 0x1000) {
this.mode |= itemType;
}
};
Stats.fromBuffer = function fromBuffer (buffer$$1) {
var size = buffer$$1.readUInt32LE(0), mode = buffer$$1.readUInt32LE(4), atime = buffer$$1.readDoubleLE(8), mtime = buffer$$1.readDoubleLE(16), ctime = buffer$$1.readDoubleLE(24);
return new Stats(mode & 0xF000, size, mode & 0xFFF, new Date(atime), new Date(mtime), new Date(ctime));
};
Stats.prototype.toBuffer = function toBuffer () {
var buffer$$1 = Buffer.alloc(32);
buffer$$1.writeUInt32LE(this.size, 0);
buffer$$1.writeUInt32LE(this.mode, 4);
buffer$$1.writeDoubleLE(this.atime.getTime(), 8);
buffer$$1.writeDoubleLE(this.mtime.getTime(), 16);
buffer$$1.writeDoubleLE(this.ctime.getTime(), 24);
return buffer$$1;
};
/**
* **Nonstandard**: Clone the stats object.
* @return [BrowserFS.node.fs.Stats]
*/
Stats.prototype.clone = function clone () {
return new Stats(this.mode & 0xF000, this.size, this.mode & 0xFFF, this.atime, this.mtime, this.ctime);
};
/**
* @return [Boolean] True if this item is a file.
*/
Stats.prototype.isFile = function isFile () {
return (this.mode & 0xF000) === FileType.FILE;
};
/**
* @return [Boolean] True if this item is a directory.
*/
Stats.prototype.isDirectory = function isDirectory () {
return (this.mode & 0xF000) === FileType.DIRECTORY;
};
/**
* @return [Boolean] True if this item is a symbolic link (only valid through lstat)
*/
Stats.prototype.isSymbolicLink = function isSymbolicLink () {
return (this.mode & 0xF000) === FileType.SYMLINK;
};
/**
* Change the mode of the file. We use this helper function to prevent messing
* up the type of the file, which is encoded in mode.
*/
Stats.prototype.chmod = function chmod (mode) {
this.mode = (this.mode & 0xF000) | mode;
};
// We don't support the following types of files.
Stats.prototype.isSocket = function isSocket () {
return false;
};
Stats.prototype.isBlockDevice = function isBlockDevice () {
return false;
};
Stats.prototype.isCharacterDevice = function isCharacterDevice () {
return false;
};
Stats.prototype.isFIFO = function isFIFO () {
return false;
};
/**
* Wraps a callback function. Used for unit testing. Defaults to a NOP.
* @hidden
*/
var wrapCb = function (cb, numArgs) {
return cb;
};
/**
* @hidden
*/
function assertRoot(fs) {
if (fs) {
return fs;
}
throw new ApiError(ErrorCode.EIO, "Initialize BrowserFS with a file system using BrowserFS.initialize(filesystem)");
}
/**
* @hidden
*/
function normalizeMode(mode, def) {
switch (typeof mode) {
case 'number':
// (path, flag, mode, cb?)
return mode;
case 'string':
// (path, flag, modeString, cb?)
var trueMode = parseInt(mode, 8);
if (!isNaN(trueMode)) {
return trueMode;
}
// Invalid string.
return def;
default:
return def;
}
}
/**
* @hidden
*/
function normalizeTime(time) {
if (time instanceof Date) {
return time;
}
else if (typeof time === 'number') {
return new Date(time * 1000);
}
else {
throw new ApiError(ErrorCode.EINVAL, "Invalid time.");
}
}
/**
* @hidden
*/
function normalizePath(p) {
// Node doesn't allow null characters in paths.
if (p.indexOf('\u0000') >= 0) {
throw new ApiError(ErrorCode.EINVAL, 'Path must be a string without null bytes.');
}
else if (p === '') {
throw new ApiError(ErrorCode.EINVAL, 'Path must not be empty.');
}
return path.resolve(p);
}
/**
* @hidden
*/
function normalizeOptions(options, defEnc, defFlag, defMode) {
switch (typeof options) {
case 'object':
return {
encoding: typeof options['encoding'] !== 'undefined' ? options['encoding'] : defEnc,
flag: typeof options['flag'] !== 'undefined' ? options['flag'] : defFlag,
mode: normalizeMode(options['mode'], defMode)
};
case 'string':
return {
encoding: options,
flag: defFlag,
mode: defMode
};
default:
return {
encoding: defEnc,
flag: defFlag,
mode: defMode
};
}
}
/**
* The default callback is a NOP.
* @hidden
* @private
*/
function nopCb() {
// NOP.
}
/**
* The node frontend to all filesystems.
* This layer handles:
*
* * Sanity checking inputs.
* * Normalizing paths.
* * Resetting stack depth for asynchronous operations which may not go through
* the browser by wrapping all input callbacks using `setImmediate`.
* * Performing the requested operation through the filesystem or the file
* descriptor, as appropriate.
* * Handling optional arguments and setting default arguments.
* @see http://nodejs.org/api/fs.html
*/
var FS = function FS() {
/* tslint:enable:variable-name */
this.F_OK = 0;
this.R_OK = 4;
this.W_OK = 2;
this.X_OK = 1;
this.root = null;
this.fdMap = {};
this.nextFd = 100;
};
FS.prototype.initialize = function initialize (rootFS) {
if (!rootFS.constructor.isAvailable()) {
throw new ApiError(ErrorCode.EINVAL, 'Tried to instantiate BrowserFS with an unavailable file system.');
}
return this.root = rootFS;
};
/**
* converts Date or number to a fractional UNIX timestamp
* Grabbed from NodeJS sources (lib/fs.js)
*/
FS.prototype._toUnixTimestamp = function _toUnixTimestamp (time) {
if (typeof time === 'number') {
return time;
}
else if (time instanceof Date) {
return time.getTime() / 1000;
}
throw new Error("Cannot parse time: " + time);
};
/**
* **NONSTANDARD**: Grab the FileSystem instance that backs this API.
* @return [BrowserFS.FileSystem | null] Returns null if the file system has
* not been initialized.
*/
FS.prototype.getRootFS = function getRootFS () {
if (this.root) {
return this.root;
}
else {
return null;
}
};
// FILE OR DIRECTORY METHODS
/**
* Asynchronous rename. No arguments other than a possible exception are given
* to the completion callback.
* @param oldPath
* @param newPath
* @param callback
*/
FS.prototype.rename = function rename (oldPath, newPath, cb) {
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 1);
try {
assertRoot(this.root).rename(normalizePath(oldPath), normalizePath(newPath), newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous rename.
* @param oldPath
* @param newPath
*/
FS.prototype.renameSync = function renameSync (oldPath, newPath) {
assertRoot(this.root).renameSync(normalizePath(oldPath), normalizePath(newPath));
};
/**
* Test whether or not the given path exists by checking with the file system.
* Then call the callback argument with either true or false.
* @example Sample invocation
* fs.exists('/etc/passwd', function (exists) {
* util.debug(exists ? "it's there" : "no passwd!");
* });
* @param path
* @param callback
*/
FS.prototype.exists = function exists (path$$1, cb) {
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 1);
try {
return assertRoot(this.root).exists(normalizePath(path$$1), newCb);
}
catch (e) {
// Doesn't return an error. If something bad happens, we assume it just
// doesn't exist.
return newCb(false);
}
};
/**
* Test whether or not the given path exists by checking with the file system.
* @param path
* @return [boolean]
*/
FS.prototype.existsSync = function existsSync (path$$1) {
try {
return assertRoot(this.root).existsSync(normalizePath(path$$1));
}
catch (e) {
// Doesn't return an error. If something bad happens, we assume it just
// doesn't exist.
return false;
}
};
/**
* Asynchronous `stat`.
* @param path
* @param callback
*/
FS.prototype.stat = function stat (path$$1, cb) {
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 2);
try {
return assertRoot(this.root).stat(normalizePath(path$$1), false, newCb);
}
catch (e) {
return newCb(e);
}
};
/**
* Synchronous `stat`.
* @param path
* @return [BrowserFS.node.fs.Stats]
*/
FS.prototype.statSync = function statSync (path$$1) {
return assertRoot(this.root).statSync(normalizePath(path$$1), false);
};
/**
* Asynchronous `lstat`.
* `lstat()` is identical to `stat()`, except that if path is a symbolic link,
* then the link itself is stat-ed, not the file that it refers to.
* @param path
* @param callback
*/
FS.prototype.lstat = function lstat (path$$1, cb) {
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 2);
try {
return assertRoot(this.root).stat(normalizePath(path$$1), true, newCb);
}
catch (e) {
return newCb(e);
}
};
/**
* Synchronous `lstat`.
* `lstat()` is identical to `stat()`, except that if path is a symbolic link,
* then the link itself is stat-ed, not the file that it refers to.
* @param path
* @return [BrowserFS.node.fs.Stats]
*/
FS.prototype.lstatSync = function lstatSync (path$$1) {
return assertRoot(this.root).statSync(normalizePath(path$$1), true);
};
FS.prototype.truncate = function truncate (path$$1, arg2, cb) {
if ( arg2 === void 0 ) arg2 = 0;
if ( cb === void 0 ) cb = nopCb;
var len = 0;
if (typeof arg2 === 'function') {
cb = arg2;
}
else if (typeof arg2 === 'number') {
len = arg2;
}
var newCb = wrapCb(cb, 1);
try {
if (len < 0) {
throw new ApiError(ErrorCode.EINVAL);
}
return assertRoot(this.root).truncate(normalizePath(path$$1), len, newCb);
}
catch (e) {
return newCb(e);
}
};
/**
* Synchronous `truncate`.
* @param path
* @param len
*/
FS.prototype.truncateSync = function truncateSync (path$$1, len) {
if ( len === void 0 ) len = 0;
if (len < 0) {
throw new ApiError(ErrorCode.EINVAL);
}
return assertRoot(this.root).truncateSync(normalizePath(path$$1), len);
};
/**
* Asynchronous `unlink`.
* @param path
* @param callback
*/
FS.prototype.unlink = function unlink (path$$1, cb) {
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 1);
try {
return assertRoot(this.root).unlink(normalizePath(path$$1), newCb);
}
catch (e) {
return newCb(e);
}
};
/**
* Synchronous `unlink`.
* @param path
*/
FS.prototype.unlinkSync = function unlinkSync (path$$1) {
return assertRoot(this.root).unlinkSync(normalizePath(path$$1));
};
FS.prototype.open = function open (path$$1, flag, arg2, cb) {
var this$1 = this;
if ( cb === void 0 ) cb = nopCb;
var mode = normalizeMode(arg2, 0x1a4);
cb = typeof arg2 === 'function' ? arg2 : cb;
var newCb = wrapCb(cb, 2);
try {
assertRoot(this.root).open(normalizePath(path$$1), FileFlag.getFileFlag(flag), mode, function (e, file) {
if (file) {
newCb(e, this$1.getFdForFile(file));
}
else {
newCb(e);
}
});
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous file open.
* @see http://www.manpagez.com/man/2/open/
* @param path
* @param flags
* @param mode defaults to `0644`
* @return [BrowserFS.File]
*/
FS.prototype.openSync = function openSync (path$$1, flag, mode) {
if ( mode === void 0 ) mode = 0x1a4;
return this.getFdForFile(assertRoot(this.root).openSync(normalizePath(path$$1), FileFlag.getFileFlag(flag), normalizeMode(mode, 0x1a4)));
};
FS.prototype.readFile = function readFile (filename, arg2, cb) {
if ( arg2 === void 0 ) arg2 = {};
if ( cb === void 0 ) cb = nopCb;
var options = normalizeOptions(arg2, null, 'r', null);
cb = typeof arg2 === 'function' ? arg2 : cb;
var newCb = wrapCb(cb, 2);
try {
var flag = FileFlag.getFileFlag(options['flag']);
if (!flag.isReadable()) {
return newCb(new ApiError(ErrorCode.EINVAL, 'Flag passed to readFile must allow for reading.'));
}
return assertRoot(this.root).readFile(normalizePath(filename), options.encoding, flag, newCb);
}
catch (e) {
return newCb(e);
}
};
FS.prototype.readFileSync = function readFileSync (filename, arg2) {
if ( arg2 === void 0 ) arg2 = {};
var options = normalizeOptions(arg2, null, 'r', null);
var flag = FileFlag.getFileFlag(options.flag);
if (!flag.isReadable()) {
throw new ApiError(ErrorCode.EINVAL, 'Flag passed to readFile must allow for reading.');
}
return assertRoot(this.root).readFileSync(normalizePath(filename), options.encoding, flag);
};
FS.prototype.writeFile = function writeFile (filename, data, arg3, cb) {
if ( arg3 === void 0 ) arg3 = {};
if ( cb === void 0 ) cb = nopCb;
var options = normalizeOptions(arg3, 'utf8', 'w', 0x1a4);
cb = typeof arg3 === 'function' ? arg3 : cb;
var newCb = wrapCb(cb, 1);
try {
var flag = FileFlag.getFileFlag(options.flag);
if (!flag.isWriteable()) {
return newCb(new ApiError(ErrorCode.EINVAL, 'Flag passed to writeFile must allow for writing.'));
}
return assertRoot(this.root).writeFile(normalizePath(filename), data, options.encoding, flag, options.mode, newCb);
}
catch (e) {
return newCb(e);
}
};
FS.prototype.writeFileSync = function writeFileSync (filename, data, arg3) {
var options = normalizeOptions(arg3, 'utf8', 'w', 0x1a4);
var flag = FileFlag.getFileFlag(options.flag);
if (!flag.isWriteable()) {
throw new ApiError(ErrorCode.EINVAL, 'Flag passed to writeFile must allow for writing.');
}
return assertRoot(this.root).writeFileSync(normalizePath(filename), data, options.encoding, flag, options.mode);
};
FS.prototype.appendFile = function appendFile (filename, data, arg3, cb) {
if ( cb === void 0 ) cb = nopCb;
var options = normalizeOptions(arg3, 'utf8', 'a', 0x1a4);
cb = typeof arg3 === 'function' ? arg3 : cb;
var newCb = wrapCb(cb, 1);
try {
var flag = FileFlag.getFileFlag(options.flag);
if (!flag.isAppendable()) {
return newCb(new ApiError(ErrorCode.EINVAL, 'Flag passed to appendFile must allow for appending.'));
}
assertRoot(this.root).appendFile(normalizePath(filename), data, options.encoding, flag, options.mode, newCb);
}
catch (e) {
newCb(e);
}
};
FS.prototype.appendFileSync = function appendFileSync (filename, data, arg3) {
var options = normalizeOptions(arg3, 'utf8', 'a', 0x1a4);
var flag = FileFlag.getFileFlag(options.flag);
if (!flag.isAppendable()) {
throw new ApiError(ErrorCode.EINVAL, 'Flag passed to appendFile must allow for appending.');
}
return assertRoot(this.root).appendFileSync(normalizePath(filename), data, options.encoding, flag, options.mode);
};
// FILE DESCRIPTOR METHODS
/**
* Asynchronous `fstat`.
* `fstat()` is identical to `stat()`, except that the file to be stat-ed is
* specified by the file descriptor `fd`.
* @param fd
* @param callback
*/
FS.prototype.fstat = function fstat (fd, cb) {
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 2);
try {
var file = this.fd2file(fd);
file.stat(newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous `fstat`.
* `fstat()` is identical to `stat()`, except that the file to be stat-ed is
* specified by the file descriptor `fd`.
* @param fd
* @return [BrowserFS.node.fs.Stats]
*/
FS.prototype.fstatSync = function fstatSync (fd) {
return this.fd2file(fd).statSync();
};
/**
* Asynchronous close.
* @param fd
* @param callback
*/
FS.prototype.close = function close (fd, cb) {
var this$1 = this;
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 1);
try {
this.fd2file(fd).close(function (e) {
if (!e) {
this$1.closeFd(fd);
}
newCb(e);
});
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous close.
* @param fd
*/
FS.prototype.closeSync = function closeSync (fd) {
this.fd2file(fd).closeSync();
this.closeFd(fd);
};
FS.prototype.ftruncate = function ftruncate (fd, arg2, cb) {
if ( cb === void 0 ) cb = nopCb;
var length = typeof arg2 === 'number' ? arg2 : 0;
cb = typeof arg2 === 'function' ? arg2 : cb;
var newCb = wrapCb(cb, 1);
try {
var file = this.fd2file(fd);
if (length < 0) {
throw new ApiError(ErrorCode.EINVAL);
}
file.truncate(length, newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous ftruncate.
* @param fd
* @param len
*/
FS.prototype.ftruncateSync = function ftruncateSync (fd, len) {
if ( len === void 0 ) len = 0;
var file = this.fd2file(fd);
if (len < 0) {
throw new ApiError(ErrorCode.EINVAL);
}
file.truncateSync(len);
};
/**
* Asynchronous fsync.
* @param fd
* @param callback
*/
FS.prototype.fsync = function fsync (fd, cb) {
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 1);
try {
this.fd2file(fd).sync(newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous fsync.
* @param fd
*/
FS.prototype.fsyncSync = function fsyncSync (fd) {
this.fd2file(fd).syncSync();
};
/**
* Asynchronous fdatasync.
* @param fd
* @param callback
*/
FS.prototype.fdatasync = function fdatasync (fd, cb) {
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 1);
try {
this.fd2file(fd).datasync(newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous fdatasync.
* @param fd
*/
FS.prototype.fdatasyncSync = function fdatasyncSync (fd) {
this.fd2file(fd).datasyncSync();
};
FS.prototype.write = function write (fd, arg2, arg3, arg4, arg5, cb) {
if ( cb === void 0 ) cb = nopCb;
var buffer$$1, offset, length, position = null;
if (typeof arg2 === 'string') {
// Signature 1: (fd, string, [position?, [encoding?]], cb?)
var encoding = 'utf8';
switch (typeof arg3) {
case 'function':
// (fd, string, cb)
cb = arg3;
break;
case 'number':
// (fd, string, position, encoding?, cb?)
position = arg3;
encoding = typeof arg4 === 'string' ? arg4 : 'utf8';
cb = typeof arg5 === 'function' ? arg5 : cb;
break;
default:
// ...try to find the callback and get out of here!
cb = typeof arg4 === 'function' ? arg4 : typeof arg5 === 'function' ? arg5 : cb;
return cb(new ApiError(ErrorCode.EINVAL, 'Invalid arguments.'));
}
buffer$$1 = Buffer.from(arg2, encoding);
offset = 0;
length = buffer$$1.length;
}
else {
// Signature 2: (fd, buffer, offset, length, position?, cb?)
buffer$$1 = arg2;
offset = arg3;
length = arg4;
position = typeof arg5 === 'number' ? arg5 : null;
cb = typeof arg5 === 'function' ? arg5 : cb;
}
var newCb = wrapCb(cb, 3);
try {
var file = this.fd2file(fd);
if (position === undefined || position === null) {
position = file.getPos();
}
file.write(buffer$$1, offset, length, position, newCb);
}
catch (e) {
newCb(e);
}
};
FS.prototype.writeSync = function writeSync (fd, arg2, arg3, arg4, arg5) {
var buffer$$1, offset = 0, length, position;
if (typeof arg2 === 'string') {
// Signature 1: (fd, string, [position?, [encoding?]])
position = typeof arg3 === 'number' ? arg3 : null;
var encoding = typeof arg4 === 'string' ? arg4 : 'utf8';
offset = 0;
buffer$$1 = Buffer.from(arg2, encoding);
length = buffer$$1.length;
}
else {
// Signature 2: (fd, buffer, offset, length, position?)
buffer$$1 = arg2;
offset = arg3;
length = arg4;
position = typeof arg5 === 'number' ? arg5 : null;
}
var file = this.fd2file(fd);
if (position === undefined || position === null) {
position = file.getPos();
}
return file.writeSync(buffer$$1, offset, length, position);
};
FS.prototype.read = function read (fd, arg2, arg3, arg4, arg5, cb) {
if ( cb === void 0 ) cb = nopCb;
var position, offset, length, buffer$$1, newCb;
if (typeof arg2 === 'number') {
// legacy interface
// (fd, length, position, encoding, callback)
length = arg2;
position = arg3;
var encoding = arg4;
cb = typeof arg5 === 'function' ? arg5 : cb;
offset = 0;
buffer$$1 = Buffer.alloc(length);
// XXX: Inefficient.
// Wrap the cb so we shelter upper layers of the API from these
// shenanigans.
newCb = wrapCb(function (err, bytesRead, buf) {
if (err) {
return cb(err);
}
cb(err, buf.toString(encoding), bytesRead);
}, 3);
}
else {
buffer$$1 = arg2;
offset = arg3;
length = arg4;
position = arg5;
newCb = wrapCb(cb, 3);
}
try {
var file = this.fd2file(fd);
if (position === undefined || position === null) {
position = file.getPos();
}
file.read(buffer$$1, offset, length, position, newCb);
}
catch (e) {
newCb(e);
}
};
FS.prototype.readSync = function readSync (fd, arg2, arg3, arg4, arg5) {
var shenanigans = false;
var buffer$$1, offset, length, position, encoding = 'utf8';
if (typeof arg2 === 'number') {
length = arg2;
position = arg3;
encoding = arg4;
offset = 0;
buffer$$1 = Buffer.alloc(length);
shenanigans = true;
}
else {
buffer$$1 = arg2;
offset = arg3;
length = arg4;
position = arg5;
}
var file = this.fd2file(fd);
if (position === undefined || position === null) {
position = file.getPos();
}
var rv = file.readSync(buffer$$1, offset, length, position);
if (!shenanigans) {
return rv;
}
else {
return [buffer$$1.toString(encoding), rv];
}
};
/**
* Asynchronous `fchown`.
* @param fd
* @param uid
* @param gid
* @param callback
*/
FS.prototype.fchown = function fchown (fd, uid, gid, callback) {
if ( callback === void 0 ) callback = nopCb;
var newCb = wrapCb(callback, 1);
try {
this.fd2file(fd).chown(uid, gid, newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous `fchown`.
* @param fd
* @param uid
* @param gid
*/
FS.prototype.fchownSync = function fchownSync (fd, uid, gid) {
this.fd2file(fd).chownSync(uid, gid);
};
/**
* Asynchronous `fchmod`.
* @param fd
* @param mode
* @param callback
*/
FS.prototype.fchmod = function fchmod (fd, mode, cb) {
var newCb = wrapCb(cb, 1);
try {
var numMode = typeof mode === 'string' ? parseInt(mode, 8) : mode;
this.fd2file(fd).chmod(numMode, newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous `fchmod`.
* @param fd
* @param mode
*/
FS.prototype.fchmodSync = function fchmodSync (fd, mode) {
var numMode = typeof mode === 'string' ? parseInt(mode, 8) : mode;
this.fd2file(fd).chmodSync(numMode);
};
/**
* Change the file timestamps of a file referenced by the supplied file
* descriptor.
* @param fd
* @param atime
* @param mtime
* @param callback
*/
FS.prototype.futimes = function futimes (fd, atime, mtime, cb) {
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 1);
try {
var file = this.fd2file(fd);
if (typeof atime === 'number') {
atime = new Date(atime * 1000);
}
if (typeof mtime === 'number') {
mtime = new Date(mtime * 1000);
}
file.utimes(atime, mtime, newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Change the file timestamps of a file referenced by the supplied file
* descriptor.
* @param fd
* @param atime
* @param mtime
*/
FS.prototype.futimesSync = function futimesSync (fd, atime, mtime) {
this.fd2file(fd).utimesSync(normalizeTime(atime), normalizeTime(mtime));
};
// DIRECTORY-ONLY METHODS
/**
* Asynchronous `rmdir`.
* @param path
* @param callback
*/
FS.prototype.rmdir = function rmdir (path$$1, cb) {
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 1);
try {
path$$1 = normalizePath(path$$1);
assertRoot(this.root).rmdir(path$$1, newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous `rmdir`.
* @param path
*/
FS.prototype.rmdirSync = function rmdirSync (path$$1) {
path$$1 = normalizePath(path$$1);
return assertRoot(this.root).rmdirSync(path$$1);
};
/**
* Asynchronous `mkdir`.
* @param path
* @param mode defaults to `0777`
* @param callback
*/
FS.prototype.mkdir = function mkdir (path$$1, mode, cb) {
if ( cb === void 0 ) cb = nopCb;
if (typeof mode === 'function') {
cb = mode;
mode = 0x1ff;
}
var newCb = wrapCb(cb, 1);
try {
path$$1 = normalizePath(path$$1);
assertRoot(this.root).mkdir(path$$1, mode, newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous `mkdir`.
* @param path
* @param mode defaults to `0777`
*/
FS.prototype.mkdirSync = function mkdirSync (path$$1, mode) {
assertRoot(this.root).mkdirSync(normalizePath(path$$1), normalizeMode(mode, 0x1ff));
};
/**
* Asynchronous `readdir`. Reads the contents of a directory.
* The callback gets two arguments `(err, files)` where `files` is an array of
* the names of the files in the directory excluding `'.'` and `'..'`.
* @param path
* @param callback
*/
FS.prototype.readdir = function readdir (path$$1, cb) {
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 2);
try {
path$$1 = normalizePath(path$$1);
assertRoot(this.root).readdir(path$$1, newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous `readdir`. Reads the contents of a directory.
* @param path
* @return [String[]]
*/
FS.prototype.readdirSync = function readdirSync (path$$1) {
path$$1 = normalizePath(path$$1);
return assertRoot(this.root).readdirSync(path$$1);
};
// SYMLINK METHODS
/**
* Asynchronous `link`.
* @param srcpath
* @param dstpath
* @param callback
*/
FS.prototype.link = function link (srcpath, dstpath, cb) {
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 1);
try {
srcpath = normalizePath(srcpath);
dstpath = normalizePath(dstpath);
assertRoot(this.root).link(srcpath, dstpath, newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous `link`.
* @param srcpath
* @param dstpath
*/
FS.prototype.linkSync = function linkSync (srcpath, dstpath) {
srcpath = normalizePath(srcpath);
dstpath = normalizePath(dstpath);
return assertRoot(this.root).linkSync(srcpath, dstpath);
};
FS.prototype.symlink = function symlink (srcpath, dstpath, arg3, cb) {
if ( cb === void 0 ) cb = nopCb;
var type = typeof arg3 === 'string' ? arg3 : 'file';
cb = typeof arg3 === 'function' ? arg3 : cb;
var newCb = wrapCb(cb, 1);
try {
if (type !== 'file' && type !== 'dir') {
return newCb(new ApiError(ErrorCode.EINVAL, "Invalid type: " + type));
}
srcpath = normalizePath(srcpath);
dstpath = normalizePath(dstpath);
assertRoot(this.root).symlink(srcpath, dstpath, type, newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous `symlink`.
* @param srcpath
* @param dstpath
* @param type can be either `'dir'` or `'file'` (default is `'file'`)
*/
FS.prototype.symlinkSync = function symlinkSync (srcpath, dstpath, type) {
if (!type) {
type = 'file';
}
else if (type !== 'file' && type !== 'dir') {
throw new ApiError(ErrorCode.EINVAL, "Invalid type: " + type);
}
srcpath = normalizePath(srcpath);
dstpath = normalizePath(dstpath);
return assertRoot(this.root).symlinkSync(srcpath, dstpath, type);
};
/**
* Asynchronous readlink.
* @param path
* @param callback
*/
FS.prototype.readlink = function readlink (path$$1, cb) {
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 2);
try {
path$$1 = normalizePath(path$$1);
assertRoot(this.root).readlink(path$$1, newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous readlink.
* @param path
* @return [String]
*/
FS.prototype.readlinkSync = function readlinkSync (path$$1) {
path$$1 = normalizePath(path$$1);
return assertRoot(this.root).readlinkSync(path$$1);
};
// PROPERTY OPERATIONS
/**
* Asynchronous `chown`.
* @param path
* @param uid
* @param gid
* @param callback
*/
FS.prototype.chown = function chown (path$$1, uid, gid, cb) {
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 1);
try {
path$$1 = normalizePath(path$$1);
assertRoot(this.root).chown(path$$1, false, uid, gid, newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous `chown`.
* @param path
* @param uid
* @param gid
*/
FS.prototype.chownSync = function chownSync (path$$1, uid, gid) {
path$$1 = normalizePath(path$$1);
assertRoot(this.root).chownSync(path$$1, false, uid, gid);
};
/**
* Asynchronous `lchown`.
* @param path
* @param uid
* @param gid
* @param callback
*/
FS.prototype.lchown = function lchown (path$$1, uid, gid, cb) {
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 1);
try {
path$$1 = normalizePath(path$$1);
assertRoot(this.root).chown(path$$1, true, uid, gid, newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous `lchown`.
* @param path
* @param uid
* @param gid
*/
FS.prototype.lchownSync = function lchownSync (path$$1, uid, gid) {
path$$1 = normalizePath(path$$1);
assertRoot(this.root).chownSync(path$$1, true, uid, gid);
};
/**
* Asynchronous `chmod`.
* @param path
* @param mode
* @param callback
*/
FS.prototype.chmod = function chmod (path$$1, mode, cb) {
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 1);
try {
var numMode = normalizeMode(mode, -1);
if (numMode < 0) {
throw new ApiError(ErrorCode.EINVAL, "Invalid mode.");
}
assertRoot(this.root).chmod(normalizePath(path$$1), false, numMode, newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous `chmod`.
* @param path
* @param mode
*/
FS.prototype.chmodSync = function chmodSync (path$$1, mode) {
var numMode = normalizeMode(mode, -1);
if (numMode < 0) {
throw new ApiError(ErrorCode.EINVAL, "Invalid mode.");
}
path$$1 = normalizePath(path$$1);
assertRoot(this.root).chmodSync(path$$1, false, numMode);
};
/**
* Asynchronous `lchmod`.
* @param path
* @param mode
* @param callback
*/
FS.prototype.lchmod = function lchmod (path$$1, mode, cb) {
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 1);
try {
var numMode = normalizeMode(mode, -1);
if (numMode < 0) {
throw new ApiError(ErrorCode.EINVAL, "Invalid mode.");
}
assertRoot(this.root).chmod(normalizePath(path$$1), true, numMode, newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous `lchmod`.
* @param path
* @param mode
*/
FS.prototype.lchmodSync = function lchmodSync (path$$1, mode) {
var numMode = normalizeMode(mode, -1);
if (numMode < 1) {
throw new ApiError(ErrorCode.EINVAL, "Invalid mode.");
}
assertRoot(this.root).chmodSync(normalizePath(path$$1), true, numMode);
};
/**
* Change file timestamps of the file referenced by the supplied path.
* @param path
* @param atime
* @param mtime
* @param callback
*/
FS.prototype.utimes = function utimes (path$$1, atime, mtime, cb) {
if ( cb === void 0 ) cb = nopCb;
var newCb = wrapCb(cb, 1);
try {
assertRoot(this.root).utimes(normalizePath(path$$1), normalizeTime(atime), normalizeTime(mtime), newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Change file timestamps of the file referenced by the supplied path.
* @param path
* @param atime
* @param mtime
*/
FS.prototype.utimesSync = function utimesSync (path$$1, atime, mtime) {
assertRoot(this.root).utimesSync(normalizePath(path$$1), normalizeTime(atime), normalizeTime(mtime));
};
FS.prototype.realpath = function realpath (path$$1, arg2, cb) {
if ( cb === void 0 ) cb = nopCb;
var cache = typeof (arg2) === 'object' ? arg2 : {};
cb = typeof (arg2) === 'function' ? arg2 : nopCb;
var newCb = wrapCb(cb, 2);
try {
path$$1 = normalizePath(path$$1);
assertRoot(this.root).realpath(path$$1, cache, newCb);
}
catch (e) {
newCb(e);
}
};
/**
* Synchronous `realpath`.
* @param path
* @param cache An object literal of mapped paths that can be used to
* force a specific path resolution or avoid additional `fs.stat` calls for
* known real paths.
* @return [String]
*/
FS.prototype.realpathSync = function realpathSync (path$$1, cache) {
if ( cache === void 0 ) cache = {};
path$$1 = normalizePath(path$$1);
return assertRoot(this.root).realpathSync(path$$1, cache);
};
FS.prototype.watchFile = function watchFile (filename, arg2, listener) {
if ( listener === void 0 ) listener = nopCb;
throw new ApiError(ErrorCode.ENOTSUP);
};
FS.prototype.unwatchFile = function unwatchFile (filename, listener)