Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use faster xxhash implementaion #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
118 changes: 105 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
"src"
],
"engines": {
"node": ">=10"
"node": ">=10.20"
},
"dependencies": {
"@node-rs/xxhash": "~1.0.0",
"make-dir": "~3.1.0",
"mime": "~2.5.2",
"minimatch": "~3.0.4",
"xxhashjs": "~0.2.2"
"minimatch": "~3.0.4"
},
"devDependencies": {
"chai": "4.1.2",
Expand Down
10 changes: 3 additions & 7 deletions src/lib/hash.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const crypto = require('crypto');
const xxh = require('xxhashjs');
const { xxh32, xxh64 } = require('@node-rs/xxhash');
const HEXBASE = 16;

const defaultHashOptions = {
Expand All @@ -11,13 +11,9 @@ const defaultHashOptions = {
};

const getxxhash = (content, options) => {
const hashFunc = options.method === 'xxhash32' ? xxh.h32 : xxh.h64;
const seed = 0;
const hashFunc = options.method === 'xxhash32' ? xxh32 : xxh64;

return hashFunc(seed)
.update(content)
.digest()
.toString(HEXBASE);
return hashFunc(content).toString(HEXBASE);
};

const getHash = (content, options) => {
Expand Down