writable.end([chunk[, encoding]][, callback])
-
chunk<string> | <Buffer> | <TypedArray> | <DataView> | <any> 可选的要写入的数据。对于不以对象模式运行的流,chunk必须是 <string>、<Buffer>、<TypedArray> 或 <DataView>。对于对象模式的流,chunk可以是除null之外的任何 JavaScript 值。¥
chunk<string> | <Buffer> | <TypedArray> | <DataView> | <any> Optional data to write. For streams not operating in object mode,chunkmust be a <string>, <Buffer>, <TypedArray> or <DataView>. For object mode streams,chunkmay be any JavaScript value other thannull. -
encoding<string>chunk为字符串时的编码¥
encoding<string> The encoding ifchunkis a string -
callback<Function> 流结束时的回调。¥
callback<Function> Callback for when the stream is finished. -
返回:<this>
¥Returns: <this>
调用 writable.end() 方法表示不再有数据写入 Writable。可选的 chunk 和 encoding 参数允许在关闭流之前立即写入最后一个额外的数据块。
¥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!