Skip to content

Commit

Permalink
update deps, switch to prebuild, make work for node 10
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Jun 29, 2018
1 parent 1951f56 commit cc354b7
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Files
.lock-wscript
pre-gyp-publish.sh
package-lock.json

# Filetypes
.*.swp
Expand Down
18 changes: 6 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@ os:
- osx
sudo: false
language: node_js
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
env:
matrix:
- TRAVIS_NODE_VERSION="4"
- TRAVIS_NODE_VERSION="6"
- TRAVIS_NODE_VERSION="8"
- TRAVIS_NODE_VERSION="10"
before_install:
- export JOBS=max
node_js:
- 6
- 8
- 10
notifications:
email:
- [email protected]
Expand Down
12 changes: 1 addition & 11 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@
}
]
]
}, {
'target_name': 'action_after_build',
'type': 'none',
'dependencies': [ '<(module_name)' ],
'copies': [
{
'files': [ '<(PRODUCT_DIR)/<(module_name).node' ],
'destination': '<(module_path)'
}
]
}
]
}
}
16 changes: 6 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
var binary = require('node-pre-gyp')
var path = require('path')
var binPath = binary.find(path.resolve(path.join(__dirname, 'package.json')))
var bin = require(binPath)
var bin = require('bindings')('bignum')
var Buffer = require('safe-buffer').Buffer
var BigNum = bin.BigNum

module.exports = BigNum
Expand All @@ -28,7 +26,7 @@ BigNum.conditionArgs = function (num, base) {
base: 2
}
}
} else if (num.match(/e\-/)) { // negative exponent
} else if (num.match(/e-/)) { // negative exponent
return {
num: Math.floor(Number(num)).toString(),
base: base || 10
Expand Down Expand Up @@ -257,9 +255,7 @@ BigNum.prototype.rand = function (to) {
return this.brand0()
}
} else {
var x = BigNum.isBigNum(to)
? to.sub(this)
: BigNum(to).sub(this)
var x = BigNum.isBigNum(to) ? to.sub(this) : BigNum(to).sub(this)
return x.brand0().add(this)
}
}
Expand Down Expand Up @@ -342,7 +338,7 @@ BigNum.prototype.toBuffer = function (opts) {
var len = buf.length === 1 && buf[0] === 0 ? 0 : buf.length
if (buf[0] & 0x80) len++

var ret = new Buffer(4 + len)
var ret = Buffer.alloc(4 + len)
if (len > 0) buf.copy(ret, 4 + (buf[0] & 0x80 ? 1 : 0))
if (buf[0] & 0x80) ret[4] = 0

Expand Down Expand Up @@ -377,7 +373,7 @@ BigNum.prototype.toBuffer = function (opts) {
var size = opts.size === 'auto' ? Math.ceil(hex.length / 2) : (opts.size || 1)

len = Math.ceil(hex.length / (2 * size)) * size
buf = new Buffer(len)
buf = Buffer.alloc(len)

// zero-pad the hex string so the chunks are all `size` long
while (hex.length < 2 * len) hex = '0' + hex
Expand Down
18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,23 @@
"url": "http:https://www.justmoon.net"
},
"dependencies": {
"nan": "^2.10.0",
"node-pre-gyp": "~0.10.2"
"bindings": "~1.3.0",
"nan": "~2.10.0",
"prebuild-install": "~4.0.0",
"safe-buffer": "~5.1.2"
},
"devDependencies": {
"aws-sdk": "~2.4.0",
"prebuild": "~7.6.0",
"prebuild-ci": "~2.2.3",
"put": "~0.0.5",
"standard": "~7.1.2",
"standard": "~11.0.1",
"tap": "~12.0.1"
},
"scripts": {
"install": "node-pre-gyp install --fallback-to-build",
"rebuild": "node-pre-gyp rebuild",
"test": "standard && tap --timeout 120 test/*.js"
"install": "prebuild-install || node-gyp rebuild",
"rebuild": "prebuild --compile",
"prebuild": "prebuild --all --strip --verbose",
"test": "standard && tap --timeout 120 test/*.js && prebuild-ci"
},
"binary": {
"host": "https://rvagg-node.s3-us-west-2.amazonaws.com",
Expand Down
5 changes: 3 additions & 2 deletions test/big.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var Buffer = require('safe-buffer').Buffer
var BigNum = require('../')
var test = require('tap').test

Expand Down Expand Up @@ -511,7 +512,7 @@ test('endian', { timeout: 120000 }, function (t) {
t.deepEqual(b.toBuffer({ endian: 'big', size: 'auto' }).toString('hex'), '0102030405')
t.deepEqual(b.toBuffer({ endian: 'little', size: 'auto' }).toString('hex'), '0504030201')

var c = new Buffer('000102030405', 'hex')
var c = Buffer.from('000102030405', 'hex')
t.deepEqual(BigNum.fromBuffer(c, { endian: 'big', size: 'auto' }).toString(16), '0102030405')
t.deepEqual(BigNum.fromBuffer(c, { endian: 'little', size: 'auto' }).toString(16), '050403020100')

Expand All @@ -520,7 +521,7 @@ test('endian', { timeout: 120000 }, function (t) {

test('bitlength', { timeout: 120000 }, function (t) {
var bl = BigNum(
'433593290010590489671135819286259593426549306666324008679782084292' +
'433593290010590489671135819286259593426549306666324008679782084292' +
'2446494189019075159822930571858728009485237489829138626896756141' +
'873895833763224917704497568647701157104426'
).bitLength()
Expand Down
25 changes: 13 additions & 12 deletions test/buf.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
var BigNum = require('../')
var put = require('put')
var test = require('tap').test
var Buffer = require('safe-buffer').Buffer

test('bufBe', function (t) {
var buf1 = new Buffer([1, 2, 3, 4])
var buf1 = Buffer.from([1, 2, 3, 4])
var num = BigNum.fromBuffer(buf1, { size: 4 }).toNumber()
t.deepEqual(
num,
Expand All @@ -22,7 +23,7 @@ test('bufBe', function (t) {
})

test('bufLe', function (t) {
var buf1 = new Buffer([1, 2, 3, 4])
var buf1 = Buffer.from([1, 2, 3, 4])
var num = BigNum
.fromBuffer(buf1, { size: 4, endian: 'little' })
.toNumber()
Expand All @@ -36,8 +37,8 @@ test('bufLe', function (t) {
})

test('bufBe_le', function (t) {
var bufBe = new Buffer([1, 2, 3, 4, 5, 6, 7, 8])
var bufLe = new Buffer([4, 3, 2, 1, 8, 7, 6, 5])
var bufBe = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8])
var bufLe = Buffer.from([4, 3, 2, 1, 8, 7, 6, 5])

var numBe = BigNum
.fromBuffer(bufBe, { size: 4, endian: 'big' })
Expand All @@ -53,11 +54,11 @@ test('bufBe_le', function (t) {
})

test('buf_high_bits', function (t) {
var bufBe = new Buffer([
var bufBe = Buffer.from([
201, 202, 203, 204,
205, 206, 207, 208
])
var bufLe = new Buffer([
var bufLe = Buffer.from([
204, 203, 202, 201,
208, 207, 206, 205
])
Expand Down Expand Up @@ -104,7 +105,7 @@ test('buf_to_from', function (t) {
})

test('toBuf', function (t) {
var buf = new Buffer([ 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f ])
var buf = Buffer.from([ 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f ])
var b = BigNum(
0x0a * 256 * 256 * 256 * 256 * 256 +
0x0b * 256 * 256 * 256 * 256 +
Expand Down Expand Up @@ -169,15 +170,15 @@ test('toMpint', function (t) {
// http:https://tools.ietf.org/html/rfc4251#page-10

var refs = {
'0': new Buffer([ 0x00, 0x00, 0x00, 0x00 ]),
'9a378f9b2e332a7': new Buffer([
'0': Buffer.from([ 0x00, 0x00, 0x00, 0x00 ]),
'9a378f9b2e332a7': Buffer.from([
0x00, 0x00, 0x00, 0x08,
0x09, 0xa3, 0x78, 0xf9,
0xb2, 0xe3, 0x32, 0xa7
]),
'80': new Buffer([ 0x00, 0x00, 0x00, 0x02, 0x00, 0x80 ]),
'-1234': new Buffer([ 0x00, 0x00, 0x00, 0x02, 0xed, 0xcc ]),
'-deadbeef': new Buffer([ 0x00, 0x00, 0x00, 0x05, 0xff, 0x21, 0x52, 0x41, 0x11 ])
'80': Buffer.from([ 0x00, 0x00, 0x00, 0x02, 0x00, 0x80 ]),
'-1234': Buffer.from([ 0x00, 0x00, 0x00, 0x02, 0xed, 0xcc ]),
'-deadbeef': Buffer.from([ 0x00, 0x00, 0x00, 0x05, 0xff, 0x21, 0x52, 0x41, 0x11 ])
}

Object.keys(refs).forEach(function (key) {
Expand Down

0 comments on commit cc354b7

Please sign in to comment.