diff --git a/test1/fs/createWriteStream.js b/test1/fs/createWriteStream.js new file mode 100644 index 0000000..49023e3 --- /dev/null +++ b/test1/fs/createWriteStream.js @@ -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() diff --git a/test1/fs.js b/test1/fs/fs.js similarity index 100% rename from test1/fs.js rename to test1/fs/fs.js diff --git a/test1/fs/output.txt b/test1/fs/output.txt new file mode 100644 index 0000000..0f9d399 --- /dev/null +++ b/test1/fs/output.txt @@ -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!