我正在使用 keccak256 npm 模块来计算上传文件的哈希值。我验证了正确性,我发现给定的哈希与某些在线哈希计算器上比较的哈希不对应(例如:this或this或this)。
我运行的代码是:
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;
});
任何人都可以向我解释我错在哪里以及如何纠正它?