Можно сделать что-нибудь в таком роде:
const stream = require('stream');
const fs = require('fs');
class PercentWatcher extends stream.Duplex {
constructor(fd) {
super();
this.size = fs.fstatSync(fd).size;
this.handled = 0;
}
_read() {}
_write(chunk, encoding, callback) {
this.push(chunk);
this.handled += chunk.length;
console.log(`\n\n${Math.round(this.handled / this.size * 100)}%\n\n`);
callback();
}
}
const fd = fs.openSync('file.txt', 'r');
fs.createReadStream(null, {fd}).pipe(new PercentWatcher(fd)).pipe(process.stdout);