原来的代码如下:
var readable = fs.createReadStream( filepath );
var writable = fs.createWriteStream( outFilepath );
readable.pipe( writable );
doSomeThing();
但是这样的代码会导致在文件没有传输完成的情况下就执行了doSomeThing()
。
改成如下代码:
var readable = fs.createReadStream( filepath );
var writable = fs.createWriteStream( outFilepath );
readable.pipe( writable );
readable.on('close', ()=> { doSomeThing(); }) });
就可以了。