@zenfs/core 1.11.1 → 1.11.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/dist/backends/cow.js +1 -2
- package/dist/mixins/async.js +2 -5
- package/dist/vfs/promises.js +5 -11
- package/dist/vfs/watchers.js +7 -10
- package/package.json +1 -1
- package/tests/fs/watch.test.ts +7 -2
- package/types/readable-stream.d.ts +1 -0
package/dist/backends/cow.js
CHANGED
|
@@ -458,8 +458,7 @@ export class CopyOnWriteFS extends FileSystem {
|
|
|
458
458
|
return;
|
|
459
459
|
}
|
|
460
460
|
const data = new Uint8Array(stats.size);
|
|
461
|
-
|
|
462
|
-
await readable.read(data);
|
|
461
|
+
await this.readable.read(path, data, 0, stats.size);
|
|
463
462
|
const writable = __addDisposableResource(env_2, await this.writable.createFile(path, 'w', stats.mode, stats), true);
|
|
464
463
|
await writable.write(data);
|
|
465
464
|
}
|
package/dist/mixins/async.js
CHANGED
|
@@ -211,10 +211,9 @@ export function Async(FS) {
|
|
|
211
211
|
if (!stats.isDirectory()) {
|
|
212
212
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
213
213
|
try {
|
|
214
|
-
const asyncFile = __addDisposableResource(env_1, await this.openFile(path, parseFlag('r')), true);
|
|
215
214
|
const syncFile = __addDisposableResource(env_1, this._sync.createFileSync(path, parseFlag('w'), stats.mode, stats), false);
|
|
216
215
|
const buffer = new Uint8Array(stats.size);
|
|
217
|
-
await
|
|
216
|
+
await this.read(path, buffer, 0, stats.size);
|
|
218
217
|
syncFile.writeSync(buffer, 0, stats.size);
|
|
219
218
|
return;
|
|
220
219
|
}
|
|
@@ -223,9 +222,7 @@ export function Async(FS) {
|
|
|
223
222
|
env_1.hasError = true;
|
|
224
223
|
}
|
|
225
224
|
finally {
|
|
226
|
-
|
|
227
|
-
if (result_1)
|
|
228
|
-
await result_1;
|
|
225
|
+
__disposeResources(env_1);
|
|
229
226
|
}
|
|
230
227
|
}
|
|
231
228
|
if (path !== '/') {
|
package/dist/vfs/promises.js
CHANGED
|
@@ -113,9 +113,8 @@ export class FileHandle {
|
|
|
113
113
|
*/
|
|
114
114
|
async truncate(length) {
|
|
115
115
|
length || (length = 0);
|
|
116
|
-
if (length < 0)
|
|
116
|
+
if (length < 0)
|
|
117
117
|
throw new ErrnoError(Errno.EINVAL);
|
|
118
|
-
}
|
|
119
118
|
await this.file.truncate(length);
|
|
120
119
|
this._emitChange();
|
|
121
120
|
}
|
|
@@ -162,11 +161,10 @@ export class FileHandle {
|
|
|
162
161
|
offset = buffer.offset;
|
|
163
162
|
buffer = buffer.buffer;
|
|
164
163
|
}
|
|
165
|
-
|
|
166
|
-
position = this.file.position;
|
|
167
|
-
}
|
|
164
|
+
const pos = Number.isSafeInteger(position) ? position : this.file.position;
|
|
168
165
|
buffer || (buffer = new Uint8Array((await this.file.stat()).size));
|
|
169
|
-
|
|
166
|
+
offset !== null && offset !== void 0 ? offset : (offset = 0);
|
|
167
|
+
return this.file.read(buffer, offset, length !== null && length !== void 0 ? length : buffer.byteLength - offset, pos);
|
|
170
168
|
}
|
|
171
169
|
async readFile(_options) {
|
|
172
170
|
const options = normalizeOptions(_options, null, 'r', 0o444);
|
|
@@ -501,11 +499,7 @@ export async function writeFile(path, data, _options) {
|
|
|
501
499
|
try {
|
|
502
500
|
const options = normalizeOptions(_options, 'utf8', 'w+', 0o644);
|
|
503
501
|
const handle = __addDisposableResource(env_3, path instanceof FileHandle ? path : await open.call(this, path.toString(), options.flag, options.mode), true);
|
|
504
|
-
const _data = typeof data == 'string'
|
|
505
|
-
? data
|
|
506
|
-
: data instanceof DataView
|
|
507
|
-
? new Uint8Array(data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength))
|
|
508
|
-
: data;
|
|
502
|
+
const _data = typeof data == 'string' ? data : data instanceof DataView ? new Uint8Array(data.buffer, data.byteOffset, data.byteLength) : data;
|
|
509
503
|
if (typeof _data != 'string' && !(_data instanceof Uint8Array)) {
|
|
510
504
|
throw new ErrnoError(Errno.EINVAL, 'The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received ' + typeof data, handle.file.path, 'writeFile');
|
|
511
505
|
}
|
package/dist/vfs/watchers.js
CHANGED
|
@@ -2,7 +2,7 @@ import { EventEmitter } from 'eventemitter3';
|
|
|
2
2
|
import { ErrnoError } from '../internal/error.js';
|
|
3
3
|
import { isStatsEqual } from '../stats.js';
|
|
4
4
|
import { normalizePath } from '../utils.js';
|
|
5
|
-
import { dirname, join, relative } from './path.js';
|
|
5
|
+
import { basename, dirname, join, relative } from './path.js';
|
|
6
6
|
import { statSync } from './sync.js';
|
|
7
7
|
/**
|
|
8
8
|
* Base class for file system watchers.
|
|
@@ -143,16 +143,13 @@ export function emitChange(context, eventType, filename) {
|
|
|
143
143
|
if (context)
|
|
144
144
|
filename = join((_a = context.root) !== null && _a !== void 0 ? _a : '/', filename);
|
|
145
145
|
filename = normalizePath(filename);
|
|
146
|
-
// Notify watchers on parent directories if they are watching recursively
|
|
147
|
-
let
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
parent = dirname(parent);
|
|
151
|
-
const parentWatchers = watchers.get(parent);
|
|
152
|
-
if (!parentWatchers)
|
|
146
|
+
// Notify watchers, including ones on parent directories if they are watching recursively
|
|
147
|
+
for (let path = filename; path != '/'; path = dirname(path)) {
|
|
148
|
+
const watchersForPath = watchers.get(path);
|
|
149
|
+
if (!watchersForPath)
|
|
153
150
|
continue;
|
|
154
|
-
for (const watcher of
|
|
155
|
-
watcher.emit('change', eventType, relative(
|
|
151
|
+
for (const watcher of watchersForPath) {
|
|
152
|
+
watcher.emit('change', eventType, relative(path, filename) || basename(filename));
|
|
156
153
|
}
|
|
157
154
|
}
|
|
158
155
|
}
|
package/package.json
CHANGED
package/tests/fs/watch.test.ts
CHANGED
|
@@ -13,13 +13,18 @@ await fs.promises.writeFile(testFile, 'Initial content');
|
|
|
13
13
|
*/
|
|
14
14
|
await suite('Watch Features', () => {
|
|
15
15
|
test('fs.watch should emit events on file change', async () => {
|
|
16
|
+
const { promise, resolve } = Promise.withResolvers<[string, string]>();
|
|
17
|
+
|
|
16
18
|
using watcher = fs.watch(testFile, (eventType, filename) => {
|
|
17
|
-
|
|
18
|
-
assert.equal(filename, 'test.txt');
|
|
19
|
+
resolve([eventType, filename]);
|
|
19
20
|
});
|
|
20
21
|
|
|
21
22
|
// Modify the file to trigger the event
|
|
22
23
|
await fs.promises.writeFile(testFile, 'Updated content');
|
|
24
|
+
|
|
25
|
+
const [eventType, filename] = await promise;
|
|
26
|
+
assert.equal(eventType, 'change');
|
|
27
|
+
assert.equal(filename, 'test.txt');
|
|
23
28
|
});
|
|
24
29
|
|
|
25
30
|
test('fs.watch should emit events on file rename (delete)', async () => {
|
|
@@ -11,6 +11,7 @@ This allows us to bypass those problems.
|
|
|
11
11
|
Warning: Do not install @types/readable-stream alongside this package!
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
/// <reference types="node" preserve="true" />
|
|
14
15
|
declare module 'readable-stream' {
|
|
15
16
|
import { Readable, Writable } from 'node:stream';
|
|
16
17
|
export { Readable, Writable };
|