mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
Enable node:vfs by default. --no-experimental-vfs disables node:vfs exposure and --vfs-load. Assisted-by: pi Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: https://github.com/nodejs/node/pull/66318 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
41 lines
1012 B
JavaScript
41 lines
1012 B
JavaScript
// Flags: --disable-warning=ExperimentalWarning
|
|
'use strict';
|
|
|
|
// VFS streams must expose bytesRead, bytesWritten, and pending.
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const vfs = require('node:vfs');
|
|
|
|
// ReadStream: bytesRead and pending
|
|
{
|
|
const myVfs = vfs.create();
|
|
myVfs.writeFileSync('/stream.txt', 'stream data');
|
|
|
|
const rs = myVfs.createReadStream('/stream.txt');
|
|
assert.strictEqual(rs.pending, true);
|
|
|
|
rs.on('data', common.mustCall(() => {
|
|
assert.strictEqual(rs.pending, false);
|
|
assert.ok(rs.bytesRead > 0);
|
|
}));
|
|
|
|
rs.on('end', common.mustCall());
|
|
}
|
|
|
|
// WriteStream: bytesWritten and pending
|
|
{
|
|
const myVfs = vfs.create();
|
|
myVfs.writeFileSync('/out.txt', '');
|
|
|
|
const ws = myVfs.createWriteStream('/out.txt');
|
|
assert.strictEqual(ws.pending, true);
|
|
assert.strictEqual(ws.bytesWritten, 0);
|
|
|
|
ws.write('hello', common.mustCall(() => {
|
|
assert.strictEqual(ws.pending, false);
|
|
assert.strictEqual(ws.bytesWritten, 5);
|
|
ws.end();
|
|
}));
|
|
}
|