Make ref an optional dependency

The ref module adds a compile step even when using the pure-JavaScript client.
This makes the installation optional so if the install fails due to not having
a compiler around you can still use the JavaScript client.

closes #398
This commit is contained in:
Brian Carlson 2013-07-23 10:10:41 -05:00
parent 343caefb75
commit 910cc134c9
2 changed files with 12 additions and 4 deletions

View File

@ -1,5 +1,8 @@
var ref = require('ref');
var endian = (ref.endianness === 'LE') ? 'BE' : 'LE';
try {
var ref = require('ref');
var endian = (ref.endianness === 'LE') ? 'BE' : 'LE';
} catch(e) {
}
var parseBits = function(data, bits, offset, invert, callback) {
offset = offset || 0;
@ -109,6 +112,9 @@ var parseInt32 = function(value) {
};
var parseInt64 = function(value) {
if(typeof ref == 'undefined') {
throw new Error("the ref module is not installed. npm install ref to use the binary parser on bigints");
}
return String(ref['readInt64' + endian](value, 0));
};

View File

@ -19,13 +19,15 @@
"main": "./lib",
"dependencies": {
"generic-pool": "2.0.3",
"buffer-writer": "1.0.0",
"ref": "0.1.3"
"buffer-writer": "1.0.0"
},
"devDependencies": {
"jshint": "1.1.0",
"semver": "~1.1.4"
},
"optionalDependencies": {
"ref": "0.1.3"
},
"scripts": {
"test": "make test-travis connectionString=postgres://postgres@localhost:5432/postgres",
"install": "node-gyp rebuild || (exit 0)"