From b47cb98c6ff1e8d5b5fc5b4f7bcb6279379bce3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E9=93=B6=E5=86=9B?= Date: Sat, 29 Aug 2026 23:37:43 +0800 Subject: [PATCH] 111 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈银军 --- test1/fs/createWriteStream.js | 18 ++++++++++++++++++ test1/{ => fs}/fs.js | 0 test1/fs/output.txt | 11 +++++++++++ 3 files changed, 29 insertions(+) create mode 100644 test1/fs/createWriteStream.js rename test1/{ => fs}/fs.js (100%) create mode 100644 test1/fs/output.txt 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!