美文网首页
nodejs copy视频到当前目录(stream)

nodejs copy视频到当前目录(stream)

作者: 撸猫真君 | 来源:发表于2017-07-10 10:39 被阅读688次

方法一:

var fs=require('fs');

var readStream=fs.createReadStream('1.mp4');

var writeStream=fs.createWriteStream('1-stream.mp4');

readStream.on('data',function(chunk){

if( writeStream.write(chunk) ===false ){

console.log('still cached');

readStream.pause();

}

})

readStream.on('end',function(){

writeStream.end();

})

writeStream.on('drain',function(){

console.log('data drains');

readStream.resume();

})

方法二(pipe|管道):

var fs= require('fs');

fs.createReadStream('1.mp4').pipe(fs.createWriteStream('1-pipe.mp4'));

相关文章

网友评论

      本文标题:nodejs copy视频到当前目录(stream)

      本文链接:https://www.haomeiwen.com/subject/qfsyhxtx.html