I am utilizing nodejs' built-in crypto, zlib, and fs packages to encrypt a sizeable file with the following code:
import fs from 'fs';
import zlib from 'zlib';
import crypto from 'crypto';
const initVect = crypto.randomBytes(16);
const fread = fs.createReadStream('X:/File.mp4');
const fwrite = fs.createWriteStream('X:/File.mp4.enc');
const gzipStream = zlib.createGzip();
const hashedPassword = crypto.createHash('sha256').update('SomePassword').digest();
const cipher = crypto.createCipheriv(
'aes-256-cbc',
hashedPassword,
initVect
);
fread.pipe(gzipStream).pipe(cipher).pipe(fwrite);
However, I am unsure how to implement an encryption progress/status indicator. As encrypting a large file will take considerable time, I wish to display the encryption progress in the console for the user's benefit.
Could anyone provide guidance on achieving this?