Skip to content

Commit cc354b7

Browse files
committedJun 29, 2018
update deps, switch to prebuild, make work for node 10
1 parent 1951f56 commit cc354b7

File tree

7 files changed

+41
-55
lines changed

7 files changed

+41
-55
lines changed
 

‎.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Files
22
.lock-wscript
3-
pre-gyp-publish.sh
3+
package-lock.json
44

55
# Filetypes
66
.*.swp

‎.travis.yml

+6-12
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@ os:
33
- osx
44
sudo: false
55
language: node_js
6-
addons:
7-
apt:
8-
sources:
9-
- ubuntu-toolchain-r-test
10-
packages:
11-
- g++-4.8
12-
env:
13-
matrix:
14-
- TRAVIS_NODE_VERSION="4"
15-
- TRAVIS_NODE_VERSION="6"
16-
- TRAVIS_NODE_VERSION="8"
17-
- TRAVIS_NODE_VERSION="10"
6+
before_install:
7+
- export JOBS=max
8+
node_js:
9+
- 6
10+
- 8
11+
- 10
1812
notifications:
1913
email:
2014
- rod@vagg.org

‎binding.gyp

+1-11
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,6 @@
8282
}
8383
]
8484
]
85-
}, {
86-
'target_name': 'action_after_build',
87-
'type': 'none',
88-
'dependencies': [ '<(module_name)' ],
89-
'copies': [
90-
{
91-
'files': [ '<(PRODUCT_DIR)/<(module_name).node' ],
92-
'destination': '<(module_path)'
93-
}
94-
]
9585
}
9686
]
97-
}
87+
}

‎index.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
var binary = require('node-pre-gyp')
2-
var path = require('path')
3-
var binPath = binary.find(path.resolve(path.join(__dirname, 'package.json')))
4-
var bin = require(binPath)
1+
var bin = require('bindings')('bignum')
2+
var Buffer = require('safe-buffer').Buffer
53
var BigNum = bin.BigNum
64

75
module.exports = BigNum
@@ -28,7 +26,7 @@ BigNum.conditionArgs = function (num, base) {
2826
base: 2
2927
}
3028
}
31-
} else if (num.match(/e\-/)) { // negative exponent
29+
} else if (num.match(/e-/)) { // negative exponent
3230
return {
3331
num: Math.floor(Number(num)).toString(),
3432
base: base || 10
@@ -257,9 +255,7 @@ BigNum.prototype.rand = function (to) {
257255
return this.brand0()
258256
}
259257
} else {
260-
var x = BigNum.isBigNum(to)
261-
? to.sub(this)
262-
: BigNum(to).sub(this)
258+
var x = BigNum.isBigNum(to) ? to.sub(this) : BigNum(to).sub(this)
263259
return x.brand0().add(this)
264260
}
265261
}
@@ -342,7 +338,7 @@ BigNum.prototype.toBuffer = function (opts) {
342338
var len = buf.length === 1 && buf[0] === 0 ? 0 : buf.length
343339
if (buf[0] & 0x80) len++
344340

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

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

379375
len = Math.ceil(hex.length / (2 * size)) * size
380-
buf = new Buffer(len)
376+
buf = Buffer.alloc(len)
381377

382378
// zero-pad the hex string so the chunks are all `size` long
383379
while (hex.length < 2 * len) hex = '0' + hex

‎package.json

+11-7
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,23 @@
2222
"url": "http://www.justmoon.net"
2323
},
2424
"dependencies": {
25-
"nan": "^2.10.0",
26-
"node-pre-gyp": "~0.10.2"
25+
"bindings": "~1.3.0",
26+
"nan": "~2.10.0",
27+
"prebuild-install": "~4.0.0",
28+
"safe-buffer": "~5.1.2"
2729
},
2830
"devDependencies": {
29-
"aws-sdk": "~2.4.0",
31+
"prebuild": "~7.6.0",
32+
"prebuild-ci": "~2.2.3",
3033
"put": "~0.0.5",
31-
"standard": "~7.1.2",
34+
"standard": "~11.0.1",
3235
"tap": "~12.0.1"
3336
},
3437
"scripts": {
35-
"install": "node-pre-gyp install --fallback-to-build",
36-
"rebuild": "node-pre-gyp rebuild",
37-
"test": "standard && tap --timeout 120 test/*.js"
38+
"install": "prebuild-install || node-gyp rebuild",
39+
"rebuild": "prebuild --compile",
40+
"prebuild": "prebuild --all --strip --verbose",
41+
"test": "standard && tap --timeout 120 test/*.js && prebuild-ci"
3842
},
3943
"binary": {
4044
"host": "https://rvagg-node.s3-us-west-2.amazonaws.com",

‎test/big.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var Buffer = require('safe-buffer').Buffer
12
var BigNum = require('../')
23
var test = require('tap').test
34

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

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

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

521522
test('bitlength', { timeout: 120000 }, function (t) {
522523
var bl = BigNum(
523-
'433593290010590489671135819286259593426549306666324008679782084292' +
524+
'433593290010590489671135819286259593426549306666324008679782084292' +
524525
'2446494189019075159822930571858728009485237489829138626896756141' +
525526
'873895833763224917704497568647701157104426'
526527
).bitLength()

‎test/buf.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
var BigNum = require('../')
22
var put = require('put')
33
var test = require('tap').test
4+
var Buffer = require('safe-buffer').Buffer
45

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

2425
test('bufLe', function (t) {
25-
var buf1 = new Buffer([1, 2, 3, 4])
26+
var buf1 = Buffer.from([1, 2, 3, 4])
2627
var num = BigNum
2728
.fromBuffer(buf1, { size: 4, endian: 'little' })
2829
.toNumber()
@@ -36,8 +37,8 @@ test('bufLe', function (t) {
3637
})
3738

3839
test('bufBe_le', function (t) {
39-
var bufBe = new Buffer([1, 2, 3, 4, 5, 6, 7, 8])
40-
var bufLe = new Buffer([4, 3, 2, 1, 8, 7, 6, 5])
40+
var bufBe = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8])
41+
var bufLe = Buffer.from([4, 3, 2, 1, 8, 7, 6, 5])
4142

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

5556
test('buf_high_bits', function (t) {
56-
var bufBe = new Buffer([
57+
var bufBe = Buffer.from([
5758
201, 202, 203, 204,
5859
205, 206, 207, 208
5960
])
60-
var bufLe = new Buffer([
61+
var bufLe = Buffer.from([
6162
204, 203, 202, 201,
6263
208, 207, 206, 205
6364
])
@@ -104,7 +105,7 @@ test('buf_to_from', function (t) {
104105
})
105106

106107
test('toBuf', function (t) {
107-
var buf = new Buffer([ 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f ])
108+
var buf = Buffer.from([ 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f ])
108109
var b = BigNum(
109110
0x0a * 256 * 256 * 256 * 256 * 256 +
110111
0x0b * 256 * 256 * 256 * 256 +
@@ -169,15 +170,15 @@ test('toMpint', function (t) {
169170
// http://tools.ietf.org/html/rfc4251#page-10
170171

171172
var refs = {
172-
'0': new Buffer([ 0x00, 0x00, 0x00, 0x00 ]),
173-
'9a378f9b2e332a7': new Buffer([
173+
'0': Buffer.from([ 0x00, 0x00, 0x00, 0x00 ]),
174+
'9a378f9b2e332a7': Buffer.from([
174175
0x00, 0x00, 0x00, 0x08,
175176
0x09, 0xa3, 0x78, 0xf9,
176177
0xb2, 0xe3, 0x32, 0xa7
177178
]),
178-
'80': new Buffer([ 0x00, 0x00, 0x00, 0x02, 0x00, 0x80 ]),
179-
'-1234': new Buffer([ 0x00, 0x00, 0x00, 0x02, 0xed, 0xcc ]),
180-
'-deadbeef': new Buffer([ 0x00, 0x00, 0x00, 0x05, 0xff, 0x21, 0x52, 0x41, 0x11 ])
179+
'80': Buffer.from([ 0x00, 0x00, 0x00, 0x02, 0x00, 0x80 ]),
180+
'-1234': Buffer.from([ 0x00, 0x00, 0x00, 0x02, 0xed, 0xcc ]),
181+
'-deadbeef': Buffer.from([ 0x00, 0x00, 0x00, 0x05, 0xff, 0x21, 0x52, 0x41, 0x11 ])
181182
}
182183

183184
Object.keys(refs).forEach(function (key) {

0 commit comments

Comments
 (0)
Please sign in to comment.