如何存储crypto.createHash('sha1')
(填充后hash.update(buffer)
)的当前状态以在另一个http request
可能发生在 node.js 的不同进程中使用它?
我想象做这样的事情:
var crypto = require('crypto'),
hash = someDatabase.read('hashstate') // continue with filled hash
|| crypto.createHash('sha1'); // start a new hash
// update the hash
someObj.on('data', function(buffer){
hash.update(buffer);
});
someObj.on('end', function(){
// store the current state of hash to retrieve it later (this won't work:)
someDatabase.write('hashstate', hash);
if(theEndOfAllRequests){
// create the result of multiple http requests
hash.digest('hex');
}
});