Node.js计算md5


title: Node.js计算md5

const crypto = require('crypto');


async function cal_md_file_md5(file_path) {

    const md5 = await new Promise((resolve, reject)=>{
        const stream = fs.createReadStream(file_path);
        const hash = crypto.createHash('md5');

        stream.on('data', chunk => {
            hash.update(chunk, 'utf8');
        });

        stream.on('end', () => {
            const md5 = hash.digest('hex');
            console.log(file_path, md5);
            resolve(md5);
        });
    })
    return md5;
}

本文永久更新地址(欢迎来读留言,写评论):

https://www.v2fy.com/p/2021-08-02-md5-1627900802000