stream.finished(stream[, options])
-
stream
<Stream> -
options
<Object>-
error
<boolean> | <undefined> -
readable
<boolean> | <undefined> -
writable
<boolean> | <undefined> -
signal
:<AbortSignal> | <undefined>
-
-
返回:<Promise> 当流不再可读或可写时执行。
¥Returns: <Promise> Fulfills when the stream is no longer readable or writable.
const { finished } = require('node:stream/promises');
const fs = require('node:fs');
const rs = fs.createReadStream('archive.tar');
async function run() {
await finished(rs);
console.log('Stream is done reading.');
}
run().catch(console.error);
rs.resume(); // Drain the stream.
import { finished } from 'node:stream/promises';
import { createReadStream } from 'node:fs';
const rs = createReadStream('archive.tar');
async function run() {
await finished(rs);
console.log('Stream is done reading.');
}
run().catch(console.error);
rs.resume(); // Drain the stream.
finished
API 还提供了 回调版本。
¥The finished
API also provides a callback version.