memfs 4.0.0 → 4.1.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/LICENSE +201 -24
- package/README.md +21 -92
- package/lib/Dirent.d.ts +2 -1
- package/lib/__tests__/util.d.ts +13 -0
- package/lib/__tests__/util.js +29 -0
- package/lib/consts/AMODE.d.ts +9 -0
- package/lib/consts/FLAG.d.ts +22 -0
- package/lib/consts/FLAG.js +2 -0
- package/lib/fsa/types.d.ts +3 -3
- package/lib/fsa-to-node/FsaNodeCore.d.ts +32 -0
- package/lib/fsa-to-node/FsaNodeCore.js +168 -0
- package/lib/fsa-to-node/FsaNodeDirent.d.ts +13 -0
- package/lib/fsa-to-node/FsaNodeDirent.js +31 -0
- package/lib/fsa-to-node/FsaNodeFs.d.ts +171 -0
- package/lib/fsa-to-node/FsaNodeFs.js +842 -0
- package/lib/fsa-to-node/FsaNodeFsOpenFile.d.ts +24 -0
- package/lib/fsa-to-node/FsaNodeFsOpenFile.js +46 -0
- package/lib/fsa-to-node/FsaNodeReadStream.d.ts +24 -0
- package/lib/fsa-to-node/FsaNodeReadStream.js +100 -0
- package/lib/fsa-to-node/FsaNodeStats.d.ts +30 -0
- package/lib/fsa-to-node/FsaNodeStats.js +52 -0
- package/lib/fsa-to-node/FsaNodeWriteStream.d.ts +48 -0
- package/lib/fsa-to-node/FsaNodeWriteStream.js +162 -0
- package/lib/fsa-to-node/__tests__/FsaNodeFs.test.d.ts +1 -0
- package/lib/fsa-to-node/__tests__/FsaNodeFs.test.js +873 -0
- package/lib/fsa-to-node/__tests__/util.test.d.ts +1 -0
- package/lib/fsa-to-node/__tests__/util.test.js +28 -0
- package/lib/fsa-to-node/constants.d.ts +3 -0
- package/lib/fsa-to-node/constants.js +2 -0
- package/lib/fsa-to-node/index.d.ts +2 -0
- package/lib/fsa-to-node/index.js +7 -0
- package/lib/fsa-to-node/json.d.ts +4 -0
- package/lib/fsa-to-node/json.js +7 -0
- package/lib/fsa-to-node/types.d.ts +37 -0
- package/lib/fsa-to-node/types.js +2 -0
- package/lib/fsa-to-node/util.d.ts +4 -0
- package/lib/fsa-to-node/util.js +40 -0
- package/lib/fsa-to-node/worker/FsaNodeSyncAdapterWorker.d.ts +10 -0
- package/lib/fsa-to-node/worker/FsaNodeSyncAdapterWorker.js +72 -0
- package/lib/fsa-to-node/worker/FsaNodeSyncWorker.d.ts +20 -0
- package/lib/fsa-to-node/worker/FsaNodeSyncWorker.js +190 -0
- package/lib/fsa-to-node/worker/SyncMessenger.d.ts +24 -0
- package/lib/fsa-to-node/worker/SyncMessenger.js +80 -0
- package/lib/fsa-to-node/worker/constants.d.ts +8 -0
- package/lib/fsa-to-node/worker/constants.js +2 -0
- package/lib/fsa-to-node/worker/types.d.ts +17 -0
- package/lib/fsa-to-node/worker/types.js +2 -0
- package/lib/index.d.ts +5 -4
- package/lib/index.js +1 -1
- package/lib/node/constants.d.ts +41 -0
- package/lib/node/constants.js +56 -0
- package/lib/node/options.d.ts +23 -0
- package/lib/node/options.js +94 -0
- package/lib/node/promises.d.ts +1 -1
- package/lib/node/promises.js +1 -3
- package/lib/node/types/FsCommonObjects.d.ts +17 -0
- package/lib/node/types/FsCommonObjects.js +2 -0
- package/lib/node/types/{sync.d.ts → FsSynchronousApi.d.ts} +36 -37
- package/lib/node/types/FsSynchronousApi.js +2 -0
- package/lib/node/types/callback.d.ts +57 -58
- package/lib/node/types/index.d.ts +1 -1
- package/lib/node/types/misc.d.ts +6 -8
- package/lib/node/types/options.d.ts +20 -6
- package/lib/node/types/promises.d.ts +2 -2
- package/lib/node/util.d.ts +19 -0
- package/lib/node/util.js +265 -1
- package/lib/node-to-fsa/NodeFileSystemDirectoryHandle.d.ts +71 -0
- package/lib/node-to-fsa/NodeFileSystemDirectoryHandle.js +264 -0
- package/lib/node-to-fsa/NodeFileSystemFileHandle.d.ts +28 -0
- package/lib/node-to-fsa/NodeFileSystemFileHandle.js +73 -0
- package/lib/node-to-fsa/NodeFileSystemHandle.d.ts +33 -0
- package/lib/node-to-fsa/NodeFileSystemHandle.js +53 -0
- package/lib/node-to-fsa/NodeFileSystemSyncAccessHandle.d.ts +42 -0
- package/lib/node-to-fsa/NodeFileSystemSyncAccessHandle.js +116 -0
- package/lib/node-to-fsa/NodeFileSystemWritableFileStream.d.ts +54 -0
- package/lib/node-to-fsa/NodeFileSystemWritableFileStream.js +195 -0
- package/lib/node-to-fsa/NodePermissionStatus.d.ts +8 -0
- package/lib/node-to-fsa/NodePermissionStatus.js +13 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemDirectoryHandle.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemDirectoryHandle.test.js +627 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemFileHandle.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemFileHandle.test.js +191 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemHandle.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemHandle.test.js +49 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemSyncAccessHandle.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemSyncAccessHandle.test.js +183 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemWritableFileStream.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemWritableFileStream.test.js +106 -0
- package/lib/node-to-fsa/__tests__/scenarios.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/scenarios.test.js +46 -0
- package/lib/node-to-fsa/__tests__/util.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/util.test.js +25 -0
- package/lib/node-to-fsa/index.d.ts +7 -0
- package/lib/node-to-fsa/index.js +26 -0
- package/lib/node-to-fsa/types.d.ts +12 -0
- package/lib/node-to-fsa/types.js +2 -0
- package/lib/node-to-fsa/util.d.ts +11 -0
- package/lib/node-to-fsa/util.js +33 -0
- package/lib/node.d.ts +1 -1
- package/lib/volume.d.ts +45 -126
- package/lib/volume.js +204 -562
- package/lib/webfs/index.d.ts +1 -0
- package/lib/webfs/index.js +22 -0
- package/package.json +28 -5
- /package/lib/{node/types/sync.js → consts/AMODE.js} +0 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.NodeFileSystemWritableFileStream = exports.createSwapFile = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* When Chrome writes to the file, it creates a copy of the file with extension
|
|
15
|
+
* `.crswap` and then replaces the original file with the copy only when the
|
|
16
|
+
* `close()` method is called. If the `abort()` method is called, the `.crswap`
|
|
17
|
+
* file is deleted.
|
|
18
|
+
*
|
|
19
|
+
* If a file name with with extension `.crswap` is already taken, it
|
|
20
|
+
* creates a new swap file with extension `.1.crswap` and so on.
|
|
21
|
+
*/
|
|
22
|
+
const createSwapFile = (fs, path, keepExistingData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
let handle;
|
|
24
|
+
let swapPath = path + '.crswap';
|
|
25
|
+
try {
|
|
26
|
+
handle = yield fs.promises.open(swapPath, 'ax');
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (!error || typeof error !== 'object' || error.code !== 'EEXIST')
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
if (!handle) {
|
|
33
|
+
for (let i = 1; i < 1000; i++) {
|
|
34
|
+
try {
|
|
35
|
+
swapPath = `${path}.${i}.crswap`;
|
|
36
|
+
handle = yield fs.promises.open(swapPath, 'ax');
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (!error || typeof error !== 'object' || error.code !== 'EEXIST')
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (!handle)
|
|
46
|
+
throw new Error(`Could not create a swap file for "${path}".`);
|
|
47
|
+
if (keepExistingData)
|
|
48
|
+
yield fs.promises.copyFile(path, swapPath, fs.constants.COPYFILE_FICLONE);
|
|
49
|
+
return [handle, swapPath];
|
|
50
|
+
});
|
|
51
|
+
exports.createSwapFile = createSwapFile;
|
|
52
|
+
/**
|
|
53
|
+
* Is a WritableStream object with additional convenience methods, which
|
|
54
|
+
* operates on a single file on disk. The interface is accessed through the
|
|
55
|
+
* `FileSystemFileHandle.createWritable()` method.
|
|
56
|
+
*
|
|
57
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream
|
|
58
|
+
*/
|
|
59
|
+
class NodeFileSystemWritableFileStream extends WritableStream {
|
|
60
|
+
constructor(fs, path, keepExistingData) {
|
|
61
|
+
const swap = { handle: undefined, path: '', offset: 0 };
|
|
62
|
+
super({
|
|
63
|
+
start() {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const promise = (0, exports.createSwapFile)(fs, path, keepExistingData);
|
|
66
|
+
swap.ready = promise.then(() => undefined);
|
|
67
|
+
const [handle, swapPath] = yield promise;
|
|
68
|
+
swap.handle = handle;
|
|
69
|
+
swap.path = swapPath;
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
write(chunk) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
yield swap.ready;
|
|
75
|
+
const handle = swap.handle;
|
|
76
|
+
if (!handle)
|
|
77
|
+
throw new Error('Invalid state');
|
|
78
|
+
const buffer = Buffer.from(typeof chunk === 'string' ? chunk : chunk instanceof Blob ? yield chunk.arrayBuffer() : chunk);
|
|
79
|
+
const { bytesWritten } = yield handle.write(buffer, 0, buffer.length, swap.offset);
|
|
80
|
+
swap.offset += bytesWritten;
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
close() {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
yield swap.ready;
|
|
86
|
+
const handle = swap.handle;
|
|
87
|
+
if (!handle)
|
|
88
|
+
return;
|
|
89
|
+
yield handle.close();
|
|
90
|
+
yield fs.promises.rename(swap.path, path);
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
abort() {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
yield swap.ready;
|
|
96
|
+
const handle = swap.handle;
|
|
97
|
+
if (!handle)
|
|
98
|
+
return;
|
|
99
|
+
yield handle.close();
|
|
100
|
+
yield fs.promises.unlink(swap.path);
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
this.fs = fs;
|
|
105
|
+
this.path = path;
|
|
106
|
+
this.swap = swap;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* @sse https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/seek
|
|
110
|
+
* @param position An `unsigned long` describing the byte position from the top
|
|
111
|
+
* (beginning) of the file.
|
|
112
|
+
*/
|
|
113
|
+
seek(position) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
this.swap.offset = position;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/truncate
|
|
120
|
+
* @param size An `unsigned long` of the amount of bytes to resize the stream to.
|
|
121
|
+
*/
|
|
122
|
+
truncate(size) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
yield this.swap.ready;
|
|
125
|
+
const handle = this.swap.handle;
|
|
126
|
+
if (!handle)
|
|
127
|
+
throw new Error('Invalid state');
|
|
128
|
+
yield handle.truncate(size);
|
|
129
|
+
if (this.swap.offset > size)
|
|
130
|
+
this.swap.offset = size;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
writeBase(chunk) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
const writer = this.getWriter();
|
|
136
|
+
try {
|
|
137
|
+
yield writer.write(chunk);
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
writer.releaseLock();
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
write(params) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
if (!params)
|
|
147
|
+
throw new TypeError('Missing required argument: params');
|
|
148
|
+
switch (typeof params) {
|
|
149
|
+
case 'string': {
|
|
150
|
+
return this.writeBase(params);
|
|
151
|
+
}
|
|
152
|
+
case 'object': {
|
|
153
|
+
const constructor = params.constructor;
|
|
154
|
+
switch (constructor) {
|
|
155
|
+
case ArrayBuffer:
|
|
156
|
+
case Blob:
|
|
157
|
+
case DataView:
|
|
158
|
+
return this.writeBase(params);
|
|
159
|
+
default: {
|
|
160
|
+
if (ArrayBuffer.isView(params)) {
|
|
161
|
+
return this.writeBase(params);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
const options = params;
|
|
165
|
+
switch (options.type) {
|
|
166
|
+
case 'write': {
|
|
167
|
+
if (typeof options.position === 'number')
|
|
168
|
+
yield this.seek(options.position);
|
|
169
|
+
return this.writeBase(params.data);
|
|
170
|
+
}
|
|
171
|
+
case 'truncate': {
|
|
172
|
+
if (typeof params.size !== 'number')
|
|
173
|
+
throw new TypeError('Missing required argument: size');
|
|
174
|
+
if (this.swap.offset > params.size)
|
|
175
|
+
this.swap.offset = params.size;
|
|
176
|
+
return this.truncate(params.size);
|
|
177
|
+
}
|
|
178
|
+
case 'seek':
|
|
179
|
+
if (typeof params.position !== 'number')
|
|
180
|
+
throw new TypeError('Missing required argument: position');
|
|
181
|
+
return this.seek(params.position);
|
|
182
|
+
default:
|
|
183
|
+
throw new TypeError('Invalid argument: params');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
default:
|
|
190
|
+
throw new TypeError('Invalid argument: params');
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.NodeFileSystemWritableFileStream = NodeFileSystemWritableFileStream;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @see [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PermissionStatus)
|
|
3
|
+
*/
|
|
4
|
+
export declare class NodePermissionStatus {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly state: 'granted' | 'denied' | 'prompt';
|
|
7
|
+
constructor(name: string, state: 'granted' | 'denied' | 'prompt');
|
|
8
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodePermissionStatus = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @see [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PermissionStatus)
|
|
6
|
+
*/
|
|
7
|
+
class NodePermissionStatus {
|
|
8
|
+
constructor(name, state) {
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.state = state;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.NodePermissionStatus = NodePermissionStatus;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|