Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Nodejs】复制文件并获取进度 #47

Open
AwesomeDevin opened this issue Apr 21, 2021 · 0 comments
Open

【Nodejs】复制文件并获取进度 #47

AwesomeDevin opened this issue Apr 21, 2021 · 0 comments
Labels

Comments

@AwesomeDevin
Copy link
Owner

const fs = require('fs')

const input = 'test.mp4'
var file = fs.createReadStream(input);
var out = fs.createWriteStream('./test1.mp4');

let totalSize = fs.statSync( input ).size  // 通过 fs.statSync 获取文件大小
let curSize = 0

file.on('data',function(chunk){
  curSize += chunk.length
  const percent = (curSize / totalSize * 100)
  out.write(chunk)
  console.log(`读取中,当前进度:${percent}`)
});
file.on('end',function(){
	out.end();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant