BREAKING CHANGE(scope): change and name to @pushrocks/smarthash
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
import * as plugins from "./nodehash.plugins";
|
||||
import * as plugins from './nodehash.plugins';
|
||||
|
||||
export * from "./nodehash.sha256";
|
||||
export * from './nodehash.sha256';
|
||||
|
@@ -1,15 +1,14 @@
|
||||
import * as plugins from "./nodehash.plugins";
|
||||
import * as plugins from './nodehash.plugins';
|
||||
|
||||
export let hashStreamPipeStop = (resolveFuntion) => {
|
||||
let forEach = (chunk:Buffer,enc,cb) => {
|
||||
resolveFuntion(chunk.toString("utf8"));
|
||||
cb(null,chunk);
|
||||
};
|
||||
export let hashStreamPipeStop = resolveFuntion => {
|
||||
let forEach = (chunk: Buffer, enc, cb) => {
|
||||
resolveFuntion(chunk.toString('utf8'));
|
||||
cb(null, chunk);
|
||||
};
|
||||
|
||||
let atEnd = (cb) => {
|
||||
cb();
|
||||
};
|
||||
|
||||
return plugins.through2(forEach,atEnd);
|
||||
let atEnd = cb => {
|
||||
cb();
|
||||
};
|
||||
|
||||
return plugins.through2(forEach, atEnd);
|
||||
};
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import "typings-global";
|
||||
export import crypto = require("crypto");
|
||||
export import fs = require("fs");
|
||||
export import path = require("path");
|
||||
export import q = require("q");
|
||||
export import stream = require("stream");
|
||||
export import through2 = require("through2");
|
||||
export import crypto = require('crypto');
|
||||
export import fs = require('fs');
|
||||
export import path = require('path');
|
||||
export import q = require('@pushrocks/smartpromise');
|
||||
export import stream = require('stream');
|
||||
export import through2 = require('through2');
|
||||
|
@@ -1,51 +1,48 @@
|
||||
import * as plugins from "./nodehash.plugins";
|
||||
import * as helpers from "./nodehash.helpers";
|
||||
import * as plugins from './nodehash.plugins';
|
||||
import * as helpers from './nodehash.helpers';
|
||||
|
||||
/**
|
||||
* creates sha256 Hash from Stream
|
||||
*/
|
||||
export let sha256FromStream = (input) => {
|
||||
let done = plugins.q.defer();
|
||||
let hash = plugins.crypto.createHash('sha256');
|
||||
export let sha256FromStream = (input): Promise<string> => {
|
||||
let done = plugins.q.defer<string>();
|
||||
let hash = plugins.crypto.createHash('sha256');
|
||||
|
||||
hash["setEncoding"]("hex");
|
||||
input
|
||||
.pipe(hash)
|
||||
.pipe(helpers.hashStreamPipeStop(done.resolve));
|
||||
return done.promise;
|
||||
hash['setEncoding']('hex');
|
||||
input.pipe(hash).pipe(helpers.hashStreamPipeStop(done.resolve));
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* creates sha256 Hash from File;
|
||||
*/
|
||||
export let sha256FromFile = (filePath:string) => {
|
||||
let done = plugins.q.defer();
|
||||
let absolutePath = plugins.path.resolve(filePath);
|
||||
let readableStream = plugins.fs.createReadStream(absolutePath);
|
||||
sha256FromStream(readableStream)
|
||||
.then((resultHashString) => {
|
||||
done.resolve(resultHashString);
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
export let sha256FromFile = (filePath: string) => {
|
||||
let done = plugins.q.defer();
|
||||
let absolutePath = plugins.path.resolve(filePath);
|
||||
let readableStream = plugins.fs.createReadStream(absolutePath);
|
||||
sha256FromStream(readableStream).then(resultHashString => {
|
||||
done.resolve(resultHashString);
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* Computes sha256 Hash from String synchronously
|
||||
*/
|
||||
export let sha256FromStringSync = (stringArg) => {
|
||||
let hash = plugins.crypto.createHash('sha256');
|
||||
hash.update(stringArg);
|
||||
return hash.digest("hex");
|
||||
export let sha256FromStringSync = stringArg => {
|
||||
let hash = plugins.crypto.createHash('sha256');
|
||||
hash.update(stringArg);
|
||||
return hash.digest('hex');
|
||||
};
|
||||
|
||||
/**
|
||||
* Computes sha256 Hash from String
|
||||
*/
|
||||
export let 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;
|
||||
};
|
||||
export let 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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user