Bun 提供了一个用于递增写入文件的 API。这对于写入大型文件,或长时间写入文件非常有用。 在Documentation Index
Fetch the complete documentation index at: https://bun.zhcndoc.com/llms.txt
Use this file to discover all available pages before exploring further.
BunFile 上调用 .writer() 可以获取一个 FileSink 实例。该实例可用于高效地缓冲数据,并周期性地“刷新”到磁盘。你可以多次写入和刷新。
.write() 方法可以接受字符串或二进制数据。
当内部缓冲区满时,
FileSink 也会自动刷新。你可以通过 highWaterMark 选项配置缓冲区大小。
写入完成后,调用
.end() 来自动刷新缓冲区并关闭文件。
完整文档:FileSink。