Skip to content

Commit

Permalink
fix(node): older versions of node@4 do not support base64buffer strin…
Browse files Browse the repository at this point in the history
…g parsing

Fixes: npm/npm#16809
  • Loading branch information
zkat committed May 31, 2017
1 parent 76f4a69 commit 513df4e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
10 changes: 4 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const Buffer = require('safe-buffer').Buffer

const crypto = require('crypto')
const Transform = require('stream').Transform

Expand Down Expand Up @@ -31,7 +33,7 @@ class Hash {
this.options = rawOpts ? rawOpts.slice(1).split('?') : []
}
hexDigest () {
return this.digest && bufFrom(this.digest, 'base64').toString('hex')
return this.digest && Buffer.from(this.digest, 'base64').toString('hex')
}
toJSON () {
return this.toString()
Expand Down Expand Up @@ -154,7 +156,7 @@ function fromHex (hexDigest, algorithm, opts) {
: ''
return parse(
`${algorithm}-${
bufFrom(hexDigest, 'hex').toString('base64')
Buffer.from(hexDigest, 'hex').toString('base64')
}${optString}`, opts
)
}
Expand Down Expand Up @@ -332,7 +334,3 @@ function getPrioritizedHash (algo1, algo2) {
? algo1
: algo2
}

function bufFrom (data, enc) {
return Buffer.from ? Buffer.from(data, enc) : new Buffer(data, enc)
}
8 changes: 6 additions & 2 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
"twitter": "maybekatz"
},
"license": "CC0-1.0",
"dependencies": {},
"dependencies": {
"safe-buffer": "^5.0.1"
},
"devDependencies": {
"nyc": "^10.3.2",
"standard": "^9.0.2",
Expand Down

0 comments on commit 513df4e

Please sign in to comment.