为什么,何时以及如何关闭写流?

时间:2019-07-01 12:02:36

标签: javascript node.js

这是我的代码

let file = writeFile(filename, destination)

我请求链接并通过管道调用它。

reponse.pipe(file)

我的写功能

 function writeFile(filename, destination) {
   // console.log('ad',dir);
   let num = 1;

   let nm_wo_ext = filename.substr(0, filename.lastIndexOf("."));
   let ext = filename.split(".").pop();
   let jpath = path.join(destination, filename);

   while (fs.existsSync(jpath)) {
     // let f = nm_wo_ext  + '('(num++) +ext
     filename = `${nm_wo_ext} (${num++}).${ext}`;

     jpath = path.join(destination, filename);
     // console.log({jpath});
   }
   // fs.writeFileSync(jpath,data )

   return fs.createWriteStream(jpath);
 }

在这里如何关闭createwritestream?

0 个答案:

没有答案