memfs 3.5.3 → 4.0.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/fsa/types.d.ts +82 -0
- package/lib/fsa/types.js +2 -0
- 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 +1 -1
- package/lib/promises.d.ts +0 -78
- package/lib/promises.js +0 -158
package/lib/node.js
CHANGED
|
@@ -1,213 +1,160 @@
|
|
|
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.File = exports.Link = exports.Node = exports.SEP = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
4
|
+
const process_1 = require("./process");
|
|
5
|
+
const buffer_1 = require("./internal/buffer");
|
|
6
|
+
const constants_1 = require("./constants");
|
|
7
|
+
const events_1 = require("events");
|
|
8
|
+
const Stats_1 = require("./Stats");
|
|
9
|
+
const { S_IFMT, S_IFDIR, S_IFREG, S_IFLNK, O_APPEND } = constants_1.constants;
|
|
10
|
+
const getuid = () => { var _a, _b; return (_b = (_a = process_1.default.getuid) === null || _a === void 0 ? void 0 : _a.call(process_1.default)) !== null && _b !== void 0 ? _b : 0; };
|
|
11
|
+
const getgid = () => { var _a, _b; return (_b = (_a = process_1.default.getgid) === null || _a === void 0 ? void 0 : _a.call(process_1.default)) !== null && _b !== void 0 ? _b : 0; };
|
|
27
12
|
exports.SEP = '/';
|
|
28
13
|
/**
|
|
29
14
|
* Node in a file system (like i-node, v-node).
|
|
30
15
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (perm === void 0) { perm = 438; }
|
|
35
|
-
var _this = _super.call(this) || this;
|
|
16
|
+
class Node extends events_1.EventEmitter {
|
|
17
|
+
constructor(ino, perm = 0o666) {
|
|
18
|
+
super();
|
|
36
19
|
// User ID and group ID.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
20
|
+
this._uid = getuid();
|
|
21
|
+
this._gid = getgid();
|
|
22
|
+
this._atime = new Date();
|
|
23
|
+
this._mtime = new Date();
|
|
24
|
+
this._ctime = new Date();
|
|
25
|
+
this._perm = 0o666; // Permissions `chmod`, `fchmod`
|
|
26
|
+
this.mode = S_IFREG; // S_IFDIR, S_IFREG, etc.. (file by default?)
|
|
44
27
|
// Number of hard links pointing at this Node.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
this._mtime = mtime;
|
|
100
|
-
this.ctime = new Date();
|
|
101
|
-
},
|
|
102
|
-
enumerable: false,
|
|
103
|
-
configurable: true
|
|
104
|
-
});
|
|
105
|
-
Object.defineProperty(Node.prototype, "perm", {
|
|
106
|
-
get: function () {
|
|
107
|
-
return this._perm;
|
|
108
|
-
},
|
|
109
|
-
set: function (perm) {
|
|
110
|
-
this._perm = perm;
|
|
111
|
-
this.ctime = new Date();
|
|
112
|
-
},
|
|
113
|
-
enumerable: false,
|
|
114
|
-
configurable: true
|
|
115
|
-
});
|
|
116
|
-
Object.defineProperty(Node.prototype, "nlink", {
|
|
117
|
-
get: function () {
|
|
118
|
-
return this._nlink;
|
|
119
|
-
},
|
|
120
|
-
set: function (nlink) {
|
|
121
|
-
this._nlink = nlink;
|
|
122
|
-
this.ctime = new Date();
|
|
123
|
-
},
|
|
124
|
-
enumerable: false,
|
|
125
|
-
configurable: true
|
|
126
|
-
});
|
|
127
|
-
Node.prototype.getString = function (encoding) {
|
|
128
|
-
if (encoding === void 0) { encoding = 'utf8'; }
|
|
28
|
+
this._nlink = 1;
|
|
29
|
+
this._perm = perm;
|
|
30
|
+
this.mode |= perm;
|
|
31
|
+
this.ino = ino;
|
|
32
|
+
}
|
|
33
|
+
set ctime(ctime) {
|
|
34
|
+
this._ctime = ctime;
|
|
35
|
+
}
|
|
36
|
+
get ctime() {
|
|
37
|
+
return this._ctime;
|
|
38
|
+
}
|
|
39
|
+
set uid(uid) {
|
|
40
|
+
this._uid = uid;
|
|
41
|
+
this.ctime = new Date();
|
|
42
|
+
}
|
|
43
|
+
get uid() {
|
|
44
|
+
return this._uid;
|
|
45
|
+
}
|
|
46
|
+
set gid(gid) {
|
|
47
|
+
this._gid = gid;
|
|
48
|
+
this.ctime = new Date();
|
|
49
|
+
}
|
|
50
|
+
get gid() {
|
|
51
|
+
return this._gid;
|
|
52
|
+
}
|
|
53
|
+
set atime(atime) {
|
|
54
|
+
this._atime = atime;
|
|
55
|
+
this.ctime = new Date();
|
|
56
|
+
}
|
|
57
|
+
get atime() {
|
|
58
|
+
return this._atime;
|
|
59
|
+
}
|
|
60
|
+
set mtime(mtime) {
|
|
61
|
+
this._mtime = mtime;
|
|
62
|
+
this.ctime = new Date();
|
|
63
|
+
}
|
|
64
|
+
get mtime() {
|
|
65
|
+
return this._mtime;
|
|
66
|
+
}
|
|
67
|
+
set perm(perm) {
|
|
68
|
+
this._perm = perm;
|
|
69
|
+
this.ctime = new Date();
|
|
70
|
+
}
|
|
71
|
+
get perm() {
|
|
72
|
+
return this._perm;
|
|
73
|
+
}
|
|
74
|
+
set nlink(nlink) {
|
|
75
|
+
this._nlink = nlink;
|
|
76
|
+
this.ctime = new Date();
|
|
77
|
+
}
|
|
78
|
+
get nlink() {
|
|
79
|
+
return this._nlink;
|
|
80
|
+
}
|
|
81
|
+
getString(encoding = 'utf8') {
|
|
129
82
|
this.atime = new Date();
|
|
130
83
|
return this.getBuffer().toString(encoding);
|
|
131
|
-
}
|
|
132
|
-
|
|
84
|
+
}
|
|
85
|
+
setString(str) {
|
|
133
86
|
// this.setBuffer(bufferFrom(str, 'utf8'));
|
|
134
87
|
this.buf = (0, buffer_1.bufferFrom)(str, 'utf8');
|
|
135
88
|
this.touch();
|
|
136
|
-
}
|
|
137
|
-
|
|
89
|
+
}
|
|
90
|
+
getBuffer() {
|
|
138
91
|
this.atime = new Date();
|
|
139
92
|
if (!this.buf)
|
|
140
93
|
this.setBuffer((0, buffer_1.bufferAllocUnsafe)(0));
|
|
141
94
|
return (0, buffer_1.bufferFrom)(this.buf); // Return a copy.
|
|
142
|
-
}
|
|
143
|
-
|
|
95
|
+
}
|
|
96
|
+
setBuffer(buf) {
|
|
144
97
|
this.buf = (0, buffer_1.bufferFrom)(buf); // Creates a copy of data.
|
|
145
98
|
this.touch();
|
|
146
|
-
}
|
|
147
|
-
|
|
99
|
+
}
|
|
100
|
+
getSize() {
|
|
148
101
|
return this.buf ? this.buf.length : 0;
|
|
149
|
-
}
|
|
150
|
-
|
|
102
|
+
}
|
|
103
|
+
setModeProperty(property) {
|
|
151
104
|
this.mode = (this.mode & ~S_IFMT) | property;
|
|
152
|
-
}
|
|
153
|
-
|
|
105
|
+
}
|
|
106
|
+
setIsFile() {
|
|
154
107
|
this.setModeProperty(S_IFREG);
|
|
155
|
-
}
|
|
156
|
-
|
|
108
|
+
}
|
|
109
|
+
setIsDirectory() {
|
|
157
110
|
this.setModeProperty(S_IFDIR);
|
|
158
|
-
}
|
|
159
|
-
|
|
111
|
+
}
|
|
112
|
+
setIsSymlink() {
|
|
160
113
|
this.setModeProperty(S_IFLNK);
|
|
161
|
-
}
|
|
162
|
-
|
|
114
|
+
}
|
|
115
|
+
isFile() {
|
|
163
116
|
return (this.mode & S_IFMT) === S_IFREG;
|
|
164
|
-
}
|
|
165
|
-
|
|
117
|
+
}
|
|
118
|
+
isDirectory() {
|
|
166
119
|
return (this.mode & S_IFMT) === S_IFDIR;
|
|
167
|
-
}
|
|
168
|
-
|
|
120
|
+
}
|
|
121
|
+
isSymlink() {
|
|
169
122
|
// return !!this.symlink;
|
|
170
123
|
return (this.mode & S_IFMT) === S_IFLNK;
|
|
171
|
-
}
|
|
172
|
-
|
|
124
|
+
}
|
|
125
|
+
makeSymlink(steps) {
|
|
173
126
|
this.symlink = steps;
|
|
174
127
|
this.setIsSymlink();
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (off === void 0) { off = 0; }
|
|
178
|
-
if (len === void 0) { len = buf.length; }
|
|
179
|
-
if (pos === void 0) { pos = 0; }
|
|
128
|
+
}
|
|
129
|
+
write(buf, off = 0, len = buf.length, pos = 0) {
|
|
180
130
|
if (!this.buf)
|
|
181
131
|
this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
|
|
182
132
|
if (pos + len > this.buf.length) {
|
|
183
|
-
|
|
133
|
+
const newBuf = (0, buffer_1.bufferAllocUnsafe)(pos + len);
|
|
184
134
|
this.buf.copy(newBuf, 0, 0, this.buf.length);
|
|
185
135
|
this.buf = newBuf;
|
|
186
136
|
}
|
|
187
137
|
buf.copy(this.buf, pos, off, off + len);
|
|
188
138
|
this.touch();
|
|
189
139
|
return len;
|
|
190
|
-
}
|
|
140
|
+
}
|
|
191
141
|
// Returns the number of bytes read.
|
|
192
|
-
|
|
193
|
-
if (off === void 0) { off = 0; }
|
|
194
|
-
if (len === void 0) { len = buf.byteLength; }
|
|
195
|
-
if (pos === void 0) { pos = 0; }
|
|
142
|
+
read(buf, off = 0, len = buf.byteLength, pos = 0) {
|
|
196
143
|
this.atime = new Date();
|
|
197
144
|
if (!this.buf)
|
|
198
145
|
this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
|
|
199
|
-
|
|
146
|
+
let actualLen = len;
|
|
200
147
|
if (actualLen > buf.byteLength) {
|
|
201
148
|
actualLen = buf.byteLength;
|
|
202
149
|
}
|
|
203
150
|
if (actualLen + pos > this.buf.length) {
|
|
204
151
|
actualLen = this.buf.length - pos;
|
|
205
152
|
}
|
|
206
|
-
|
|
153
|
+
const buf2 = buf instanceof Buffer ? buf : Buffer.from(buf.buffer);
|
|
154
|
+
this.buf.copy(buf2, off, pos, pos + actualLen);
|
|
207
155
|
return actualLen;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (len === void 0) { len = 0; }
|
|
156
|
+
}
|
|
157
|
+
truncate(len = 0) {
|
|
211
158
|
if (!len)
|
|
212
159
|
this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
|
|
213
160
|
else {
|
|
@@ -217,31 +164,29 @@ var Node = /** @class */ (function (_super) {
|
|
|
217
164
|
this.buf = this.buf.slice(0, len);
|
|
218
165
|
}
|
|
219
166
|
else {
|
|
220
|
-
|
|
167
|
+
const buf = (0, buffer_1.bufferAllocUnsafe)(len);
|
|
221
168
|
this.buf.copy(buf);
|
|
222
169
|
buf.fill(0, this.buf.length);
|
|
223
170
|
this.buf = buf;
|
|
224
171
|
}
|
|
225
172
|
}
|
|
226
173
|
this.touch();
|
|
227
|
-
}
|
|
228
|
-
|
|
174
|
+
}
|
|
175
|
+
chmod(perm) {
|
|
229
176
|
this.perm = perm;
|
|
230
|
-
this.mode = (this.mode & ~
|
|
177
|
+
this.mode = (this.mode & ~0o777) | perm;
|
|
231
178
|
this.touch();
|
|
232
|
-
}
|
|
233
|
-
|
|
179
|
+
}
|
|
180
|
+
chown(uid, gid) {
|
|
234
181
|
this.uid = uid;
|
|
235
182
|
this.gid = gid;
|
|
236
183
|
this.touch();
|
|
237
|
-
}
|
|
238
|
-
|
|
184
|
+
}
|
|
185
|
+
touch() {
|
|
239
186
|
this.mtime = new Date();
|
|
240
187
|
this.emit('change', this);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (uid === void 0) { uid = getuid(); }
|
|
244
|
-
if (gid === void 0) { gid = getgid(); }
|
|
188
|
+
}
|
|
189
|
+
canRead(uid = getuid(), gid = getgid()) {
|
|
245
190
|
if (this.perm & 4 /* S.IROTH */) {
|
|
246
191
|
return true;
|
|
247
192
|
}
|
|
@@ -256,10 +201,8 @@ var Node = /** @class */ (function (_super) {
|
|
|
256
201
|
}
|
|
257
202
|
}
|
|
258
203
|
return false;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
if (uid === void 0) { uid = getuid(); }
|
|
262
|
-
if (gid === void 0) { gid = getgid(); }
|
|
204
|
+
}
|
|
205
|
+
canWrite(uid = getuid(), gid = getgid()) {
|
|
263
206
|
if (this.perm & 2 /* S.IWOTH */) {
|
|
264
207
|
return true;
|
|
265
208
|
}
|
|
@@ -274,11 +217,11 @@ var Node = /** @class */ (function (_super) {
|
|
|
274
217
|
}
|
|
275
218
|
}
|
|
276
219
|
return false;
|
|
277
|
-
}
|
|
278
|
-
|
|
220
|
+
}
|
|
221
|
+
del() {
|
|
279
222
|
this.emit('delete', this);
|
|
280
|
-
}
|
|
281
|
-
|
|
223
|
+
}
|
|
224
|
+
toJSON() {
|
|
282
225
|
return {
|
|
283
226
|
ino: this.ino,
|
|
284
227
|
uid: this.uid,
|
|
@@ -292,58 +235,49 @@ var Node = /** @class */ (function (_super) {
|
|
|
292
235
|
symlink: this.symlink,
|
|
293
236
|
data: this.getString(),
|
|
294
237
|
};
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
}(events_1.EventEmitter));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
298
240
|
exports.Node = Node;
|
|
299
241
|
/**
|
|
300
242
|
* Represents a hard link that points to an i-node `node`.
|
|
301
243
|
*/
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
244
|
+
class Link extends events_1.EventEmitter {
|
|
245
|
+
get steps() {
|
|
246
|
+
return this._steps;
|
|
247
|
+
}
|
|
248
|
+
// Recursively sync children steps, e.g. in case of dir rename
|
|
249
|
+
set steps(val) {
|
|
250
|
+
this._steps = val;
|
|
251
|
+
for (const [child, link] of Object.entries(this.children)) {
|
|
252
|
+
if (child === '.' || child === '..') {
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
link === null || link === void 0 ? void 0 : link.syncSteps();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
constructor(vol, parent, name) {
|
|
259
|
+
super();
|
|
260
|
+
this.children = {};
|
|
307
261
|
// Path to this node as Array: ['usr', 'bin', 'node'].
|
|
308
|
-
|
|
262
|
+
this._steps = [];
|
|
309
263
|
// "i-node" number of the node.
|
|
310
|
-
|
|
264
|
+
this.ino = 0;
|
|
311
265
|
// Number of children.
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
Object.defineProperty(Link.prototype, "steps", {
|
|
320
|
-
get: function () {
|
|
321
|
-
return this._steps;
|
|
322
|
-
},
|
|
323
|
-
// Recursively sync children steps, e.g. in case of dir rename
|
|
324
|
-
set: function (val) {
|
|
325
|
-
this._steps = val;
|
|
326
|
-
for (var _i = 0, _a = Object.entries(this.children); _i < _a.length; _i++) {
|
|
327
|
-
var _b = _a[_i], child = _b[0], link = _b[1];
|
|
328
|
-
if (child === '.' || child === '..') {
|
|
329
|
-
continue;
|
|
330
|
-
}
|
|
331
|
-
link === null || link === void 0 ? void 0 : link.syncSteps();
|
|
332
|
-
}
|
|
333
|
-
},
|
|
334
|
-
enumerable: false,
|
|
335
|
-
configurable: true
|
|
336
|
-
});
|
|
337
|
-
Link.prototype.setNode = function (node) {
|
|
266
|
+
this.length = 0;
|
|
267
|
+
this.vol = vol;
|
|
268
|
+
this.parent = parent;
|
|
269
|
+
this.name = name;
|
|
270
|
+
this.syncSteps();
|
|
271
|
+
}
|
|
272
|
+
setNode(node) {
|
|
338
273
|
this.node = node;
|
|
339
274
|
this.ino = node.ino;
|
|
340
|
-
}
|
|
341
|
-
|
|
275
|
+
}
|
|
276
|
+
getNode() {
|
|
342
277
|
return this.node;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
var link = new Link(this.vol, this, name);
|
|
278
|
+
}
|
|
279
|
+
createChild(name, node = this.vol.createNode()) {
|
|
280
|
+
const link = new Link(this.vol, this, name);
|
|
347
281
|
link.setNode(node);
|
|
348
282
|
if (node.isDirectory()) {
|
|
349
283
|
link.children['.'] = link;
|
|
@@ -351,13 +285,12 @@ var Link = /** @class */ (function (_super) {
|
|
|
351
285
|
}
|
|
352
286
|
this.setChild(name, link);
|
|
353
287
|
return link;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
if (link === void 0) { link = new Link(this.vol, this, name); }
|
|
288
|
+
}
|
|
289
|
+
setChild(name, link = new Link(this.vol, this, name)) {
|
|
357
290
|
this.children[name] = link;
|
|
358
291
|
link.parent = this;
|
|
359
292
|
this.length++;
|
|
360
|
-
|
|
293
|
+
const node = link.getNode();
|
|
361
294
|
if (node.isDirectory()) {
|
|
362
295
|
link.children['..'] = this;
|
|
363
296
|
this.getNode().nlink++;
|
|
@@ -365,9 +298,9 @@ var Link = /** @class */ (function (_super) {
|
|
|
365
298
|
this.getNode().mtime = new Date();
|
|
366
299
|
this.emit('child:add', link, this);
|
|
367
300
|
return link;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
|
|
301
|
+
}
|
|
302
|
+
deleteChild(link) {
|
|
303
|
+
const node = link.getNode();
|
|
371
304
|
if (node.isDirectory()) {
|
|
372
305
|
delete link.children['..'];
|
|
373
306
|
this.getNode().nlink--;
|
|
@@ -376,19 +309,19 @@ var Link = /** @class */ (function (_super) {
|
|
|
376
309
|
this.length--;
|
|
377
310
|
this.getNode().mtime = new Date();
|
|
378
311
|
this.emit('child:delete', link, this);
|
|
379
|
-
}
|
|
380
|
-
|
|
312
|
+
}
|
|
313
|
+
getChild(name) {
|
|
381
314
|
this.getNode().mtime = new Date();
|
|
382
315
|
if (Object.hasOwnProperty.call(this.children, name)) {
|
|
383
316
|
return this.children[name];
|
|
384
317
|
}
|
|
385
|
-
}
|
|
386
|
-
|
|
318
|
+
}
|
|
319
|
+
getPath() {
|
|
387
320
|
return this.steps.join(exports.SEP);
|
|
388
|
-
}
|
|
389
|
-
|
|
321
|
+
}
|
|
322
|
+
getName() {
|
|
390
323
|
return this.steps[this.steps.length - 1];
|
|
391
|
-
}
|
|
324
|
+
}
|
|
392
325
|
// del() {
|
|
393
326
|
// const parent = this.parent;
|
|
394
327
|
// if(parent) {
|
|
@@ -405,36 +338,33 @@ var Link = /** @class */ (function (_super) {
|
|
|
405
338
|
*
|
|
406
339
|
* @return {Link|null}
|
|
407
340
|
*/
|
|
408
|
-
|
|
409
|
-
if (stop === void 0) { stop = steps.length; }
|
|
410
|
-
if (i === void 0) { i = 0; }
|
|
341
|
+
walk(steps, stop = steps.length, i = 0) {
|
|
411
342
|
if (i >= steps.length)
|
|
412
343
|
return this;
|
|
413
344
|
if (i >= stop)
|
|
414
345
|
return this;
|
|
415
|
-
|
|
416
|
-
|
|
346
|
+
const step = steps[i];
|
|
347
|
+
const link = this.getChild(step);
|
|
417
348
|
if (!link)
|
|
418
349
|
return null;
|
|
419
350
|
return link.walk(steps, stop, i + 1);
|
|
420
|
-
}
|
|
421
|
-
|
|
351
|
+
}
|
|
352
|
+
toJSON() {
|
|
422
353
|
return {
|
|
423
354
|
steps: this.steps,
|
|
424
355
|
ino: this.ino,
|
|
425
356
|
children: Object.keys(this.children),
|
|
426
357
|
};
|
|
427
|
-
}
|
|
428
|
-
|
|
358
|
+
}
|
|
359
|
+
syncSteps() {
|
|
429
360
|
this.steps = this.parent ? this.parent.steps.concat([this.name]) : [this.name];
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
}(events_1.EventEmitter));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
433
363
|
exports.Link = Link;
|
|
434
364
|
/**
|
|
435
365
|
* Represents an open file (file descriptor) that points to a `Link` (Hard-link) and a `Node`.
|
|
436
366
|
*/
|
|
437
|
-
|
|
367
|
+
class File {
|
|
438
368
|
/**
|
|
439
369
|
* Open a Link-Node pair. `node` is provided separately as that might be a different node
|
|
440
370
|
* rather the one `link` points to, because it might be a symlink.
|
|
@@ -443,68 +373,58 @@ var File = /** @class */ (function () {
|
|
|
443
373
|
* @param flags
|
|
444
374
|
* @param fd
|
|
445
375
|
*/
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* A cursor/offset position in a file, where data will be written on write.
|
|
449
|
-
* User can "seek" this position.
|
|
450
|
-
*/
|
|
451
|
-
this.position = 0;
|
|
376
|
+
constructor(link, node, flags, fd) {
|
|
452
377
|
this.link = link;
|
|
453
378
|
this.node = node;
|
|
454
379
|
this.flags = flags;
|
|
455
380
|
this.fd = fd;
|
|
381
|
+
this.position = 0;
|
|
382
|
+
if (this.flags & O_APPEND)
|
|
383
|
+
this.position = this.getSize();
|
|
456
384
|
}
|
|
457
|
-
|
|
458
|
-
if (encoding === void 0) { encoding = 'utf8'; }
|
|
385
|
+
getString(encoding = 'utf8') {
|
|
459
386
|
return this.node.getString();
|
|
460
|
-
}
|
|
461
|
-
|
|
387
|
+
}
|
|
388
|
+
setString(str) {
|
|
462
389
|
this.node.setString(str);
|
|
463
|
-
}
|
|
464
|
-
|
|
390
|
+
}
|
|
391
|
+
getBuffer() {
|
|
465
392
|
return this.node.getBuffer();
|
|
466
|
-
}
|
|
467
|
-
|
|
393
|
+
}
|
|
394
|
+
setBuffer(buf) {
|
|
468
395
|
this.node.setBuffer(buf);
|
|
469
|
-
}
|
|
470
|
-
|
|
396
|
+
}
|
|
397
|
+
getSize() {
|
|
471
398
|
return this.node.getSize();
|
|
472
|
-
}
|
|
473
|
-
|
|
399
|
+
}
|
|
400
|
+
truncate(len) {
|
|
474
401
|
this.node.truncate(len);
|
|
475
|
-
}
|
|
476
|
-
|
|
402
|
+
}
|
|
403
|
+
seekTo(position) {
|
|
477
404
|
this.position = position;
|
|
478
|
-
}
|
|
479
|
-
|
|
405
|
+
}
|
|
406
|
+
stats() {
|
|
480
407
|
return Stats_1.default.build(this.node);
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
if (offset === void 0) { offset = 0; }
|
|
484
|
-
if (length === void 0) { length = buf.length; }
|
|
408
|
+
}
|
|
409
|
+
write(buf, offset = 0, length = buf.length, position) {
|
|
485
410
|
if (typeof position !== 'number')
|
|
486
411
|
position = this.position;
|
|
487
|
-
|
|
488
|
-
position = this.getSize();
|
|
489
|
-
var bytes = this.node.write(buf, offset, length, position);
|
|
412
|
+
const bytes = this.node.write(buf, offset, length, position);
|
|
490
413
|
this.position = position + bytes;
|
|
491
414
|
return bytes;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
if (offset === void 0) { offset = 0; }
|
|
495
|
-
if (length === void 0) { length = buf.byteLength; }
|
|
415
|
+
}
|
|
416
|
+
read(buf, offset = 0, length = buf.byteLength, position) {
|
|
496
417
|
if (typeof position !== 'number')
|
|
497
418
|
position = this.position;
|
|
498
|
-
|
|
419
|
+
const bytes = this.node.read(buf, offset, length, position);
|
|
499
420
|
this.position = position + bytes;
|
|
500
421
|
return bytes;
|
|
501
|
-
}
|
|
502
|
-
|
|
422
|
+
}
|
|
423
|
+
chmod(perm) {
|
|
503
424
|
this.node.chmod(perm);
|
|
504
|
-
}
|
|
505
|
-
|
|
425
|
+
}
|
|
426
|
+
chown(uid, gid) {
|
|
506
427
|
this.node.chown(uid, gid);
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
}());
|
|
428
|
+
}
|
|
429
|
+
}
|
|
510
430
|
exports.File = File;
|