-
-
Notifications
You must be signed in to change notification settings - Fork 35
Use safe-buffer & License, drop Node<4 and md5.js #19
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
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6174e01
safe-buffer
dcousens c66a06d
add MIT LICENSE
dcousens 352e1e8
travis: drop Node <4
dcousens 3fee95a
README: cleanup
dcousens 082b20e
package: bump standard
dcousens d4096c8
md5: re-order for define-before-use
dcousens f612e33
rm safe-buffer dependency, use md5.js and latest ripemd160
dcousens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,32 @@ | ||
'use strict' | ||
var intSize = 4 | ||
var zeroBuffer = new Buffer(intSize) | ||
zeroBuffer.fill(0) | ||
var INT32_SIZE = 4 | ||
var CHAR64_SIZE = 8 | ||
var HASH128_SIZE = 16 | ||
|
||
var charSize = 8 | ||
var hashSize = 16 | ||
var Buffer = require('safe-buffer').Buffer | ||
var zeroBuffer = Buffer.alloc(INT32_SIZE, 0) | ||
|
||
function toArray (buf) { | ||
if ((buf.length % intSize) !== 0) { | ||
var len = buf.length + (intSize - (buf.length % intSize)) | ||
function asUInt32Array (buf) { | ||
if ((buf.length % INT32_SIZE) !== 0) { | ||
var len = buf.length + (INT32_SIZE - (buf.length % INT32_SIZE)) | ||
buf = Buffer.concat([buf, zeroBuffer], len) | ||
} | ||
|
||
var arr = new Array(buf.length >>> 2) | ||
for (var i = 0, j = 0; i < buf.length; i += intSize, j++) { | ||
for (var i = 0, j = 0; i < buf.length; i += INT32_SIZE, j++) { | ||
arr[j] = buf.readInt32LE(i) | ||
} | ||
|
||
return arr | ||
} | ||
|
||
module.exports = function hash (buf, fn) { | ||
var arr = fn(toArray(buf), buf.length * charSize) | ||
buf = new Buffer(hashSize) | ||
var arr = fn(asUInt32Array(buf), buf.length * CHAR64_SIZE) | ||
buf = new Buffer(HASH128_SIZE) | ||
|
||
for (var i = 0; i < arr.length; i++) { | ||
buf.writeInt32LE(arr[i], i << 2, true) | ||
} | ||
|
||
return buf | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alloc zero fills by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, it was just about making that clear