Skip to content

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

Open
@AwesomeDevin

Description

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();
})

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions