@@ -0,0 +1,18 @@
|
||||
const fs = require('fs')
|
||||
const writeStream = fs.createWriteStream('./output.txt')
|
||||
writeStream.write('hello world!')
|
||||
writeStream.write('hello world!\n')
|
||||
writeStream.write('hello world!\n')
|
||||
writeStream.write('hello world!\n')
|
||||
writeStream.write('hello world!\n')
|
||||
writeStream.write('hello world!\n')
|
||||
writeStream.write('hello world!\n')
|
||||
writeStream.write('hello world!\n')
|
||||
writeStream.write('hello world!\n')
|
||||
writeStream.write('hello world!\n')
|
||||
writeStream.write('hello world!\n')
|
||||
writeStream.write('hello world!\n')
|
||||
// end(): 等待缓冲区数据全部写完后再关闭流,触发 finish 事件,再触发 close 事件
|
||||
writeStream.end()
|
||||
// close(): 直接关闭流并释放资源,不会等待缓冲区数据写完,可能丢失未写入的数据
|
||||
writeStream.close()
|
||||
@@ -0,0 +1,11 @@
|
||||
hello world!hello world!
|
||||
hello world!
|
||||
hello world!
|
||||
hello world!
|
||||
hello world!
|
||||
hello world!
|
||||
hello world!
|
||||
hello world!
|
||||
hello world!
|
||||
hello world!
|
||||
hello world!
|
||||
Reference in New Issue
Block a user