Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

asset-hash

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asset-hash - npm Package Compare versions

Comparing version 2.0.0 to 2.1.1

59

lib/index.cjs.js

@@ -1,2 +0,2 @@

/*! asset-hash v2.0.0 by Sebastian Werner <s.werner@sebastian-software.de> */
/*! asset-hash v2.1.1 by Sebastian Werner <s.werner@sebastian-software.de> */
'use strict';

@@ -15,9 +15,11 @@

var BigInt = _interopDefault(require('big.js'));
var XXHash = require('xxhash');
var XXHash__default = _interopDefault(XXHash);
var HashThrough = _interopDefault(require('hash-through'));
var metrohash = require('metrohash');
var XXHash32 = require('xxhash');
var XXHash32__default = _interopDefault(XXHash32);
var DEFAULT_HASH = "xxhash",
DEFAULT_ENCODING = "base52",
DEFAULT_MAX_LENGTH = 16,
XXHASH_CONSTRUCT = 0xCAFEBABE,
var DEFAULT_HASH = "metrohash128",
DEFAULT_ENCODING = "hex",
DEFAULT_MAX_LENGTH = 8,
XXHASH_CONSTRUCT = 0xcafebabe,
baseEncodeTables = {

@@ -41,7 +43,7 @@ 26: "abcdefghijklmnopqrstuvwxyz",

var readLength = buffer.length;
var length = buffer.length;
BigInt.DP = 0;
BigInt.RM = 0;
for (var current = new BigInt(0), i = readLength - 1; i >= 0; i--) {
for (var current = new BigInt(0), i = length - 1; i >= 0; i--) {
current = current.times(256).plus(buffer[i]);

@@ -62,12 +64,19 @@ }

function computeDigest(buffer, _temp) {
function computeDigest(bufferOrString, _temp) {
var _ref = _temp === void 0 ? {} : _temp,
encoding = _ref.encoding,
maxLength = _ref.maxLength,
output = "";
output = "",
isString = typeof bufferOrString == "string";
if (encoding === "hex" || encoding === "base64" || encoding === "utf8") {
output = buffer.toString(encoding);
if (isString && encoding === "hex") {
output = bufferOrString;
} else {
output = baseEncode(buffer, encoding);
var buffer = isString ? Buffer.from(bufferOrString, "hex") : bufferOrString;
if (encoding === "hex" || encoding === "base64" || encoding === "utf8") {
output = buffer.toString(encoding);
} else {
output = baseEncode(buffer, encoding);
}
}

@@ -108,6 +117,22 @@

function createHasher(hash) {
return hash === "xxhash" ? new XXHash__default(XXHASH_CONSTRUCT) : crypto.createHash(hash);
var hasher;
if (hash === "xxhash32") {
hasher = new XXHash32__default(XXHASH_CONSTRUCT);
} else if (hash === "xxhash64") {
hasher = new XXHash32.XXHash64(XXHASH_CONSTRUCT);
} else if (hash === "metrohash64") {
hasher = new metrohash.MetroHash64();
} else if (hash === "metrohash128") {
hasher = new metrohash.MetroHash128();
} else {
hasher = crypto.createHash(hash);
}
return hasher;
}
function createStreamingHasher(hash) {
return hash === "xxhash" ? new XXHash.Stream(XXHASH_CONSTRUCT, "buffer") : crypto.createHash(hash);
return HashThrough(function () {
return createHasher(hash);
});
}

@@ -128,3 +153,3 @@ function getHash(fileName, _temp2) {

try {
var digest = computeDigest(hasher.read(), {
var digest = computeDigest(hasher.digest("buffer"), {
encoding: encoding,

@@ -131,0 +156,0 @@ maxLength: maxLength

@@ -1,2 +0,2 @@

/*! asset-hash v2.0.0 by Sebastian Werner <s.werner@sebastian-software.de> */
/*! asset-hash v2.1.1 by Sebastian Werner <s.werner@sebastian-software.de> */
import 'core-js/modules/es6.promise';

@@ -9,8 +9,10 @@ import 'core-js/modules/es6.regexp.to-string';

import BigInt from 'big.js';
import XXHash, { Stream } from 'xxhash';
import HashThrough from 'hash-through';
import { MetroHash128, MetroHash64 } from 'metrohash';
import XXHash32, { XXHash64 } from 'xxhash';
var DEFAULT_HASH = "xxhash",
DEFAULT_ENCODING = "base52",
DEFAULT_MAX_LENGTH = 16,
XXHASH_CONSTRUCT = 0xCAFEBABE,
var DEFAULT_HASH = "metrohash128",
DEFAULT_ENCODING = "hex",
DEFAULT_MAX_LENGTH = 8,
XXHASH_CONSTRUCT = 0xcafebabe,
baseEncodeTables = {

@@ -34,7 +36,7 @@ 26: "abcdefghijklmnopqrstuvwxyz",

var readLength = buffer.length;
var length = buffer.length;
BigInt.DP = 0;
BigInt.RM = 0;
for (var current = new BigInt(0), i = readLength - 1; i >= 0; i--) {
for (var current = new BigInt(0), i = length - 1; i >= 0; i--) {
current = current.times(256).plus(buffer[i]);

@@ -55,12 +57,19 @@ }

function computeDigest(buffer, _temp) {
function computeDigest(bufferOrString, _temp) {
var _ref = _temp === void 0 ? {} : _temp,
encoding = _ref.encoding,
maxLength = _ref.maxLength,
output = "";
output = "",
isString = typeof bufferOrString == "string";
if (encoding === "hex" || encoding === "base64" || encoding === "utf8") {
output = buffer.toString(encoding);
if (isString && encoding === "hex") {
output = bufferOrString;
} else {
output = baseEncode(buffer, encoding);
var buffer = isString ? Buffer.from(bufferOrString, "hex") : bufferOrString;
if (encoding === "hex" || encoding === "base64" || encoding === "utf8") {
output = buffer.toString(encoding);
} else {
output = baseEncode(buffer, encoding);
}
}

@@ -101,6 +110,22 @@

function createHasher(hash) {
return hash === "xxhash" ? new XXHash(XXHASH_CONSTRUCT) : createHash(hash);
var hasher;
if (hash === "xxhash32") {
hasher = new XXHash32(XXHASH_CONSTRUCT);
} else if (hash === "xxhash64") {
hasher = new XXHash64(XXHASH_CONSTRUCT);
} else if (hash === "metrohash64") {
hasher = new MetroHash64();
} else if (hash === "metrohash128") {
hasher = new MetroHash128();
} else {
hasher = createHash(hash);
}
return hasher;
}
function createStreamingHasher(hash) {
return hash === "xxhash" ? new Stream(XXHASH_CONSTRUCT, "buffer") : createHash(hash);
return HashThrough(function () {
return createHasher(hash);
});
}

@@ -121,3 +146,3 @@ function getHash(fileName, _temp2) {

try {
var digest = computeDigest(hasher.read(), {
var digest = computeDigest(hasher.digest("buffer"), {
encoding: encoding,

@@ -124,0 +149,0 @@ maxLength: maxLength

{
"name": "asset-hash",
"version": "2.0.0",
"version": "2.1.1",
"description": "Very fast asset hashing function for using e.g. during front-end deployments.",

@@ -40,7 +40,7 @@ "main": "lib/index.cjs.js",

"babel-jest": "^23.4.0",
"babel-preset-edge": "^4.9.0",
"babel-preset-edge": "^4.9.1",
"eslint": "^5.1.0",
"eslint-config-readable": "^2.1.3",
"flow-bin": "^0.76.0",
"jest": "^23.4.0",
"jest": "^23.4.1",
"preppy": "^4.2.3",

@@ -53,4 +53,6 @@ "prettier": "^1.13.7"

"core-js": "^2.5.7",
"hash-through": "^0.1.16",
"metrohash": "^2.4.1",
"xxhash": "^0.2.4"
}
}

@@ -31,2 +31,8 @@ # _Asset Hash_ <br/>[![Sponsored by][sponsor-img]][sponsor] [![Version][npm-version-img]][npm] [![Downloads][npm-downloads-img]][npm] [![Build Status Unix][travis-img]][travis] [![Build Status Windows][appveyor-img]][appveyor] [![Dependencies][deps-img]][deps]

## Speed
For speed comparisons of different algorithms we created a small repository containing the source code and some results. [Check it out](https://github.com/sebastian-software/node-hash-comparison). TLDR: Modern non-cryptographic hashing could be way faster than cryptographic solutions like MD5 or SHA1. Best algorithm right now for our use cases seems to be MetroHash128. This is why we made it the default.
## Usage

@@ -38,3 +44,4 @@

- `encoding`:
- `encoding`: Any valid encoding for built-in digests `hex`, `base64`, `base62`, ...
- `maxLength`: Maximum length of returned digest. Keep in mind that this increases collison probability.

@@ -41,0 +48,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc