memfs 3.4.12 → 3.5.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/Stats.d.ts +1 -1
- package/lib/encoding.d.ts +2 -2
- package/lib/promises.d.ts +1 -1
- package/lib/setImmediate.d.ts +1 -1
- package/lib/setTimeoutUnref.d.ts +1 -1
- package/lib/volume.d.ts +9 -9
- package/lib/volume.js +76 -7
- package/package.json +1 -1
package/lib/Stats.d.ts
CHANGED
package/lib/encoding.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export type TDataOut = string | Buffer;
|
|
3
|
+
export type TEncodingExtended = BufferEncoding | 'buffer';
|
|
4
4
|
export declare const ENCODING_UTF8: BufferEncoding;
|
|
5
5
|
export declare function assertEncoding(encoding: string | undefined): void;
|
|
6
6
|
export declare function strToEncoding(str: string, encoding?: TEncodingExtended): TDataOut;
|
package/lib/promises.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export interface IFileHandle {
|
|
|
28
28
|
write(buffer: Buffer | Uint8Array, offset?: number, length?: number, position?: number): Promise<TFileHandleWriteResult>;
|
|
29
29
|
writeFile(data: TData, options?: IWriteFileOptions): Promise<void>;
|
|
30
30
|
}
|
|
31
|
-
export
|
|
31
|
+
export type TFileHandle = PathLike | IFileHandle;
|
|
32
32
|
export interface IPromisesAPI {
|
|
33
33
|
FileHandle: any;
|
|
34
34
|
access(path: PathLike, mode?: number): Promise<void>;
|
package/lib/setImmediate.d.ts
CHANGED
package/lib/setTimeoutUnref.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type TSetTimeout = (callback: (...args: any[]) => void, time?: number, args?: any[]) => any;
|
|
2
2
|
/**
|
|
3
3
|
* `setTimeoutUnref` is just like `setTimeout`,
|
|
4
4
|
* only in Node's environment it will "unref" its macro task.
|
package/lib/volume.d.ts
CHANGED
|
@@ -14,12 +14,12 @@ import { TEncodingExtended, TDataOut } from './encoding';
|
|
|
14
14
|
export interface IError extends Error {
|
|
15
15
|
code?: string;
|
|
16
16
|
}
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
20
|
-
export
|
|
21
|
-
export
|
|
22
|
-
export
|
|
17
|
+
export type TFileId = PathLike | number;
|
|
18
|
+
export type TData = TDataOut | Uint8Array;
|
|
19
|
+
export type TFlags = string | number;
|
|
20
|
+
export type TMode = string | number;
|
|
21
|
+
export type TTime = number | string | Date;
|
|
22
|
+
export type TCallback<TData> = (error?: IError | null, data?: TData) => void;
|
|
23
23
|
export declare enum FLAGS {
|
|
24
24
|
r,
|
|
25
25
|
'r+',
|
|
@@ -40,7 +40,7 @@ export declare enum FLAGS {
|
|
|
40
40
|
'ax+',
|
|
41
41
|
'xa+'
|
|
42
42
|
}
|
|
43
|
-
export
|
|
43
|
+
export type TFlagsCopy = typeof constants.COPYFILE_EXCL | typeof constants.COPYFILE_FICLONE | typeof constants.COPYFILE_FICLONE_FORCE;
|
|
44
44
|
export declare function flagsToNumber(flags: TFlags | undefined): number;
|
|
45
45
|
export interface IOptions {
|
|
46
46
|
encoding?: BufferEncoding | TEncodingExtended;
|
|
@@ -114,7 +114,7 @@ export declare function dataToStr(data: TData, encoding?: string): string;
|
|
|
114
114
|
export declare function dataToBuffer(data: TData, encoding?: string): Buffer;
|
|
115
115
|
export declare function bufferToEncoding(buffer: Buffer, encoding?: TEncodingExtended): TDataOut;
|
|
116
116
|
export declare function toUnixTimestamp(time: any): any;
|
|
117
|
-
|
|
117
|
+
type DirectoryContent = string | null;
|
|
118
118
|
export interface DirectoryJSON {
|
|
119
119
|
[key: string]: DirectoryContent;
|
|
120
120
|
}
|
|
@@ -440,9 +440,9 @@ export declare class FSWatcher extends EventEmitter {
|
|
|
440
440
|
_encoding: BufferEncoding;
|
|
441
441
|
_link: Link;
|
|
442
442
|
_timer: any;
|
|
443
|
+
private _listenerRemovers;
|
|
443
444
|
constructor(vol: Volume);
|
|
444
445
|
private _getName;
|
|
445
|
-
private _onNodeChange;
|
|
446
446
|
private _onParentChild;
|
|
447
447
|
private _emit;
|
|
448
448
|
private _persist;
|
package/lib/volume.js
CHANGED
|
@@ -127,6 +127,9 @@ function createError(errorCode, func, path, path2, Constructor) {
|
|
|
127
127
|
if (Constructor === void 0) { Constructor = Error; }
|
|
128
128
|
var error = new Constructor(formatError(errorCode, func, path, path2));
|
|
129
129
|
error.code = errorCode;
|
|
130
|
+
if (path) {
|
|
131
|
+
error.path = path;
|
|
132
|
+
}
|
|
130
133
|
return error;
|
|
131
134
|
}
|
|
132
135
|
// ---------------------------------------- Flags
|
|
@@ -2214,9 +2217,8 @@ var FSWatcher = /** @class */ (function (_super) {
|
|
|
2214
2217
|
// _persistent: boolean = true;
|
|
2215
2218
|
_this._recursive = false;
|
|
2216
2219
|
_this._encoding = encoding_1.ENCODING_UTF8;
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
};
|
|
2220
|
+
// inode -> removers
|
|
2221
|
+
_this._listenerRemovers = new Map();
|
|
2220
2222
|
_this._onParentChild = function (link) {
|
|
2221
2223
|
if (link.getName() === _this._getName()) {
|
|
2222
2224
|
_this._emit('rename');
|
|
@@ -2248,6 +2250,7 @@ var FSWatcher = /** @class */ (function (_super) {
|
|
|
2248
2250
|
return this._steps[this._steps.length - 1];
|
|
2249
2251
|
};
|
|
2250
2252
|
FSWatcher.prototype.start = function (path, persistent, recursive, encoding) {
|
|
2253
|
+
var _this = this;
|
|
2251
2254
|
if (persistent === void 0) { persistent = true; }
|
|
2252
2255
|
if (recursive === void 0) { recursive = false; }
|
|
2253
2256
|
if (encoding === void 0) { encoding = encoding_1.ENCODING_UTF8; }
|
|
@@ -2266,9 +2269,72 @@ var FSWatcher = /** @class */ (function (_super) {
|
|
|
2266
2269
|
error.errno = err.code;
|
|
2267
2270
|
throw error;
|
|
2268
2271
|
}
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
+
var watchLinkNodeChanged = function (link) {
|
|
2273
|
+
var _a;
|
|
2274
|
+
var filepath = link.getPath();
|
|
2275
|
+
var node = link.getNode();
|
|
2276
|
+
var onNodeChange = function () { return _this.emit('change', 'change', relative(_this._filename, filepath)); };
|
|
2277
|
+
node.on('change', onNodeChange);
|
|
2278
|
+
var removers = (_a = _this._listenerRemovers.get(node.ino)) !== null && _a !== void 0 ? _a : [];
|
|
2279
|
+
removers.push(function () { return node.removeListener('change', onNodeChange); });
|
|
2280
|
+
_this._listenerRemovers.set(node.ino, removers);
|
|
2281
|
+
};
|
|
2282
|
+
var watchLinkChildrenChanged = function (link) {
|
|
2283
|
+
var _a;
|
|
2284
|
+
var node = link.getNode();
|
|
2285
|
+
// when a new link added
|
|
2286
|
+
var onLinkChildAdd = function (l) {
|
|
2287
|
+
_this.emit('change', 'rename', relative(_this._filename, l.getPath()));
|
|
2288
|
+
setTimeout(function () {
|
|
2289
|
+
// 1. watch changes of the new link-node
|
|
2290
|
+
watchLinkNodeChanged(l);
|
|
2291
|
+
// 2. watch changes of the new link-node's children
|
|
2292
|
+
watchLinkChildrenChanged(l);
|
|
2293
|
+
});
|
|
2294
|
+
};
|
|
2295
|
+
// when a new link deleted
|
|
2296
|
+
var onLinkChildDelete = function (l) {
|
|
2297
|
+
// remove the listeners of the children nodes
|
|
2298
|
+
var removeLinkNodeListeners = function (curLink) {
|
|
2299
|
+
var ino = curLink.getNode().ino;
|
|
2300
|
+
var removers = _this._listenerRemovers.get(ino);
|
|
2301
|
+
if (removers) {
|
|
2302
|
+
removers.forEach(function (r) { return r(); });
|
|
2303
|
+
_this._listenerRemovers.delete(ino);
|
|
2304
|
+
}
|
|
2305
|
+
Object.values(curLink.children).forEach(function (childLink) {
|
|
2306
|
+
if (childLink) {
|
|
2307
|
+
removeLinkNodeListeners(childLink);
|
|
2308
|
+
}
|
|
2309
|
+
});
|
|
2310
|
+
};
|
|
2311
|
+
removeLinkNodeListeners(l);
|
|
2312
|
+
_this.emit('change', 'rename', relative(_this._filename, l.getPath()));
|
|
2313
|
+
};
|
|
2314
|
+
// children nodes changed
|
|
2315
|
+
Object.values(link.children).forEach(function (childLink) {
|
|
2316
|
+
if (childLink) {
|
|
2317
|
+
watchLinkNodeChanged(childLink);
|
|
2318
|
+
}
|
|
2319
|
+
});
|
|
2320
|
+
// link children add/remove
|
|
2321
|
+
link.on('child:add', onLinkChildAdd);
|
|
2322
|
+
link.on('child:delete', onLinkChildDelete);
|
|
2323
|
+
var removers = (_a = _this._listenerRemovers.get(node.ino)) !== null && _a !== void 0 ? _a : [];
|
|
2324
|
+
removers.push(function () {
|
|
2325
|
+
link.removeListener('child:add', onLinkChildAdd);
|
|
2326
|
+
link.removeListener('child:delete', onLinkChildDelete);
|
|
2327
|
+
});
|
|
2328
|
+
if (recursive) {
|
|
2329
|
+
Object.values(link.children).forEach(function (childLink) {
|
|
2330
|
+
if (childLink) {
|
|
2331
|
+
watchLinkChildrenChanged(childLink);
|
|
2332
|
+
}
|
|
2333
|
+
});
|
|
2334
|
+
}
|
|
2335
|
+
};
|
|
2336
|
+
watchLinkNodeChanged(this._link);
|
|
2337
|
+
watchLinkChildrenChanged(this._link);
|
|
2272
2338
|
var parent = this._link.parent;
|
|
2273
2339
|
if (parent) {
|
|
2274
2340
|
// parent.on('child:add', this._onParentChild);
|
|
@@ -2280,7 +2346,10 @@ var FSWatcher = /** @class */ (function (_super) {
|
|
|
2280
2346
|
};
|
|
2281
2347
|
FSWatcher.prototype.close = function () {
|
|
2282
2348
|
clearTimeout(this._timer);
|
|
2283
|
-
this.
|
|
2349
|
+
this._listenerRemovers.forEach(function (removers) {
|
|
2350
|
+
removers.forEach(function (r) { return r(); });
|
|
2351
|
+
});
|
|
2352
|
+
this._listenerRemovers.clear();
|
|
2284
2353
|
var parent = this._link.parent;
|
|
2285
2354
|
if (parent) {
|
|
2286
2355
|
// parent.removeListener('child:add', this._onParentChild);
|