writable.end([chunk[, encoding]][, callback])


版本历史
版本变更
v22.0.0

chunk 参数现在可以是 TypedArrayDataView 实例。

v15.0.0

callback 在 'finish' 之前或出错时被调用。

v14.0.0

如果触发 'finish' 或 'error',则调用 callback

v10.0.0

此方法现在返回对 writable 的引用。

v8.0.0

参数 chunk 现在可以是 Uint8Array 实例。

v0.9.4

新增于: v0.9.4

调用 writable.end() 方法表示不再有数据写入 Writable。可选的 chunkencoding 参数允许在关闭流之前立即写入最后一个额外的数据块。

\Calling the writable.end() method signals that no more data will be written to the Writable. The optional chunk and encoding arguments allow one final additional chunk of data to be written immediately before closing the stream.

在调用 stream.end() 之后调用 stream.write() 方法将引发错误。

\Calling the stream.write() method after calling stream.end() will raise an error.

// Write 'hello, ' and then end with 'world!'.
const fs = require('node:fs');
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed! 

AltStyle によって変換されたページ (->オリジナル) /