richardgirges / express-fileupload

Simple express file upload middleware that wraps around busboy
MIT License
1.52k stars 261 forks source link

Hash algorithm #260

Closed lucasarama closed 3 years ago

lucasarama commented 3 years ago

Hi, I want to create an hash for an other file based on the same algorithm of you. So, how do you produce the md5 (on what is based, name, size... ?)

lucasarama commented 3 years ago

I found the answer, sorry. The hash is based on the file Buffer for create hash like when you upload do that :

createHash(path: string) {
    const data = fs.readFileSync(path); // send a buffer if file exist on path
    return crypto.createHash('md5').update(data).digest('hex'); // return hash on hex format like uploaded files
}