Skip to main content

2 posts tagged with "stream"

View All Tags

· One min read
Alan

Node.js 的流调用 pipe 方法之后会返回一个新的流, 监听这个新流的finish事件就可以知道pipe完成了:

axios({
method: "GET",
url: "https://www.bilibili.com/",
responseType: "stream"
}).then((response: AxiosResponse<Stream>) => {
const newStream = response.data.pipe(fs.createWriteStream(`./save-file.html`));
newStream.on("finish", () => {
// 这里流pipe已经完成
});
});