let fs = require(‘fs‘);
// 创建读取流 fs.createReadStream(路径【配置项】)
// let rs = fs.createReadStream(‘hello.txt‘,{flag:"r",encoding:"utf-8"});
let rs = fs.createReadStream(‘1.mp4‘,{flag:"r"});
// 创建写入流
let ws = fs.createWriteStream(‘a.mp4‘)
// console.log(rs);
rs.on(‘open‘,function(){
console.log(‘读取的文件已打开‘);
})
rs.on(‘close‘,function(){
ws.end(function(){
console.log(‘文件写入完成关闭‘);
})
console.log(‘读取流结束‘);
})
// 每一批数据流入完成
rs.on(‘data‘,function(chunk){
console.log(‘单批数据流入‘,chunk.length);
console.log(chunk);
ws.write(chunk,()=>{
console.log(‘单批数据流入完成‘);
})
})
---------------------2 ----------------------------
let fs = require(‘fs‘);
// 创建读取流 fs.createReadStream(路径【配置项】)
let rs = fs.createReadStream(‘1.mp4‘,{flag:"r"});
// 创建写入流
let ws = fs.createWriteStream(‘b.mp4‘)
// console.log(rs);
rs.on(‘open‘,function(){
console.log(‘读取的文件已打开‘);
})
rs.on(‘close‘,function(){
console.log(‘读取流结束‘);
})
// 从 读到写 自动完成
rs.pipe(ws)