I am using keccak256 npm module to calculate the hash of an uploaded file. I verify the correctness and I see that the given hash does not correspond to the ones compared on some online hash calculators (such as: this or this or this ).
The code I run is:
const express = require('express');
const fs = require('fs');
const keccak256 = require('keccak256');
const formidable = require('formidable'),
http = require('http'),
util = require('util');
const router = express.Router();
router.get('/', (req, res) => {
res.sendFile('index.html', {root: __dirname })
});
router.post('/upload', (req, res) => {
var form = new formidable.IncomingForm();
form.parse(req, function(err, fields, files) {
res.writeHead(200, {'content-type': 'text/plain'});
res.write('received upload saved in: ' + files.upload.path + '\n\n');
var readStream = fs.createReadStream(files.upload.path);
//res.write(readStream);
console.log(keccak256(readStream).toString('hex'))
res.end("");
});
return;
});
Can anyone kindly explain to me where I am wrong and how I can correct it?