Don't use asmcrypto's streaming API when not necessary

Optimization for Firefox
This commit is contained in:
Daniel Huigens
2018-06-18 12:54:57 +02:00
parent e1a8b17753
commit eb72d4dd63
5 changed files with 37 additions and 23 deletions

View File

@@ -43,10 +43,14 @@ function hashjs_hash(hash) {
function asmcrypto_hash(hash) {
return function(data) {
const hashInstance = new hash();
return stream.transform(data, value => {
hashInstance.process(value);
}, () => hashInstance.finish().result);
if (util.isStream(data)) {
const hashInstance = new hash();
return stream.transform(data, value => {
hashInstance.process(value);
}, () => hashInstance.finish().result);
} else {
return hash.bytes(data);
}
};
}