48 lines
3.3 KiB
JavaScript
48 lines
3.3 KiB
JavaScript
|
"use strict";
|
||
|
const plugins = require("./nodehash.plugins");
|
||
|
const helpers = require("./nodehash.helpers");
|
||
|
/**
|
||
|
* creates sha256 Hash from Stream
|
||
|
*/
|
||
|
exports.sha256FromStream = (input) => {
|
||
|
let done = plugins.q.defer();
|
||
|
let hash = plugins.crypto.createHash('sha256');
|
||
|
hash["setEncoding"]("hex");
|
||
|
input
|
||
|
.pipe(hash)
|
||
|
.pipe(helpers.hashStreamPipeStop(done.resolve));
|
||
|
return done.promise;
|
||
|
};
|
||
|
/**
|
||
|
* creates sha256 Hash from File;
|
||
|
*/
|
||
|
exports.sha256FromFile = (filePath) => {
|
||
|
let done = plugins.q.defer();
|
||
|
let absolutePath = plugins.path.resolve(filePath);
|
||
|
let readableStream = plugins.fs.createReadStream(absolutePath);
|
||
|
exports.sha256FromStream(readableStream)
|
||
|
.then((resultHashString) => {
|
||
|
done.resolve(resultHashString);
|
||
|
});
|
||
|
return done.promise;
|
||
|
};
|
||
|
/**
|
||
|
* Computes sha256 Hash from String synchronously
|
||
|
*/
|
||
|
exports.sha256FromStringSync = (stringArg) => {
|
||
|
let hash = plugins.crypto.createHash('sha256');
|
||
|
hash.update(stringArg);
|
||
|
return hash.digest("hex");
|
||
|
};
|
||
|
/**
|
||
|
* Computes sha256 Hash from String
|
||
|
*/
|
||
|
exports.sha256FromString = (stringArg) => {
|
||
|
let done = plugins.q.defer();
|
||
|
let hash = plugins.crypto.createHash('sha256');
|
||
|
hash.update(stringArg);
|
||
|
let hashResult = hash.digest("hex");
|
||
|
done.resolve(hashResult);
|
||
|
return done.promise;
|
||
|
};
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm9kZWhhc2guc2hhMjU2LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbm9kZWhhc2guc2hhMjU2LnRzIl0sIm5hbWVzIjpbXSwibWFw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