diff --git a/lib/types/binaryParsers.js b/lib/types/binaryParsers.js index 7d3319e..32837ca 100644 --- a/lib/types/binaryParsers.js +++ b/lib/types/binaryParsers.js @@ -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)); }; diff --git a/package.json b/package.json index 00878b6..7de5fa8 100644 --- a/package.json +++ b/package.json @@ -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)"