memfs 3.1.3 → 3.2.3
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/CHANGELOG.md +36 -0
- package/README.md +3 -1
- package/lib/Dirent.js +1 -1
- package/lib/internal/buffer.d.ts +1 -1
- package/lib/internal/buffer.js +9 -7
- package/lib/internal/errors.d.ts +1 -1
- package/lib/internal/errors.js +7 -5
- package/lib/node.js +13 -11
- package/lib/promises.js +10 -8
- package/lib/setImmediate.js +2 -2
- package/lib/setTimeoutUnref.js +1 -1
- package/lib/volume-localstorage.js +3 -1
- package/lib/volume.d.ts +10 -1
- package/lib/volume.js +69 -45
- package/package.json +19 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
+
## [3.2.3](https://github.com/streamich/memfs/compare/v3.2.2...v3.2.3) (2021-08-31)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* global and timers this arg in browser ([1e93ab1](https://github.com/streamich/memfs/commit/1e93ab1628e230762471737a1d2586b5bc86b496))
|
|
7
|
+
* prevent callback from triggering twice when callback throws ([07e8215](https://github.com/streamich/memfs/commit/07e8215b4a862ae2e0f1cd7f7cfe4b1465bfc2e6))
|
|
8
|
+
* prevent callback from triggering twice when callback throws ([6db755d](https://github.com/streamich/memfs/commit/6db755dabc32d81eceeb3152413bb70298a5c710)), closes [#542](https://github.com/streamich/memfs/issues/542)
|
|
9
|
+
|
|
10
|
+
## [3.2.2](https://github.com/streamich/memfs/compare/v3.2.1...v3.2.2) (2021-04-05)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **deps:** update dependency fs-monkey to v1.0.2 ([07f05db](https://github.com/streamich/memfs/commit/07f05db8b0aed43360abaf172d4297f3873d44fe))
|
|
16
|
+
* **deps:** update dependency fs-monkey to v1.0.3 ([84346ed](https://github.com/streamich/memfs/commit/84346ed7d0556b2b79f57b9b10889e54afcaebd1))
|
|
17
|
+
|
|
18
|
+
## [3.2.1](https://github.com/streamich/memfs/compare/v3.2.0...v3.2.1) (2021-03-31)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* add `The Unlicense` license SDPX in package.json ([#594](https://github.com/streamich/memfs/issues/594)) ([0e7b04b](https://github.com/streamich/memfs/commit/0e7b04b0d5172846340e95619edaa18579ed5d06))
|
|
24
|
+
|
|
25
|
+
# [3.2.0](https://github.com/streamich/memfs/compare/v3.1.3...v3.2.0) (2020-05-19)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* 'fromJSON()' did not consider cwd when creating directories ([3d6ee3b](https://github.com/streamich/memfs/commit/3d6ee3b2c0eef0345ba2bd400e9836f2d685321f))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Features
|
|
34
|
+
|
|
35
|
+
* support nested objects in 'fromJSON()' ([f8c329c](https://github.com/streamich/memfs/commit/f8c329c8e57c85cc4a394a74802af1f37dcedefd))
|
|
36
|
+
|
|
1
37
|
## [3.1.3](https://github.com/streamich/memfs/compare/v3.1.2...v3.1.3) (2020-05-14)
|
|
2
38
|
|
|
3
39
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# memfs
|
|
2
2
|
|
|
3
|
-
[![][npm-badge]][npm-url] [![][travis-badge]][travis-url]
|
|
3
|
+
[![][chat-badge]][chat] [![][npm-badge]][npm-url] [![][travis-badge]][travis-url]
|
|
4
4
|
|
|
5
5
|
In-memory file-system with [Node's `fs` API](https://nodejs.org/api/fs.html).
|
|
6
6
|
|
|
@@ -107,6 +107,8 @@ require('/index'); // hi world
|
|
|
107
107
|
- [`fs-monkey`][fs-monkey] - monkey-patches Node's `fs` module and `require` function
|
|
108
108
|
- [`libfs`](https://github.com/streamich/full-js/blob/master/src/lib/fs.ts) - real filesystem (that executes UNIX system calls) implemented in JavaScript
|
|
109
109
|
|
|
110
|
+
[chat]: https://onp4.com/@vadim/~memfs
|
|
111
|
+
[chat-badge]: https://img.shields.io/badge/Chat-%F0%9F%92%AC-green?style=flat&logo=chat&link=https://onp4.com/@vadim/~memfs
|
|
110
112
|
[npm-url]: https://www.npmjs.com/package/memfs
|
|
111
113
|
[npm-badge]: https://img.shields.io/npm/v/memfs.svg
|
|
112
114
|
[travis-url]: https://travis-ci.org/streamich/memfs
|
package/lib/Dirent.js
CHANGED
|
@@ -15,7 +15,7 @@ var Dirent = /** @class */ (function () {
|
|
|
15
15
|
Dirent.build = function (link, encoding) {
|
|
16
16
|
var dirent = new Dirent();
|
|
17
17
|
var mode = link.getNode().mode;
|
|
18
|
-
dirent.name = encoding_1.strToEncoding(link.getName(), encoding);
|
|
18
|
+
dirent.name = (0, encoding_1.strToEncoding)(link.getName(), encoding);
|
|
19
19
|
dirent.mode = mode;
|
|
20
20
|
return dirent;
|
|
21
21
|
};
|
package/lib/internal/buffer.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Buffer } from 'buffer';
|
|
|
3
3
|
declare const bufferAllocUnsafe: (size: number) => Buffer;
|
|
4
4
|
declare const bufferFrom: {
|
|
5
5
|
(arrayBuffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number | undefined, length?: number | undefined): Buffer;
|
|
6
|
-
(data: any[]): Buffer;
|
|
6
|
+
(data: readonly any[]): Buffer;
|
|
7
7
|
(data: Uint8Array): Buffer;
|
|
8
8
|
(obj: {
|
|
9
9
|
valueOf(): string | object;
|
package/lib/internal/buffer.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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));
|
|
8
10
|
};
|
|
9
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
12
|
exports.bufferFrom = exports.bufferAllocUnsafe = exports.Buffer = void 0;
|
|
@@ -15,7 +17,7 @@ function bufferV0P12Ponyfill(arg0) {
|
|
|
15
17
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
16
18
|
args[_i - 1] = arguments[_i];
|
|
17
19
|
}
|
|
18
|
-
return new (buffer_1.Buffer.bind.apply(buffer_1.Buffer,
|
|
20
|
+
return new (buffer_1.Buffer.bind.apply(buffer_1.Buffer, __spreadArray([void 0, arg0], args, false)))();
|
|
19
21
|
}
|
|
20
22
|
var bufferAllocUnsafe = buffer_1.Buffer.allocUnsafe || bufferV0P12Ponyfill;
|
|
21
23
|
exports.bufferAllocUnsafe = bufferAllocUnsafe;
|
package/lib/internal/errors.d.ts
CHANGED
package/lib/internal/errors.js
CHANGED
|
@@ -8,10 +8,12 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
8
8
|
var extendStatics = function (d, b) {
|
|
9
9
|
extendStatics = Object.setPrototypeOf ||
|
|
10
10
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
11
|
-
function (d, b) { for (var p in b) if (
|
|
11
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
12
12
|
return extendStatics(d, b);
|
|
13
13
|
};
|
|
14
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");
|
|
15
17
|
extendStatics(d, b);
|
|
16
18
|
function __() { this.constructor = d; }
|
|
17
19
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
@@ -64,7 +66,7 @@ var AssertionError = /** @class */ (function (_super) {
|
|
|
64
66
|
return _this;
|
|
65
67
|
}
|
|
66
68
|
return AssertionError;
|
|
67
|
-
}(
|
|
69
|
+
}(globalThis.Error));
|
|
68
70
|
exports.AssertionError = AssertionError;
|
|
69
71
|
function message(key, args) {
|
|
70
72
|
assert.strictEqual(typeof key, 'string');
|
|
@@ -90,9 +92,9 @@ function E(sym, val) {
|
|
|
90
92
|
messages[sym] = typeof val === 'function' ? val : String(val);
|
|
91
93
|
}
|
|
92
94
|
exports.E = E;
|
|
93
|
-
exports.Error = makeNodeError(
|
|
94
|
-
exports.TypeError = makeNodeError(
|
|
95
|
-
exports.RangeError = makeNodeError(
|
|
95
|
+
exports.Error = makeNodeError(globalThis.Error);
|
|
96
|
+
exports.TypeError = makeNodeError(globalThis.TypeError);
|
|
97
|
+
exports.RangeError = makeNodeError(globalThis.RangeError);
|
|
96
98
|
// To declare an error message, use the E(sym, val) function above. The sym
|
|
97
99
|
// must be an upper case string. The val can be either a function or a string.
|
|
98
100
|
// The return value of the function must be a string.
|
package/lib/node.js
CHANGED
|
@@ -3,10 +3,12 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
3
3
|
var extendStatics = function (d, b) {
|
|
4
4
|
extendStatics = Object.setPrototypeOf ||
|
|
5
5
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
7
|
return extendStatics(d, b);
|
|
8
8
|
};
|
|
9
9
|
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
10
12
|
extendStatics(d, b);
|
|
11
13
|
function __() { this.constructor = d; }
|
|
12
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
@@ -50,16 +52,16 @@ var Node = /** @class */ (function (_super) {
|
|
|
50
52
|
};
|
|
51
53
|
Node.prototype.setString = function (str) {
|
|
52
54
|
// this.setBuffer(bufferFrom(str, 'utf8'));
|
|
53
|
-
this.buf = buffer_1.bufferFrom(str, 'utf8');
|
|
55
|
+
this.buf = (0, buffer_1.bufferFrom)(str, 'utf8');
|
|
54
56
|
this.touch();
|
|
55
57
|
};
|
|
56
58
|
Node.prototype.getBuffer = function () {
|
|
57
59
|
if (!this.buf)
|
|
58
|
-
this.setBuffer(buffer_1.bufferAllocUnsafe(0));
|
|
59
|
-
return buffer_1.bufferFrom(this.buf); // Return a copy.
|
|
60
|
+
this.setBuffer((0, buffer_1.bufferAllocUnsafe)(0));
|
|
61
|
+
return (0, buffer_1.bufferFrom)(this.buf); // Return a copy.
|
|
60
62
|
};
|
|
61
63
|
Node.prototype.setBuffer = function (buf) {
|
|
62
|
-
this.buf = buffer_1.bufferFrom(buf); // Creates a copy of data.
|
|
64
|
+
this.buf = (0, buffer_1.bufferFrom)(buf); // Creates a copy of data.
|
|
63
65
|
this.touch();
|
|
64
66
|
};
|
|
65
67
|
Node.prototype.getSize = function () {
|
|
@@ -96,9 +98,9 @@ var Node = /** @class */ (function (_super) {
|
|
|
96
98
|
if (len === void 0) { len = buf.length; }
|
|
97
99
|
if (pos === void 0) { pos = 0; }
|
|
98
100
|
if (!this.buf)
|
|
99
|
-
this.buf = buffer_1.bufferAllocUnsafe(0);
|
|
101
|
+
this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
|
|
100
102
|
if (pos + len > this.buf.length) {
|
|
101
|
-
var newBuf = buffer_1.bufferAllocUnsafe(pos + len);
|
|
103
|
+
var newBuf = (0, buffer_1.bufferAllocUnsafe)(pos + len);
|
|
102
104
|
this.buf.copy(newBuf, 0, 0, this.buf.length);
|
|
103
105
|
this.buf = newBuf;
|
|
104
106
|
}
|
|
@@ -112,7 +114,7 @@ var Node = /** @class */ (function (_super) {
|
|
|
112
114
|
if (len === void 0) { len = buf.byteLength; }
|
|
113
115
|
if (pos === void 0) { pos = 0; }
|
|
114
116
|
if (!this.buf)
|
|
115
|
-
this.buf = buffer_1.bufferAllocUnsafe(0);
|
|
117
|
+
this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
|
|
116
118
|
var actualLen = len;
|
|
117
119
|
if (actualLen > buf.byteLength) {
|
|
118
120
|
actualLen = buf.byteLength;
|
|
@@ -126,15 +128,15 @@ var Node = /** @class */ (function (_super) {
|
|
|
126
128
|
Node.prototype.truncate = function (len) {
|
|
127
129
|
if (len === void 0) { len = 0; }
|
|
128
130
|
if (!len)
|
|
129
|
-
this.buf = buffer_1.bufferAllocUnsafe(0);
|
|
131
|
+
this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
|
|
130
132
|
else {
|
|
131
133
|
if (!this.buf)
|
|
132
|
-
this.buf = buffer_1.bufferAllocUnsafe(0);
|
|
134
|
+
this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
|
|
133
135
|
if (len <= this.buf.length) {
|
|
134
136
|
this.buf = this.buf.slice(0, len);
|
|
135
137
|
}
|
|
136
138
|
else {
|
|
137
|
-
var buf = buffer_1.bufferAllocUnsafe(0);
|
|
139
|
+
var buf = (0, buffer_1.bufferAllocUnsafe)(0);
|
|
138
140
|
this.buf.copy(buf);
|
|
139
141
|
buf.fill(0, len);
|
|
140
142
|
}
|
package/lib/promises.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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));
|
|
8
10
|
};
|
|
9
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
12
|
exports.FileHandle = void 0;
|
|
@@ -16,11 +18,11 @@ function promisify(vol, fn, getResult) {
|
|
|
16
18
|
args[_i] = arguments[_i];
|
|
17
19
|
}
|
|
18
20
|
return new Promise(function (resolve, reject) {
|
|
19
|
-
vol[fn].bind(vol).apply(void 0,
|
|
21
|
+
vol[fn].bind(vol).apply(void 0, __spreadArray(__spreadArray([], args, false), [function (error, result) {
|
|
20
22
|
if (error)
|
|
21
23
|
return reject(error);
|
|
22
24
|
return resolve(getResult(result));
|
|
23
|
-
}]));
|
|
25
|
+
}], false));
|
|
24
26
|
});
|
|
25
27
|
};
|
|
26
28
|
}
|
package/lib/setImmediate.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var _setImmediate;
|
|
4
4
|
if (typeof setImmediate === 'function')
|
|
5
|
-
_setImmediate = setImmediate.bind(
|
|
5
|
+
_setImmediate = setImmediate.bind(globalThis);
|
|
6
6
|
else
|
|
7
|
-
_setImmediate = setTimeout.bind(
|
|
7
|
+
_setImmediate = setTimeout.bind(globalThis);
|
|
8
8
|
exports.default = _setImmediate;
|
package/lib/setTimeoutUnref.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
* only in Node's environment it will "unref" its macro task.
|
|
6
6
|
*/
|
|
7
7
|
function setTimeoutUnref(callback, time, args) {
|
|
8
|
-
var ref = setTimeout.apply(
|
|
8
|
+
var ref = setTimeout.apply(globalThis, arguments);
|
|
9
9
|
if (ref && typeof ref === 'object' && typeof ref.unref === 'function')
|
|
10
10
|
ref.unref();
|
|
11
11
|
return ref;
|
|
@@ -3,10 +3,12 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
3
3
|
var extendStatics = function (d, b) {
|
|
4
4
|
extendStatics = Object.setPrototypeOf ||
|
|
5
5
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
7
|
return extendStatics(d, b);
|
|
8
8
|
};
|
|
9
9
|
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
10
12
|
extendStatics(d, b);
|
|
11
13
|
function __() { this.constructor = d; }
|
|
12
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
package/lib/volume.d.ts
CHANGED
|
@@ -101,12 +101,19 @@ export declare function dataToStr(data: TData, encoding?: string): string;
|
|
|
101
101
|
export declare function dataToBuffer(data: TData, encoding?: string): Buffer;
|
|
102
102
|
export declare function bufferToEncoding(buffer: Buffer, encoding?: TEncodingExtended): TDataOut;
|
|
103
103
|
export declare function toUnixTimestamp(time: any): any;
|
|
104
|
-
|
|
104
|
+
declare type DirectoryContent = string | null;
|
|
105
|
+
export interface DirectoryJSON {
|
|
106
|
+
[key: string]: DirectoryContent;
|
|
107
|
+
}
|
|
108
|
+
export interface NestedDirectoryJSON {
|
|
109
|
+
[key: string]: DirectoryContent | NestedDirectoryJSON;
|
|
110
|
+
}
|
|
105
111
|
/**
|
|
106
112
|
* `Volume` represents a file system.
|
|
107
113
|
*/
|
|
108
114
|
export declare class Volume {
|
|
109
115
|
static fromJSON(json: DirectoryJSON, cwd?: string): Volume;
|
|
116
|
+
static fromNestedJSON(json: NestedDirectoryJSON, cwd?: string): Volume;
|
|
110
117
|
/**
|
|
111
118
|
* Global file descriptor counter. UNIX file descriptors start from 0 and go sequentially
|
|
112
119
|
* up, so here, in order not to conflict with them, we choose some big number and descrease
|
|
@@ -163,6 +170,7 @@ export declare class Volume {
|
|
|
163
170
|
private _toJSON;
|
|
164
171
|
toJSON(paths?: PathLike | PathLike[], json?: {}, isRelative?: boolean): DirectoryJSON;
|
|
165
172
|
fromJSON(json: DirectoryJSON, cwd?: string): void;
|
|
173
|
+
fromNestedJSON(json: NestedDirectoryJSON, cwd?: string): void;
|
|
166
174
|
reset(): void;
|
|
167
175
|
mountSync(mountpoint: string, json: DirectoryJSON): void;
|
|
168
176
|
private openLink;
|
|
@@ -378,3 +386,4 @@ export declare class FSWatcher extends EventEmitter {
|
|
|
378
386
|
start(path: PathLike, persistent?: boolean, recursive?: boolean, encoding?: BufferEncoding): void;
|
|
379
387
|
close(): void;
|
|
380
388
|
}
|
|
389
|
+
export {};
|
package/lib/volume.js
CHANGED
|
@@ -3,21 +3,25 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
3
3
|
var extendStatics = function (d, b) {
|
|
4
4
|
extendStatics = Object.setPrototypeOf ||
|
|
5
5
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
7
|
return extendStatics(d, b);
|
|
8
8
|
};
|
|
9
9
|
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
10
12
|
extendStatics(d, b);
|
|
11
13
|
function __() { this.constructor = d; }
|
|
12
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
15
|
};
|
|
14
16
|
})();
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
18
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
19
|
+
if (ar || !(i in from)) {
|
|
20
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
21
|
+
ar[i] = from[i];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
25
|
};
|
|
22
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
27
|
exports.FSWatcher = exports.StatWatcher = exports.Volume = exports.toUnixTimestamp = exports.bufferToEncoding = exports.dataToBuffer = exports.dataToStr = exports.pathToSteps = exports.filenameToSteps = exports.pathToFilename = exports.flagsToNumber = exports.FLAGS = void 0;
|
|
@@ -38,17 +42,7 @@ var util = require("util");
|
|
|
38
42
|
var promises_1 = require("./promises");
|
|
39
43
|
var resolveCrossPlatform = pathModule.resolve;
|
|
40
44
|
var O_RDONLY = constants_1.constants.O_RDONLY, O_WRONLY = constants_1.constants.O_WRONLY, O_RDWR = constants_1.constants.O_RDWR, O_CREAT = constants_1.constants.O_CREAT, O_EXCL = constants_1.constants.O_EXCL, O_TRUNC = constants_1.constants.O_TRUNC, O_APPEND = constants_1.constants.O_APPEND, O_SYNC = constants_1.constants.O_SYNC, O_DIRECTORY = constants_1.constants.O_DIRECTORY, F_OK = constants_1.constants.F_OK, COPYFILE_EXCL = constants_1.constants.COPYFILE_EXCL, COPYFILE_FICLONE_FORCE = constants_1.constants.COPYFILE_FICLONE_FORCE;
|
|
41
|
-
var sep;
|
|
42
|
-
var relative;
|
|
43
|
-
if (pathModule.posix) {
|
|
44
|
-
var posix = pathModule.posix;
|
|
45
|
-
sep = posix.sep;
|
|
46
|
-
relative = posix.relative;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
sep = pathModule.sep;
|
|
50
|
-
relative = pathModule.relative;
|
|
51
|
-
}
|
|
45
|
+
var _a = pathModule.posix ? pathModule.posix : pathModule, sep = _a.sep, relative = _a.relative, join = _a.join, dirname = _a.dirname;
|
|
52
46
|
var isWin = process_1.default.platform === 'win32';
|
|
53
47
|
var kMinPoolSpace = 128;
|
|
54
48
|
// const kMaxLength = require('buffer').kMaxLength;
|
|
@@ -198,7 +192,7 @@ function getOptions(defaults, options) {
|
|
|
198
192
|
}
|
|
199
193
|
}
|
|
200
194
|
if (opts.encoding !== 'buffer')
|
|
201
|
-
encoding_1.assertEncoding(opts.encoding);
|
|
195
|
+
(0, encoding_1.assertEncoding)(opts.encoding);
|
|
202
196
|
return opts;
|
|
203
197
|
}
|
|
204
198
|
function optsGenerator(defaults) {
|
|
@@ -329,7 +323,7 @@ function dataToStr(data, encoding) {
|
|
|
329
323
|
if (buffer_1.Buffer.isBuffer(data))
|
|
330
324
|
return data.toString(encoding);
|
|
331
325
|
else if (data instanceof Uint8Array)
|
|
332
|
-
return buffer_1.bufferFrom(data).toString(encoding);
|
|
326
|
+
return (0, buffer_1.bufferFrom)(data).toString(encoding);
|
|
333
327
|
else
|
|
334
328
|
return String(data);
|
|
335
329
|
}
|
|
@@ -339,9 +333,9 @@ function dataToBuffer(data, encoding) {
|
|
|
339
333
|
if (buffer_1.Buffer.isBuffer(data))
|
|
340
334
|
return data;
|
|
341
335
|
else if (data instanceof Uint8Array)
|
|
342
|
-
return buffer_1.bufferFrom(data);
|
|
336
|
+
return (0, buffer_1.bufferFrom)(data);
|
|
343
337
|
else
|
|
344
|
-
return buffer_1.bufferFrom(String(data), encoding);
|
|
338
|
+
return (0, buffer_1.bufferFrom)(String(data), encoding);
|
|
345
339
|
}
|
|
346
340
|
exports.dataToBuffer = dataToBuffer;
|
|
347
341
|
function bufferToEncoding(buffer, encoding) {
|
|
@@ -410,6 +404,29 @@ function validateGid(gid) {
|
|
|
410
404
|
if (typeof gid !== 'number')
|
|
411
405
|
throw TypeError(ERRSTR.GID);
|
|
412
406
|
}
|
|
407
|
+
function flattenJSON(nestedJSON) {
|
|
408
|
+
var flatJSON = {};
|
|
409
|
+
function flatten(pathPrefix, node) {
|
|
410
|
+
for (var path in node) {
|
|
411
|
+
var contentOrNode = node[path];
|
|
412
|
+
var joinedPath = join(pathPrefix, path);
|
|
413
|
+
if (typeof contentOrNode === 'string') {
|
|
414
|
+
flatJSON[joinedPath] = contentOrNode;
|
|
415
|
+
}
|
|
416
|
+
else if (typeof contentOrNode === 'object' && contentOrNode !== null && Object.keys(contentOrNode).length > 0) {
|
|
417
|
+
// empty directories need an explicit entry and therefore get handled in `else`, non-empty ones are implicitly considered
|
|
418
|
+
flatten(joinedPath, contentOrNode);
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
// without this branch null, empty-object or non-object entries would not be handled in the same way
|
|
422
|
+
// by both fromJSON() and fromNestedJSON()
|
|
423
|
+
flatJSON[joinedPath] = null;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
flatten('', nestedJSON);
|
|
428
|
+
return flatJSON;
|
|
429
|
+
}
|
|
413
430
|
/**
|
|
414
431
|
* `Volume` represents a file system.
|
|
415
432
|
*/
|
|
@@ -431,7 +448,7 @@ var Volume = /** @class */ (function () {
|
|
|
431
448
|
this.maxFiles = 10000;
|
|
432
449
|
// Current number of open files.
|
|
433
450
|
this.openFiles = 0;
|
|
434
|
-
this.promisesApi = promises_1.default(this);
|
|
451
|
+
this.promisesApi = (0, promises_1.default)(this);
|
|
435
452
|
this.statWatchers = {};
|
|
436
453
|
this.props = Object.assign({ Node: node_1.Node, Link: node_1.Link, File: node_1.File }, props);
|
|
437
454
|
var root = this.createLink();
|
|
@@ -452,7 +469,7 @@ var Volume = /** @class */ (function () {
|
|
|
452
469
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
453
470
|
args[_i] = arguments[_i];
|
|
454
471
|
}
|
|
455
|
-
return _super.apply(this,
|
|
472
|
+
return _super.apply(this, __spreadArray([self], args, false)) || this;
|
|
456
473
|
}
|
|
457
474
|
return class_1;
|
|
458
475
|
}(_ReadStream));
|
|
@@ -464,7 +481,7 @@ var Volume = /** @class */ (function () {
|
|
|
464
481
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
465
482
|
args[_i] = arguments[_i];
|
|
466
483
|
}
|
|
467
|
-
return _super.apply(this,
|
|
484
|
+
return _super.apply(this, __spreadArray([self], args, false)) || this;
|
|
468
485
|
}
|
|
469
486
|
return class_2;
|
|
470
487
|
}(_WriteStream));
|
|
@@ -486,6 +503,11 @@ var Volume = /** @class */ (function () {
|
|
|
486
503
|
vol.fromJSON(json, cwd);
|
|
487
504
|
return vol;
|
|
488
505
|
};
|
|
506
|
+
Volume.fromNestedJSON = function (json, cwd) {
|
|
507
|
+
var vol = new Volume();
|
|
508
|
+
vol.fromNestedJSON(json, cwd);
|
|
509
|
+
return vol;
|
|
510
|
+
};
|
|
489
511
|
Object.defineProperty(Volume.prototype, "promises", {
|
|
490
512
|
get: function () {
|
|
491
513
|
if (this.promisesApi === null)
|
|
@@ -658,13 +680,16 @@ var Volume = /** @class */ (function () {
|
|
|
658
680
|
Volume.prototype.wrapAsync = function (method, args, callback) {
|
|
659
681
|
var _this = this;
|
|
660
682
|
validateCallback(callback);
|
|
661
|
-
setImmediate_1.default(function () {
|
|
683
|
+
(0, setImmediate_1.default)(function () {
|
|
684
|
+
var result;
|
|
662
685
|
try {
|
|
663
|
-
|
|
686
|
+
result = method.apply(_this, args);
|
|
664
687
|
}
|
|
665
688
|
catch (err) {
|
|
666
689
|
callback(err);
|
|
690
|
+
return;
|
|
667
691
|
}
|
|
692
|
+
callback(null, result);
|
|
668
693
|
});
|
|
669
694
|
};
|
|
670
695
|
Volume.prototype._toJSON = function (link, json, path) {
|
|
@@ -729,18 +754,14 @@ var Volume = /** @class */ (function () {
|
|
|
729
754
|
}
|
|
730
755
|
return json;
|
|
731
756
|
};
|
|
732
|
-
// fromJSON(json: {[filename: string]: string}, cwd: string = '/') {
|
|
733
757
|
Volume.prototype.fromJSON = function (json, cwd) {
|
|
734
758
|
if (cwd === void 0) { cwd = process_1.default.cwd(); }
|
|
735
759
|
for (var filename in json) {
|
|
736
760
|
var data = json[filename];
|
|
761
|
+
filename = resolve(filename, cwd);
|
|
737
762
|
if (typeof data === 'string') {
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
if (steps.length > 1) {
|
|
741
|
-
var dirname = sep + steps.slice(0, steps.length - 1).join(sep);
|
|
742
|
-
this.mkdirpBase(dirname, 511 /* DIR */);
|
|
743
|
-
}
|
|
763
|
+
var dir = dirname(filename);
|
|
764
|
+
this.mkdirpBase(dir, 511 /* DIR */);
|
|
744
765
|
this.writeFileSync(filename, data);
|
|
745
766
|
}
|
|
746
767
|
else {
|
|
@@ -748,6 +769,9 @@ var Volume = /** @class */ (function () {
|
|
|
748
769
|
}
|
|
749
770
|
}
|
|
750
771
|
};
|
|
772
|
+
Volume.prototype.fromNestedJSON = function (json, cwd) {
|
|
773
|
+
this.fromJSON(flattenJSON(json), cwd);
|
|
774
|
+
};
|
|
751
775
|
Volume.prototype.reset = function () {
|
|
752
776
|
this.ino = 0;
|
|
753
777
|
this.inodes = {};
|
|
@@ -891,7 +915,7 @@ var Volume = /** @class */ (function () {
|
|
|
891
915
|
callback(null, 0, buffer);
|
|
892
916
|
});
|
|
893
917
|
}
|
|
894
|
-
setImmediate_1.default(function () {
|
|
918
|
+
(0, setImmediate_1.default)(function () {
|
|
895
919
|
try {
|
|
896
920
|
var bytes = _this.readBase(fd, buffer, offset, length, position);
|
|
897
921
|
callback(null, bytes, buffer);
|
|
@@ -1027,7 +1051,7 @@ var Volume = /** @class */ (function () {
|
|
|
1027
1051
|
length = buf.length;
|
|
1028
1052
|
}
|
|
1029
1053
|
var cb = validateCallback(callback);
|
|
1030
|
-
setImmediate_1.default(function () {
|
|
1054
|
+
(0, setImmediate_1.default)(function () {
|
|
1031
1055
|
try {
|
|
1032
1056
|
var bytes = _this.writeBase(fd, buf, offset, length, position);
|
|
1033
1057
|
if (tipa !== 'string') {
|
|
@@ -1209,7 +1233,7 @@ var Volume = /** @class */ (function () {
|
|
|
1209
1233
|
var realLink = this.getResolvedLink(steps);
|
|
1210
1234
|
if (!realLink)
|
|
1211
1235
|
throw createError(ENOENT, 'realpath', filename);
|
|
1212
|
-
return encoding_1.strToEncoding(realLink.getPath(), encoding);
|
|
1236
|
+
return (0, encoding_1.strToEncoding)(realLink.getPath(), encoding);
|
|
1213
1237
|
};
|
|
1214
1238
|
Volume.prototype.realpathSync = function (path, options) {
|
|
1215
1239
|
return this.realpathBase(pathToFilename(path), getRealpathOptions(options).encoding);
|
|
@@ -1280,7 +1304,7 @@ var Volume = /** @class */ (function () {
|
|
|
1280
1304
|
}
|
|
1281
1305
|
// Rename should overwrite the new path, if that exists.
|
|
1282
1306
|
var name = newPathSteps[newPathSteps.length - 1];
|
|
1283
|
-
link.steps =
|
|
1307
|
+
link.steps = __spreadArray(__spreadArray([], newPathDirLink.steps, true), [name], false);
|
|
1284
1308
|
newPathDirLink.setChild(link.getName(), link);
|
|
1285
1309
|
};
|
|
1286
1310
|
Volume.prototype.renameSync = function (oldPath, newPath) {
|
|
@@ -1309,7 +1333,7 @@ var Volume = /** @class */ (function () {
|
|
|
1309
1333
|
var filename = pathToFilename(path);
|
|
1310
1334
|
if (typeof callback !== 'function')
|
|
1311
1335
|
throw Error(ERRSTR.CB);
|
|
1312
|
-
setImmediate_1.default(function () {
|
|
1336
|
+
(0, setImmediate_1.default)(function () {
|
|
1313
1337
|
try {
|
|
1314
1338
|
callback(_this.existsBase(filename));
|
|
1315
1339
|
}
|
|
@@ -1385,7 +1409,7 @@ var Volume = /** @class */ (function () {
|
|
|
1385
1409
|
}
|
|
1386
1410
|
var list = [];
|
|
1387
1411
|
for (var name_4 in link.children) {
|
|
1388
|
-
list.push(encoding_1.strToEncoding(name_4, options.encoding));
|
|
1412
|
+
list.push((0, encoding_1.strToEncoding)(name_4, options.encoding));
|
|
1389
1413
|
}
|
|
1390
1414
|
if (!isWin && options.encoding !== 'buffer')
|
|
1391
1415
|
list.sort();
|
|
@@ -1407,7 +1431,7 @@ var Volume = /** @class */ (function () {
|
|
|
1407
1431
|
if (!node.isSymlink())
|
|
1408
1432
|
throw createError(EINVAL, 'readlink', filename);
|
|
1409
1433
|
var str = sep + node.symlink.join(sep);
|
|
1410
|
-
return encoding_1.strToEncoding(str, encoding);
|
|
1434
|
+
return (0, encoding_1.strToEncoding)(str, encoding);
|
|
1411
1435
|
};
|
|
1412
1436
|
Volume.prototype.readlinkSync = function (path, options) {
|
|
1413
1437
|
var opts = getDefaultOpts(options);
|
|
@@ -1567,7 +1591,7 @@ var Volume = /** @class */ (function () {
|
|
|
1567
1591
|
var filename = prefix + this.genRndStr();
|
|
1568
1592
|
try {
|
|
1569
1593
|
this.mkdirBase(filename, 511 /* DIR */);
|
|
1570
|
-
return encoding_1.strToEncoding(filename, encoding);
|
|
1594
|
+
return (0, encoding_1.strToEncoding)(filename, encoding);
|
|
1571
1595
|
}
|
|
1572
1596
|
catch (err) {
|
|
1573
1597
|
if (err.code === EEXIST) {
|
|
@@ -1829,7 +1853,7 @@ var StatWatcher = /** @class */ (function (_super) {
|
|
|
1829
1853
|
if (persistent === void 0) { persistent = true; }
|
|
1830
1854
|
if (interval === void 0) { interval = 5007; }
|
|
1831
1855
|
this.filename = pathToFilename(path);
|
|
1832
|
-
this.setTimeout = persistent ? setTimeout : setTimeoutUnref_1.default;
|
|
1856
|
+
this.setTimeout = persistent ? setTimeout.bind(globalThis) : setTimeoutUnref_1.default;
|
|
1833
1857
|
this.interval = interval;
|
|
1834
1858
|
this.prev = this.vol.statSync(this.filename);
|
|
1835
1859
|
this.loop();
|
|
@@ -1843,7 +1867,7 @@ var StatWatcher = /** @class */ (function (_super) {
|
|
|
1843
1867
|
exports.StatWatcher = StatWatcher;
|
|
1844
1868
|
var pool;
|
|
1845
1869
|
function allocNewPool(poolSize) {
|
|
1846
|
-
pool = buffer_1.bufferAllocUnsafe(poolSize);
|
|
1870
|
+
pool = (0, buffer_1.bufferAllocUnsafe)(poolSize);
|
|
1847
1871
|
pool.used = 0;
|
|
1848
1872
|
}
|
|
1849
1873
|
util.inherits(FsReadStream, stream_1.Readable);
|
|
@@ -2137,7 +2161,7 @@ var FSWatcher = /** @class */ (function (_super) {
|
|
|
2137
2161
|
if (encoding === void 0) { encoding = encoding_1.ENCODING_UTF8; }
|
|
2138
2162
|
this._filename = pathToFilename(path);
|
|
2139
2163
|
this._steps = filenameToSteps(this._filename);
|
|
2140
|
-
this._filenameEncoded = encoding_1.strToEncoding(this._filename);
|
|
2164
|
+
this._filenameEncoded = (0, encoding_1.strToEncoding)(this._filename);
|
|
2141
2165
|
// this._persistent = persistent;
|
|
2142
2166
|
this._recursive = recursive;
|
|
2143
2167
|
this._encoding = encoding;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "memfs",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.3",
|
|
4
4
|
"description": "In-memory file-system with Node's fs API.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"clean": "rimraf lib types",
|
|
12
12
|
"build": "tsc -p . && cpy src/*.js lib",
|
|
13
|
-
"test": "jest",
|
|
13
|
+
"test": "jest --maxWorkers 2",
|
|
14
14
|
"test:coverage": "jest --coverage",
|
|
15
15
|
"test:watch": "jest --watch",
|
|
16
16
|
"watch": "watch \"npm run build\" ./src",
|
|
@@ -23,26 +23,26 @@
|
|
|
23
23
|
"url": "https://github.com/streamich/memfs.git"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"fs-monkey": "1.0.
|
|
26
|
+
"fs-monkey": "1.0.3"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/jest": "
|
|
30
|
-
"@types/node": "10.17.
|
|
31
|
-
"cpy-cli": "3.1.
|
|
32
|
-
"husky": "
|
|
33
|
-
"jest": "
|
|
34
|
-
"prettier": "
|
|
35
|
-
"pretty-quick": "
|
|
29
|
+
"@types/jest": "27.0.1",
|
|
30
|
+
"@types/node": "10.17.60",
|
|
31
|
+
"cpy-cli": "3.1.1",
|
|
32
|
+
"husky": "7.0.2",
|
|
33
|
+
"jest": "27.1.0",
|
|
34
|
+
"prettier": "2.3.2",
|
|
35
|
+
"pretty-quick": "3.1.1",
|
|
36
36
|
"rimraf": "3.0.2",
|
|
37
|
-
"ts-jest": "
|
|
38
|
-
"ts-node": "
|
|
37
|
+
"ts-jest": "27.0.5",
|
|
38
|
+
"ts-node": "10.2.1",
|
|
39
39
|
"tslint": "5.20.1",
|
|
40
40
|
"tslint-config-common": "1.6.0",
|
|
41
|
-
"typescript": "
|
|
42
|
-
"semantic-release": "
|
|
43
|
-
"@semantic-release/changelog": "
|
|
44
|
-
"@semantic-release/git": "
|
|
45
|
-
"@semantic-release/npm": "
|
|
41
|
+
"typescript": "4.4.2",
|
|
42
|
+
"semantic-release": "17.4.7",
|
|
43
|
+
"@semantic-release/changelog": "5.0.1",
|
|
44
|
+
"@semantic-release/git": "9.0.0",
|
|
45
|
+
"@semantic-release/npm": "7.1.3"
|
|
46
46
|
},
|
|
47
47
|
"config": {
|
|
48
48
|
"commitizen": {
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"js",
|
|
57
57
|
"jsx"
|
|
58
58
|
],
|
|
59
|
+
"testEnvironment": "node",
|
|
59
60
|
"transform": {
|
|
60
61
|
"^.+\\.tsx?$": "ts-jest"
|
|
61
62
|
},
|
|
@@ -76,6 +77,7 @@
|
|
|
76
77
|
"@semantic-release/git"
|
|
77
78
|
]
|
|
78
79
|
},
|
|
80
|
+
"license": "Unlicense",
|
|
79
81
|
"keywords": [
|
|
80
82
|
"fs",
|
|
81
83
|
"filesystem",
|