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 +26 -27
- package/lib/Stats.js +27 -31
- package/lib/encoding.js +2 -2
- package/lib/index.d.ts +16 -2
- package/lib/index.js +28 -26
- package/lib/internal/buffer.js +5 -18
- package/lib/internal/errors.js +61 -91
- package/lib/node/FileHandle.d.ts +30 -0
- package/lib/node/FileHandle.js +50 -0
- package/lib/node/promises.d.ts +2 -0
- package/lib/node/promises.js +88 -0
- package/lib/node/types/callback.d.ts +83 -0
- package/lib/node/types/callback.js +2 -0
- package/lib/node/types/index.d.ts +7 -0
- package/lib/node/types/index.js +2 -0
- package/lib/node/types/misc.d.ts +112 -0
- package/lib/node/types/misc.js +2 -0
- package/lib/node/types/options.d.ts +72 -0
- package/lib/node/types/options.js +2 -0
- package/lib/node/types/promises.d.ts +31 -0
- package/lib/node/types/promises.js +2 -0
- package/lib/node/types/sync.d.ts +100 -0
- package/lib/node/types/sync.js +2 -0
- package/lib/node/util.d.ts +2 -0
- package/lib/node/util.js +13 -0
- package/lib/node.d.ts +2 -2
- package/lib/node.js +209 -289
- package/lib/process.js +5 -5
- package/lib/setImmediate.js +1 -1
- package/lib/setTimeoutUnref.js +1 -1
- package/lib/volume-localstorage.js +48 -85
- package/lib/volume.d.ts +13 -10
- package/lib/volume.js +789 -897
- package/package.json +63 -63
- package/lib/promises.d.ts +0 -78
- package/lib/promises.js +0 -158
package/lib/process.js
CHANGED
|
@@ -12,7 +12,7 @@ exports.createProcess = void 0;
|
|
|
12
12
|
*
|
|
13
13
|
* @return {IProcess | undefined}
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
const maybeReturnProcess = () => {
|
|
16
16
|
if (typeof process !== 'undefined') {
|
|
17
17
|
return process;
|
|
18
18
|
}
|
|
@@ -24,15 +24,15 @@ var maybeReturnProcess = function () {
|
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
function createProcess() {
|
|
27
|
-
|
|
27
|
+
const p = maybeReturnProcess() || {};
|
|
28
28
|
if (!p.cwd)
|
|
29
|
-
p.cwd =
|
|
29
|
+
p.cwd = () => '/';
|
|
30
30
|
if (!p.nextTick)
|
|
31
31
|
p.nextTick = require('./setImmediate').default;
|
|
32
32
|
if (!p.emitWarning)
|
|
33
|
-
p.emitWarning =
|
|
33
|
+
p.emitWarning = (message, type) => {
|
|
34
34
|
// tslint:disable-next-line:no-console
|
|
35
|
-
console.warn(
|
|
35
|
+
console.warn(`${type}${type ? ': ' : ''}${message}`);
|
|
36
36
|
};
|
|
37
37
|
if (!p.env)
|
|
38
38
|
p.env = {};
|
package/lib/setImmediate.js
CHANGED
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
|
-
|
|
8
|
+
const ref = setTimeout.apply(typeof globalThis !== 'undefined' ? globalThis : global, arguments);
|
|
9
9
|
if (ref && typeof ref === 'object' && typeof ref.unref === 'function')
|
|
10
10
|
ref.unref();
|
|
11
11
|
return ref;
|
|
@@ -1,110 +1,73 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
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");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.createVolume = exports.ObjectStore = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
4
|
+
const volume_1 = require("./volume");
|
|
5
|
+
const node_1 = require("./node");
|
|
6
|
+
class ObjectStore {
|
|
7
|
+
constructor(obj) {
|
|
23
8
|
this.obj = obj;
|
|
24
9
|
}
|
|
25
|
-
|
|
10
|
+
setItem(key, json) {
|
|
26
11
|
this.obj[key] = JSON.stringify(json);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
12
|
+
}
|
|
13
|
+
getItem(key) {
|
|
14
|
+
const data = this.obj[key];
|
|
30
15
|
if (typeof data === void 0)
|
|
31
16
|
return void 0;
|
|
32
17
|
return JSON.parse(data);
|
|
33
|
-
}
|
|
34
|
-
|
|
18
|
+
}
|
|
19
|
+
removeItem(key) {
|
|
35
20
|
delete this.obj[key];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
}());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
39
23
|
exports.ObjectStore = ObjectStore;
|
|
40
|
-
function createVolume(namespace, LS) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return
|
|
24
|
+
function createVolume(namespace, LS = localStorage) {
|
|
25
|
+
const store = new ObjectStore(LS);
|
|
26
|
+
const key = (type, id) => `memfs.${namespace}.${type}.${id}`;
|
|
27
|
+
class NodeLocalStorage extends node_1.Node {
|
|
28
|
+
get Key() {
|
|
29
|
+
if (!this._key)
|
|
30
|
+
this._key = key('ino', this.ino);
|
|
31
|
+
return this._key;
|
|
48
32
|
}
|
|
49
|
-
|
|
50
|
-
get: function () {
|
|
51
|
-
if (!this._key)
|
|
52
|
-
this._key = key('ino', this.ino);
|
|
53
|
-
return this._key;
|
|
54
|
-
},
|
|
55
|
-
enumerable: false,
|
|
56
|
-
configurable: true
|
|
57
|
-
});
|
|
58
|
-
NodeLocalStorage.prototype.sync = function () {
|
|
33
|
+
sync() {
|
|
59
34
|
store.setItem(this.Key, this.toJSON());
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
35
|
+
}
|
|
36
|
+
touch() {
|
|
37
|
+
super.touch();
|
|
63
38
|
this.sync();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
39
|
+
}
|
|
40
|
+
del() {
|
|
41
|
+
super.del();
|
|
67
42
|
store.removeItem(this.Key);
|
|
68
|
-
};
|
|
69
|
-
return NodeLocalStorage;
|
|
70
|
-
}(node_1.Node));
|
|
71
|
-
var LinkLocalStorage = /** @class */ (function (_super) {
|
|
72
|
-
__extends(LinkLocalStorage, _super);
|
|
73
|
-
function LinkLocalStorage() {
|
|
74
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
75
43
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
});
|
|
85
|
-
LinkLocalStorage.prototype.sync = function () {
|
|
44
|
+
}
|
|
45
|
+
class LinkLocalStorage extends node_1.Link {
|
|
46
|
+
get Key() {
|
|
47
|
+
if (!this._key)
|
|
48
|
+
this._key = key('link', this.getPath());
|
|
49
|
+
return this._key;
|
|
50
|
+
}
|
|
51
|
+
sync() {
|
|
86
52
|
store.setItem(this.Key, this.toJSON());
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
function VolumeLocalStorage() {
|
|
93
|
-
return _super.call(this, {
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return class VolumeLocalStorage extends volume_1.Volume {
|
|
56
|
+
constructor() {
|
|
57
|
+
super({
|
|
94
58
|
Node: NodeLocalStorage,
|
|
95
59
|
Link: LinkLocalStorage,
|
|
96
|
-
})
|
|
60
|
+
});
|
|
97
61
|
}
|
|
98
|
-
|
|
99
|
-
|
|
62
|
+
createLink(parent, name, isDirectory, perm) {
|
|
63
|
+
const link = super.createLink(parent, name, isDirectory, perm);
|
|
100
64
|
store.setItem(key('link', link.getPath()), link.toJSON());
|
|
101
65
|
return link;
|
|
102
|
-
}
|
|
103
|
-
|
|
66
|
+
}
|
|
67
|
+
deleteLink(link) {
|
|
104
68
|
store.removeItem(key('link', link.getPath()));
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
}(volume_1.Volume));
|
|
69
|
+
return super.deleteLink(link);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
109
72
|
}
|
|
110
73
|
exports.createVolume = createVolume;
|
package/lib/volume.d.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
/// <reference types="node" />
|
|
5
|
-
import { PathLike, symlink } from 'fs';
|
|
6
5
|
import { Node, Link, File } from './node';
|
|
7
6
|
import Stats from './Stats';
|
|
8
7
|
import Dirent from './Dirent';
|
|
@@ -11,11 +10,12 @@ import { Readable, Writable } from 'stream';
|
|
|
11
10
|
import { constants } from './constants';
|
|
12
11
|
import { EventEmitter } from 'events';
|
|
13
12
|
import { TEncodingExtended, TDataOut } from './encoding';
|
|
13
|
+
import type { PathLike, symlink } from 'fs';
|
|
14
14
|
export interface IError extends Error {
|
|
15
15
|
code?: string;
|
|
16
16
|
}
|
|
17
17
|
export type TFileId = PathLike | number;
|
|
18
|
-
export type TData = TDataOut |
|
|
18
|
+
export type TData = TDataOut | ArrayBufferView | DataView;
|
|
19
19
|
export type TFlags = string | number;
|
|
20
20
|
export type TMode = string | number;
|
|
21
21
|
export type TTime = number | string | Date;
|
|
@@ -89,7 +89,10 @@ export interface IMkdirOptions {
|
|
|
89
89
|
recursive?: boolean;
|
|
90
90
|
}
|
|
91
91
|
export interface IRmdirOptions {
|
|
92
|
+
/** @deprecated */
|
|
92
93
|
recursive?: boolean;
|
|
94
|
+
maxRetries?: number;
|
|
95
|
+
retryDelay?: number;
|
|
93
96
|
}
|
|
94
97
|
export interface IRmOptions {
|
|
95
98
|
force?: boolean;
|
|
@@ -157,7 +160,7 @@ export declare class Volume {
|
|
|
157
160
|
File: new (...args: any[]) => File;
|
|
158
161
|
};
|
|
159
162
|
private promisesApi;
|
|
160
|
-
get promises(): import("./
|
|
163
|
+
get promises(): import("./node/types").FsPromisesApi;
|
|
161
164
|
constructor(props?: {});
|
|
162
165
|
createLink(): Link;
|
|
163
166
|
createLink(parent: Link, name: string, isDirectory?: boolean, perm?: number): Link;
|
|
@@ -199,19 +202,19 @@ export declare class Volume {
|
|
|
199
202
|
close(fd: number, callback: TCallback<void>): void;
|
|
200
203
|
private openFileOrGetById;
|
|
201
204
|
private readBase;
|
|
202
|
-
readSync(fd: number, buffer: Buffer |
|
|
203
|
-
read(fd: number, buffer: Buffer |
|
|
205
|
+
readSync(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, position: number): number;
|
|
206
|
+
read(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, position: number, callback: (err?: Error | null, bytesRead?: number, buffer?: Buffer | ArrayBufferView | DataView) => void): void;
|
|
204
207
|
private readFileBase;
|
|
205
208
|
readFileSync(file: TFileId, options?: IReadFileOptions | string): TDataOut;
|
|
206
209
|
readFile(id: TFileId, callback: TCallback<TDataOut>): any;
|
|
207
210
|
readFile(id: TFileId, options: IReadFileOptions | string, callback: TCallback<TDataOut>): any;
|
|
208
211
|
private writeBase;
|
|
209
|
-
writeSync(fd: number, buffer: Buffer |
|
|
212
|
+
writeSync(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset?: number, length?: number, position?: number): number;
|
|
210
213
|
writeSync(fd: number, str: string, position?: number, encoding?: BufferEncoding): number;
|
|
211
|
-
write(fd: number, buffer: Buffer |
|
|
212
|
-
write(fd: number, buffer: Buffer |
|
|
213
|
-
write(fd: number, buffer: Buffer |
|
|
214
|
-
write(fd: number, buffer: Buffer |
|
|
214
|
+
write(fd: number, buffer: Buffer | ArrayBufferView | DataView, callback: (...args: any[]) => void): any;
|
|
215
|
+
write(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, callback: (...args: any[]) => void): any;
|
|
216
|
+
write(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, callback: (...args: any[]) => void): any;
|
|
217
|
+
write(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, position: number, callback: (...args: any[]) => void): any;
|
|
215
218
|
write(fd: number, str: string, callback: (...args: any[]) => void): any;
|
|
216
219
|
write(fd: number, str: string, position: number, callback: (...args: any[]) => void): any;
|
|
217
220
|
write(fd: number, str: string, position: number, encoding: BufferEncoding, callback: (...args: any[]) => void): any;
|