memfs 3.5.2 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/Dirent.js CHANGED
@@ -1,49 +1,48 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Dirent = void 0;
4
- var constants_1 = require("./constants");
5
- var encoding_1 = require("./encoding");
6
- var S_IFMT = constants_1.constants.S_IFMT, S_IFDIR = constants_1.constants.S_IFDIR, S_IFREG = constants_1.constants.S_IFREG, S_IFBLK = constants_1.constants.S_IFBLK, S_IFCHR = constants_1.constants.S_IFCHR, S_IFLNK = constants_1.constants.S_IFLNK, S_IFIFO = constants_1.constants.S_IFIFO, S_IFSOCK = constants_1.constants.S_IFSOCK;
4
+ const constants_1 = require("./constants");
5
+ const encoding_1 = require("./encoding");
6
+ const { S_IFMT, S_IFDIR, S_IFREG, S_IFBLK, S_IFCHR, S_IFLNK, S_IFIFO, S_IFSOCK } = constants_1.constants;
7
7
  /**
8
8
  * A directory entry, like `fs.Dirent`.
9
9
  */
10
- var Dirent = /** @class */ (function () {
11
- function Dirent() {
10
+ class Dirent {
11
+ constructor() {
12
12
  this.name = '';
13
13
  this.mode = 0;
14
14
  }
15
- Dirent.build = function (link, encoding) {
16
- var dirent = new Dirent();
17
- var mode = link.getNode().mode;
15
+ static build(link, encoding) {
16
+ const dirent = new Dirent();
17
+ const { mode } = link.getNode();
18
18
  dirent.name = (0, encoding_1.strToEncoding)(link.getName(), encoding);
19
19
  dirent.mode = mode;
20
20
  return dirent;
21
- };
22
- Dirent.prototype._checkModeProperty = function (property) {
21
+ }
22
+ _checkModeProperty(property) {
23
23
  return (this.mode & S_IFMT) === property;
24
- };
25
- Dirent.prototype.isDirectory = function () {
24
+ }
25
+ isDirectory() {
26
26
  return this._checkModeProperty(S_IFDIR);
27
- };
28
- Dirent.prototype.isFile = function () {
27
+ }
28
+ isFile() {
29
29
  return this._checkModeProperty(S_IFREG);
30
- };
31
- Dirent.prototype.isBlockDevice = function () {
30
+ }
31
+ isBlockDevice() {
32
32
  return this._checkModeProperty(S_IFBLK);
33
- };
34
- Dirent.prototype.isCharacterDevice = function () {
33
+ }
34
+ isCharacterDevice() {
35
35
  return this._checkModeProperty(S_IFCHR);
36
- };
37
- Dirent.prototype.isSymbolicLink = function () {
36
+ }
37
+ isSymbolicLink() {
38
38
  return this._checkModeProperty(S_IFLNK);
39
- };
40
- Dirent.prototype.isFIFO = function () {
39
+ }
40
+ isFIFO() {
41
41
  return this._checkModeProperty(S_IFIFO);
42
- };
43
- Dirent.prototype.isSocket = function () {
42
+ }
43
+ isSocket() {
44
44
  return this._checkModeProperty(S_IFSOCK);
45
- };
46
- return Dirent;
47
- }());
45
+ }
46
+ }
48
47
  exports.Dirent = Dirent;
49
48
  exports.default = Dirent;
package/lib/Stats.js CHANGED
@@ -1,20 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Stats = void 0;
4
- var constants_1 = require("./constants");
5
- var getBigInt_1 = require("./getBigInt");
6
- var S_IFMT = constants_1.constants.S_IFMT, S_IFDIR = constants_1.constants.S_IFDIR, S_IFREG = constants_1.constants.S_IFREG, S_IFBLK = constants_1.constants.S_IFBLK, S_IFCHR = constants_1.constants.S_IFCHR, S_IFLNK = constants_1.constants.S_IFLNK, S_IFIFO = constants_1.constants.S_IFIFO, S_IFSOCK = constants_1.constants.S_IFSOCK;
4
+ const constants_1 = require("./constants");
5
+ const getBigInt_1 = require("./getBigInt");
6
+ const { S_IFMT, S_IFDIR, S_IFREG, S_IFBLK, S_IFCHR, S_IFLNK, S_IFIFO, S_IFSOCK } = constants_1.constants;
7
7
  /**
8
8
  * Statistics about a file/directory, like `fs.Stats`.
9
9
  */
10
- var Stats = /** @class */ (function () {
11
- function Stats() {
12
- }
13
- Stats.build = function (node, bigint) {
14
- if (bigint === void 0) { bigint = false; }
15
- var stats = new Stats();
16
- var uid = node.uid, gid = node.gid, atime = node.atime, mtime = node.mtime, ctime = node.ctime;
17
- var getStatNumber = !bigint ? function (number) { return number; } : getBigInt_1.default;
10
+ class Stats {
11
+ static build(node, bigint = false) {
12
+ const stats = new Stats();
13
+ const { uid, gid, atime, mtime, ctime } = node;
14
+ const getStatNumber = !bigint ? number => number : getBigInt_1.default;
18
15
  // Copy all values on Stats from Node, so that if Node values
19
16
  // change, values on Stats would still be the old ones,
20
17
  // just like in Node fs.
@@ -31,39 +28,38 @@ var Stats = /** @class */ (function () {
31
28
  stats.birthtime = ctime;
32
29
  stats.atimeMs = getStatNumber(atime.getTime());
33
30
  stats.mtimeMs = getStatNumber(mtime.getTime());
34
- var ctimeMs = getStatNumber(ctime.getTime());
31
+ const ctimeMs = getStatNumber(ctime.getTime());
35
32
  stats.ctimeMs = ctimeMs;
36
33
  stats.birthtimeMs = ctimeMs;
37
34
  stats.dev = getStatNumber(0);
38
35
  stats.mode = getStatNumber(node.mode);
39
36
  stats.nlink = getStatNumber(node.nlink);
40
37
  return stats;
41
- };
42
- Stats.prototype._checkModeProperty = function (property) {
38
+ }
39
+ _checkModeProperty(property) {
43
40
  return (Number(this.mode) & S_IFMT) === property;
44
- };
45
- Stats.prototype.isDirectory = function () {
41
+ }
42
+ isDirectory() {
46
43
  return this._checkModeProperty(S_IFDIR);
47
- };
48
- Stats.prototype.isFile = function () {
44
+ }
45
+ isFile() {
49
46
  return this._checkModeProperty(S_IFREG);
50
- };
51
- Stats.prototype.isBlockDevice = function () {
47
+ }
48
+ isBlockDevice() {
52
49
  return this._checkModeProperty(S_IFBLK);
53
- };
54
- Stats.prototype.isCharacterDevice = function () {
50
+ }
51
+ isCharacterDevice() {
55
52
  return this._checkModeProperty(S_IFCHR);
56
- };
57
- Stats.prototype.isSymbolicLink = function () {
53
+ }
54
+ isSymbolicLink() {
58
55
  return this._checkModeProperty(S_IFLNK);
59
- };
60
- Stats.prototype.isFIFO = function () {
56
+ }
57
+ isFIFO() {
61
58
  return this._checkModeProperty(S_IFIFO);
62
- };
63
- Stats.prototype.isSocket = function () {
59
+ }
60
+ isSocket() {
64
61
  return this._checkModeProperty(S_IFSOCK);
65
- };
66
- return Stats;
67
- }());
62
+ }
63
+ }
68
64
  exports.Stats = Stats;
69
65
  exports.default = Stats;
package/lib/encoding.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.strToEncoding = exports.assertEncoding = exports.ENCODING_UTF8 = void 0;
4
- var buffer_1 = require("./internal/buffer");
5
- var errors = require("./internal/errors");
4
+ const buffer_1 = require("./internal/buffer");
5
+ const errors = require("./internal/errors");
6
6
  exports.ENCODING_UTF8 = 'utf8';
7
7
  function assertEncoding(encoding) {
8
8
  if (encoding && !buffer_1.Buffer.isEncoding(encoding))
package/lib/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import Stats from './Stats';
2
2
  import Dirent from './Dirent';
3
3
  import { Volume as _Volume, StatWatcher, FSWatcher, IReadStream, IWriteStream, DirectoryJSON } from './volume';
4
- import { IPromisesAPI } from './promises';
5
4
  import { constants } from './constants';
5
+ import type { FsPromisesApi } from './node/types';
6
6
  export { DirectoryJSON };
7
7
  export declare const Volume: typeof _Volume;
8
8
  export declare const vol: _Volume;
@@ -14,8 +14,22 @@ export interface IFs extends _Volume {
14
14
  FSWatcher: new () => FSWatcher;
15
15
  ReadStream: new (...args: any[]) => IReadStream;
16
16
  WriteStream: new (...args: any[]) => IWriteStream;
17
- promises: IPromisesAPI;
17
+ promises: FsPromisesApi;
18
18
  _toUnixTimestamp: any;
19
19
  }
20
20
  export declare function createFsFromVolume(vol: _Volume): IFs;
21
21
  export declare const fs: IFs;
22
+ /**
23
+ * Creates a new file system instance.
24
+ *
25
+ * @param json File system structure expressed as a JSON object.
26
+ * Use `null` for empty directories and empty string for empty files.
27
+ * @param cwd Current working directory. The JSON structure will be created
28
+ * relative to this path.
29
+ * @returns A `memfs` file system instance, which is a drop-in replacement for
30
+ * the `fs` module.
31
+ */
32
+ export declare const memfs: (json?: DirectoryJSON, cwd?: string) => IFs;
33
+ export type IFsWithVolume = IFs & {
34
+ __vol: _Volume;
35
+ };
package/lib/index.js CHANGED
@@ -1,48 +1,50 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.fs = exports.createFsFromVolume = exports.vol = exports.Volume = void 0;
15
- var Stats_1 = require("./Stats");
16
- var Dirent_1 = require("./Dirent");
17
- var volume_1 = require("./volume");
18
- var _a = require('fs-monkey/lib/util/lists'), fsSyncMethods = _a.fsSyncMethods, fsAsyncMethods = _a.fsAsyncMethods;
19
- var constants_1 = require("./constants");
20
- var F_OK = constants_1.constants.F_OK, R_OK = constants_1.constants.R_OK, W_OK = constants_1.constants.W_OK, X_OK = constants_1.constants.X_OK;
3
+ exports.memfs = exports.fs = exports.createFsFromVolume = exports.vol = exports.Volume = void 0;
4
+ const Stats_1 = require("./Stats");
5
+ const Dirent_1 = require("./Dirent");
6
+ const volume_1 = require("./volume");
7
+ const { fsSyncMethods, fsAsyncMethods } = require('fs-monkey/lib/util/lists');
8
+ const constants_1 = require("./constants");
9
+ const { F_OK, R_OK, W_OK, X_OK } = constants_1.constants;
21
10
  exports.Volume = volume_1.Volume;
22
11
  // Default volume.
23
12
  exports.vol = new volume_1.Volume();
24
13
  function createFsFromVolume(vol) {
25
- var fs = { F_OK: F_OK, R_OK: R_OK, W_OK: W_OK, X_OK: X_OK, constants: constants_1.constants, Stats: Stats_1.default, Dirent: Dirent_1.default };
14
+ const fs = { F_OK, R_OK, W_OK, X_OK, constants: constants_1.constants, Stats: Stats_1.default, Dirent: Dirent_1.default };
26
15
  // Bind FS methods.
27
- for (var _i = 0, fsSyncMethods_1 = fsSyncMethods; _i < fsSyncMethods_1.length; _i++) {
28
- var method = fsSyncMethods_1[_i];
16
+ for (const method of fsSyncMethods)
29
17
  if (typeof vol[method] === 'function')
30
18
  fs[method] = vol[method].bind(vol);
31
- }
32
- for (var _a = 0, fsAsyncMethods_1 = fsAsyncMethods; _a < fsAsyncMethods_1.length; _a++) {
33
- var method = fsAsyncMethods_1[_a];
19
+ for (const method of fsAsyncMethods)
34
20
  if (typeof vol[method] === 'function')
35
21
  fs[method] = vol[method].bind(vol);
36
- }
37
22
  fs.StatWatcher = vol.StatWatcher;
38
23
  fs.FSWatcher = vol.FSWatcher;
39
24
  fs.WriteStream = vol.WriteStream;
40
25
  fs.ReadStream = vol.ReadStream;
41
26
  fs.promises = vol.promises;
42
27
  fs._toUnixTimestamp = volume_1.toUnixTimestamp;
28
+ fs.__vol = vol;
43
29
  return fs;
44
30
  }
45
31
  exports.createFsFromVolume = createFsFromVolume;
46
32
  exports.fs = createFsFromVolume(exports.vol);
47
- module.exports = __assign(__assign({}, module.exports), exports.fs);
33
+ /**
34
+ * Creates a new file system instance.
35
+ *
36
+ * @param json File system structure expressed as a JSON object.
37
+ * Use `null` for empty directories and empty string for empty files.
38
+ * @param cwd Current working directory. The JSON structure will be created
39
+ * relative to this path.
40
+ * @returns A `memfs` file system instance, which is a drop-in replacement for
41
+ * the `fs` module.
42
+ */
43
+ const memfs = (json = {}, cwd = '/') => {
44
+ const volume = exports.Volume.fromJSON(json, cwd);
45
+ const fs = createFsFromVolume(volume);
46
+ return fs;
47
+ };
48
+ exports.memfs = memfs;
49
+ module.exports = Object.assign(Object.assign({}, module.exports), exports.fs);
48
50
  module.exports.semantic = true;
@@ -1,25 +1,12 @@
1
1
  "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
- if (ar || !(i in from)) {
5
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
- ar[i] = from[i];
7
- }
8
- }
9
- return to.concat(ar || Array.prototype.slice.call(from));
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.bufferFrom = exports.bufferAllocUnsafe = exports.Buffer = void 0;
13
- var buffer_1 = require("buffer");
4
+ const buffer_1 = require("buffer");
14
5
  Object.defineProperty(exports, "Buffer", { enumerable: true, get: function () { return buffer_1.Buffer; } });
15
- function bufferV0P12Ponyfill(arg0) {
16
- var args = [];
17
- for (var _i = 1; _i < arguments.length; _i++) {
18
- args[_i - 1] = arguments[_i];
19
- }
20
- return new (buffer_1.Buffer.bind.apply(buffer_1.Buffer, __spreadArray([void 0, arg0], args, false)))();
6
+ function bufferV0P12Ponyfill(arg0, ...args) {
7
+ return new buffer_1.Buffer(arg0, ...args);
21
8
  }
22
- var bufferAllocUnsafe = buffer_1.Buffer.allocUnsafe || bufferV0P12Ponyfill;
9
+ const bufferAllocUnsafe = buffer_1.Buffer.allocUnsafe || bufferV0P12Ponyfill;
23
10
  exports.bufferAllocUnsafe = bufferAllocUnsafe;
24
- var bufferFrom = buffer_1.Buffer.from || bufferV0P12Ponyfill;
11
+ const bufferFrom = buffer_1.Buffer.from || bufferV0P12Ponyfill;
25
12
  exports.bufferFrom = bufferFrom;
@@ -4,77 +4,51 @@
4
4
  // change. The NodeError classes here all expose a `code` property whose
5
5
  // value statically and permanently identifies the error. While the error
6
6
  // message may change, the code should not.
7
- var __extends = (this && this.__extends) || (function () {
8
- var extendStatics = function (d, b) {
9
- extendStatics = Object.setPrototypeOf ||
10
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
11
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
12
- return extendStatics(d, b);
13
- };
14
- return function (d, b) {
15
- if (typeof b !== "function" && b !== null)
16
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
17
- extendStatics(d, b);
18
- function __() { this.constructor = d; }
19
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
20
- };
21
- })();
22
7
  Object.defineProperty(exports, "__esModule", { value: true });
23
8
  exports.E = exports.AssertionError = exports.message = exports.RangeError = exports.TypeError = exports.Error = void 0;
24
- var assert = require("assert");
25
- var util = require("util");
26
- var kCode = typeof Symbol === 'undefined' ? '_kCode' : Symbol('code');
27
- var messages = {}; // new Map();
9
+ const assert = require("assert");
10
+ const util = require("util");
11
+ const kCode = typeof Symbol === 'undefined' ? '_kCode' : Symbol('code');
12
+ const messages = {}; // new Map();
28
13
  function makeNodeError(Base) {
29
- return /** @class */ (function (_super) {
30
- __extends(NodeError, _super);
31
- function NodeError(key) {
32
- var args = [];
33
- for (var _i = 1; _i < arguments.length; _i++) {
34
- args[_i - 1] = arguments[_i];
35
- }
36
- var _this = _super.call(this, message(key, args)) || this;
37
- _this.code = key;
38
- _this[kCode] = key;
39
- _this.name = "".concat(_super.prototype.name, " [").concat(_this[kCode], "]");
40
- return _this;
14
+ return class NodeError extends Base {
15
+ constructor(key, ...args) {
16
+ super(message(key, args));
17
+ this.code = key;
18
+ this[kCode] = key;
19
+ this.name = `${super.name} [${this[kCode]}]`;
41
20
  }
42
- return NodeError;
43
- }(Base));
21
+ };
44
22
  }
45
- var g = typeof globalThis !== 'undefined' ? globalThis : global;
46
- var AssertionError = /** @class */ (function (_super) {
47
- __extends(AssertionError, _super);
48
- function AssertionError(options) {
49
- var _this = this;
23
+ const g = typeof globalThis !== 'undefined' ? globalThis : global;
24
+ class AssertionError extends g.Error {
25
+ constructor(options) {
50
26
  if (typeof options !== 'object' || options === null) {
51
27
  throw new exports.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object');
52
28
  }
53
29
  if (options.message) {
54
- _this = _super.call(this, options.message) || this;
30
+ super(options.message);
55
31
  }
56
32
  else {
57
- _this = _super.call(this, "".concat(util.inspect(options.actual).slice(0, 128), " ") +
58
- "".concat(options.operator, " ").concat(util.inspect(options.expected).slice(0, 128))) || this;
33
+ super(`${util.inspect(options.actual).slice(0, 128)} ` +
34
+ `${options.operator} ${util.inspect(options.expected).slice(0, 128)}`);
59
35
  }
60
- _this.generatedMessage = !options.message;
61
- _this.name = 'AssertionError [ERR_ASSERTION]';
62
- _this.code = 'ERR_ASSERTION';
63
- _this.actual = options.actual;
64
- _this.expected = options.expected;
65
- _this.operator = options.operator;
66
- exports.Error.captureStackTrace(_this, options.stackStartFunction);
67
- return _this;
36
+ this.generatedMessage = !options.message;
37
+ this.name = 'AssertionError [ERR_ASSERTION]';
38
+ this.code = 'ERR_ASSERTION';
39
+ this.actual = options.actual;
40
+ this.expected = options.expected;
41
+ this.operator = options.operator;
42
+ exports.Error.captureStackTrace(this, options.stackStartFunction);
68
43
  }
69
- return AssertionError;
70
- }(g.Error));
44
+ }
71
45
  exports.AssertionError = AssertionError;
72
46
  function message(key, args) {
73
47
  assert.strictEqual(typeof key, 'string');
74
48
  // const msg = messages.get(key);
75
- var msg = messages[key];
76
- assert(msg, "An invalid error message key was used: ".concat(key, "."));
77
- var fmt;
49
+ const msg = messages[key];
50
+ assert(msg, `An invalid error message key was used: ${key}.`);
51
+ let fmt;
78
52
  if (typeof msg === 'function') {
79
53
  fmt = msg;
80
54
  }
@@ -115,18 +89,18 @@ E('ERR_BUFFER_OUT_OF_BOUNDS', bufferOutOfBounds);
115
89
  E('ERR_CHILD_CLOSED_BEFORE_REPLY', 'Child closed before reply received');
116
90
  E('ERR_CONSOLE_WRITABLE_STREAM', 'Console expects a writable stream instance for %s');
117
91
  E('ERR_CPU_USAGE', 'Unable to obtain cpu usage %s');
118
- E('ERR_DNS_SET_SERVERS_FAILED', function (err, servers) { return "c-ares failed to set servers: \"".concat(err, "\" [").concat(servers, "]"); });
92
+ E('ERR_DNS_SET_SERVERS_FAILED', (err, servers) => `c-ares failed to set servers: "${err}" [${servers}]`);
119
93
  E('ERR_FALSY_VALUE_REJECTION', 'Promise was rejected with falsy value');
120
- E('ERR_ENCODING_NOT_SUPPORTED', function (enc) { return "The \"".concat(enc, "\" encoding is not supported"); });
121
- E('ERR_ENCODING_INVALID_ENCODED_DATA', function (enc) { return "The encoded data was not valid for encoding ".concat(enc); });
94
+ E('ERR_ENCODING_NOT_SUPPORTED', enc => `The "${enc}" encoding is not supported`);
95
+ E('ERR_ENCODING_INVALID_ENCODED_DATA', enc => `The encoded data was not valid for encoding ${enc}`);
122
96
  E('ERR_HTTP_HEADERS_SENT', 'Cannot render headers after they are sent to the client');
123
97
  E('ERR_HTTP_INVALID_STATUS_CODE', 'Invalid status code: %s');
124
98
  E('ERR_HTTP_TRAILER_INVALID', 'Trailers are invalid with this transfer encoding');
125
99
  E('ERR_INDEX_OUT_OF_RANGE', 'Index out of range');
126
100
  E('ERR_INVALID_ARG_TYPE', invalidArgType);
127
- E('ERR_INVALID_ARRAY_LENGTH', function (name, len, actual) {
101
+ E('ERR_INVALID_ARRAY_LENGTH', (name, len, actual) => {
128
102
  assert.strictEqual(typeof actual, 'number');
129
- return "The array \"".concat(name, "\" (length ").concat(actual, ") must be of length ").concat(len, ".");
103
+ return `The array "${name}" (length ${actual}) must be of length ${len}.`;
130
104
  });
131
105
  E('ERR_INVALID_BUFFER_SIZE', 'Buffer size must be a multiple of %s');
132
106
  E('ERR_INVALID_CALLBACK', 'Callback must be a function');
@@ -137,16 +111,16 @@ E('ERR_INVALID_FILE_URL_HOST', 'File URL host must be "localhost" or empty on %s
137
111
  E('ERR_INVALID_FILE_URL_PATH', 'File URL path %s');
138
112
  E('ERR_INVALID_HANDLE_TYPE', 'This handle type cannot be sent');
139
113
  E('ERR_INVALID_IP_ADDRESS', 'Invalid IP address: %s');
140
- E('ERR_INVALID_OPT_VALUE', function (name, value) {
141
- return "The value \"".concat(String(value), "\" is invalid for option \"").concat(name, "\"");
114
+ E('ERR_INVALID_OPT_VALUE', (name, value) => {
115
+ return `The value "${String(value)}" is invalid for option "${name}"`;
142
116
  });
143
- E('ERR_INVALID_OPT_VALUE_ENCODING', function (value) { return "The value \"".concat(String(value), "\" is invalid for option \"encoding\""); });
117
+ E('ERR_INVALID_OPT_VALUE_ENCODING', value => `The value "${String(value)}" is invalid for option "encoding"`);
144
118
  E('ERR_INVALID_REPL_EVAL_CONFIG', 'Cannot specify both "breakEvalOnSigint" and "eval" for REPL');
145
119
  E('ERR_INVALID_SYNC_FORK_INPUT', 'Asynchronous forks do not support Buffer, Uint8Array or string input: %s');
146
120
  E('ERR_INVALID_THIS', 'Value of "this" must be of type %s');
147
121
  E('ERR_INVALID_TUPLE', '%s must be an iterable %s tuple');
148
122
  E('ERR_INVALID_URL', 'Invalid URL: %s');
149
- E('ERR_INVALID_URL_SCHEME', function (expected) { return "The URL must be ".concat(oneOf(expected, 'scheme')); });
123
+ E('ERR_INVALID_URL_SCHEME', expected => `The URL must be ${oneOf(expected, 'scheme')}`);
150
124
  E('ERR_IPC_CHANNEL_CLOSED', 'Channel closed');
151
125
  E('ERR_IPC_DISCONNECTED', 'IPC channel is already disconnected');
152
126
  E('ERR_IPC_ONE_PIPE', 'Child process can have only one IPC pipe');
@@ -168,7 +142,7 @@ E('ERR_STDERR_CLOSE', 'process.stderr cannot be closed');
168
142
  E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed');
169
143
  E('ERR_STREAM_WRAP', 'Stream has StringDecoder set or is in objectMode');
170
144
  E('ERR_TLS_CERT_ALTNAME_INVALID', "Hostname/IP does not match certificate's altnames: %s");
171
- E('ERR_TLS_DH_PARAM_SIZE', function (size) { return "DH parameter size ".concat(size, " is less than 2048"); });
145
+ E('ERR_TLS_DH_PARAM_SIZE', size => `DH parameter size ${size} is less than 2048`);
172
146
  E('ERR_TLS_HANDSHAKE_TIMEOUT', 'TLS handshake timeout');
173
147
  E('ERR_TLS_RENEGOTIATION_FAILED', 'Failed to renegotiate');
174
148
  E('ERR_TLS_REQUIRED_SERVER_NAME', '"servername" is required parameter for Server.addContext');
@@ -183,7 +157,7 @@ E('ERR_V8BREAKITERATOR', 'Full ICU data not installed. ' + 'See https://github.c
183
157
  function invalidArgType(name, expected, actual) {
184
158
  assert(name, 'name is required');
185
159
  // determiner: 'must be' or 'must not be'
186
- var determiner;
160
+ let determiner;
187
161
  if (expected.includes('not ')) {
188
162
  determiner = 'must not be';
189
163
  expected = expected.split('not ')[1];
@@ -191,68 +165,64 @@ function invalidArgType(name, expected, actual) {
191
165
  else {
192
166
  determiner = 'must be';
193
167
  }
194
- var msg;
168
+ let msg;
195
169
  if (Array.isArray(name)) {
196
- var names = name.map(function (val) { return "\"".concat(val, "\""); }).join(', ');
197
- msg = "The ".concat(names, " arguments ").concat(determiner, " ").concat(oneOf(expected, 'type'));
170
+ const names = name.map(val => `"${val}"`).join(', ');
171
+ msg = `The ${names} arguments ${determiner} ${oneOf(expected, 'type')}`;
198
172
  }
199
173
  else if (name.includes(' argument')) {
200
174
  // for the case like 'first argument'
201
- msg = "The ".concat(name, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
175
+ msg = `The ${name} ${determiner} ${oneOf(expected, 'type')}`;
202
176
  }
203
177
  else {
204
- var type = name.includes('.') ? 'property' : 'argument';
205
- msg = "The \"".concat(name, "\" ").concat(type, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
178
+ const type = name.includes('.') ? 'property' : 'argument';
179
+ msg = `The "${name}" ${type} ${determiner} ${oneOf(expected, 'type')}`;
206
180
  }
207
181
  // if actual value received, output it
208
182
  if (arguments.length >= 3) {
209
- msg += ". Received type ".concat(actual !== null ? typeof actual : 'null');
183
+ msg += `. Received type ${actual !== null ? typeof actual : 'null'}`;
210
184
  }
211
185
  return msg;
212
186
  }
213
- function missingArgs() {
214
- var args = [];
215
- for (var _i = 0; _i < arguments.length; _i++) {
216
- args[_i] = arguments[_i];
217
- }
187
+ function missingArgs(...args) {
218
188
  assert(args.length > 0, 'At least one arg needs to be specified');
219
- var msg = 'The ';
220
- var len = args.length;
221
- args = args.map(function (a) { return "\"".concat(a, "\""); });
189
+ let msg = 'The ';
190
+ const len = args.length;
191
+ args = args.map(a => `"${a}"`);
222
192
  switch (len) {
223
193
  case 1:
224
- msg += "".concat(args[0], " argument");
194
+ msg += `${args[0]} argument`;
225
195
  break;
226
196
  case 2:
227
- msg += "".concat(args[0], " and ").concat(args[1], " arguments");
197
+ msg += `${args[0]} and ${args[1]} arguments`;
228
198
  break;
229
199
  default:
230
200
  msg += args.slice(0, len - 1).join(', ');
231
- msg += ", and ".concat(args[len - 1], " arguments");
201
+ msg += `, and ${args[len - 1]} arguments`;
232
202
  break;
233
203
  }
234
- return "".concat(msg, " must be specified");
204
+ return `${msg} must be specified`;
235
205
  }
236
206
  function oneOf(expected, thing) {
237
207
  assert(expected, 'expected is required');
238
208
  assert(typeof thing === 'string', 'thing is required');
239
209
  if (Array.isArray(expected)) {
240
- var len = expected.length;
210
+ const len = expected.length;
241
211
  assert(len > 0, 'At least one expected value needs to be specified');
242
212
  // tslint:disable-next-line
243
- expected = expected.map(function (i) { return String(i); });
213
+ expected = expected.map(i => String(i));
244
214
  if (len > 2) {
245
- return "one of ".concat(thing, " ").concat(expected.slice(0, len - 1).join(', '), ", or ") + expected[len - 1];
215
+ return `one of ${thing} ${expected.slice(0, len - 1).join(', ')}, or ` + expected[len - 1];
246
216
  }
247
217
  else if (len === 2) {
248
- return "one of ".concat(thing, " ").concat(expected[0], " or ").concat(expected[1]);
218
+ return `one of ${thing} ${expected[0]} or ${expected[1]}`;
249
219
  }
250
220
  else {
251
- return "of ".concat(thing, " ").concat(expected[0]);
221
+ return `of ${thing} ${expected[0]}`;
252
222
  }
253
223
  }
254
224
  else {
255
- return "of ".concat(thing, " ").concat(String(expected));
225
+ return `of ${thing} ${String(expected)}`;
256
226
  }
257
227
  }
258
228
  function bufferOutOfBounds(name, isWriting) {
@@ -260,6 +230,6 @@ function bufferOutOfBounds(name, isWriting) {
260
230
  return 'Attempt to write outside buffer bounds';
261
231
  }
262
232
  else {
263
- return "\"".concat(name, "\" is outside of buffer bounds");
233
+ return `"${name}" is outside of buffer bounds`;
264
234
  }
265
235
  }
@@ -0,0 +1,30 @@
1
+ /// <reference types="node" />
2
+ import type * as opts from './types/options';
3
+ import type { IFileHandle, IStats, TData, TDataOut, TMode, TTime } from './types/misc';
4
+ import type { FsCallbackApi } from './types';
5
+ export declare class FileHandle implements IFileHandle {
6
+ private fs;
7
+ fd: number;
8
+ constructor(fs: FsCallbackApi, fd: number);
9
+ appendFile(data: TData, options?: opts.IAppendFileOptions | string): Promise<void>;
10
+ chmod(mode: TMode): Promise<void>;
11
+ chown(uid: number, gid: number): Promise<void>;
12
+ close(): Promise<void>;
13
+ datasync(): Promise<void>;
14
+ read(buffer: Buffer | Uint8Array, offset: number, length: number, position: number): Promise<TFileHandleReadResult>;
15
+ readFile(options?: opts.IReadFileOptions | string): Promise<TDataOut>;
16
+ stat(options?: opts.IFStatOptions): Promise<IStats>;
17
+ sync(): Promise<void>;
18
+ truncate(len?: number): Promise<void>;
19
+ utimes(atime: TTime, mtime: TTime): Promise<void>;
20
+ write(buffer: Buffer | Uint8Array, offset?: number, length?: number, position?: number): Promise<TFileHandleWriteResult>;
21
+ writeFile(data: TData, options?: opts.IWriteFileOptions): Promise<void>;
22
+ }
23
+ export interface TFileHandleReadResult {
24
+ bytesRead: number;
25
+ buffer: Buffer | Uint8Array;
26
+ }
27
+ export interface TFileHandleWriteResult {
28
+ bytesWritten: number;
29
+ buffer: Buffer | Uint8Array;
30
+ }