Comparing version 0.0.14 to 0.1.0
93
index.js
@@ -1,1 +0,92 @@ | ||
module.exports = require('bindings')('binpack.node') | ||
// t is a binpack typename | ||
var sizeOfType = function(t) { | ||
// unsigned are the same length as signed | ||
if(t[0] === 'U') { | ||
t = t.slice(1); | ||
} | ||
return { | ||
'Float32' : 4, | ||
'Float64' : 8, | ||
'Int8' : 1, | ||
'Int16' : 2, | ||
'Int32' : 4, | ||
'Int64' : 8 | ||
}[t]; | ||
}; | ||
var endianConv = function(e, t) { | ||
// node doesn't define 8 bit endianness | ||
if(t[t.length - 1] === '8') | ||
return ''; | ||
if(e === 'big') { | ||
return 'BE'; | ||
} | ||
return 'LE'; | ||
}; | ||
var addBindings = function(binpackTypename, nodeTypename){ | ||
if(!(typeof nodeTypename !== "undefined" && nodeTypename !== null)) { | ||
nodeTypename = binpackTypename; | ||
} | ||
module.exports['pack' + binpackTypename] = function(num, endian){ | ||
b = new Buffer(sizeOfType(binpackTypename)); | ||
b['write' + nodeTypename + endianConv(endian, binpackTypename)](num, 0, true); | ||
return b; | ||
} | ||
module.exports['unpack' + binpackTypename] = function(buff, endian){ | ||
return buff['read' + nodeTypename + endianConv(endian, binpackTypename)](0); | ||
} | ||
} | ||
var addIntBindings = function(n) { | ||
addBindings("Int" + n); | ||
addBindings("UInt" + n); | ||
} | ||
addIntBindings(8); | ||
addIntBindings(16); | ||
addIntBindings(32); | ||
twoToThe32 = Math.pow(2, 32); | ||
// 64 bit bindings require special care | ||
var read64 = function(unsigned){return function(buff, endian){ | ||
var e = endianConv(endian, ''); | ||
var u = unsigned ? 'U' : ''; | ||
var low, high; | ||
if(e === 'LE') { | ||
low = buff.readUInt32LE(0); | ||
high = buff['read' + u + 'Int32LE'](4); | ||
} else { | ||
low = buff.readUInt32BE(4); | ||
high = buff['read' + u + 'Int32BE'](0); | ||
} | ||
return high * twoToThe32 + low; | ||
};}; | ||
var write64 = function(unsigned){return function(num, endian){ | ||
var e = endianConv(endian, ''); | ||
var u = unsigned ? 'U' : ''; | ||
var b = new Buffer(8); | ||
var high = Math.floor(num / twoToThe32); | ||
var low = Math.floor(num - high * twoToThe32); | ||
if(e == 'LE') { | ||
b.writeUInt32LE(low, 0, true); | ||
b['write' + u + 'Int32LE'](high, 4, true); | ||
} else { | ||
b.writeUInt32BE(low, 4, true); | ||
b['write' + u + 'Int32BE'](high, 0, true); | ||
} | ||
return b; | ||
};}; | ||
module.exports.unpackInt64 = read64(false); | ||
module.exports.unpackUInt64 = read64(true); | ||
module.exports.packInt64 = write64(false); | ||
module.exports.packUInt64 = write64(true); | ||
addBindings("Float32", "Float"); | ||
addBindings("Float64", "Double"); |
{ | ||
"name": "binpack", | ||
"version": "0.0.14", | ||
"main": "binpack", | ||
"version": "0.1.0", | ||
"main": "index", | ||
"author": { | ||
"name" : "Russell McClellan", | ||
"email": "russell.mcclellan@gmail.com", | ||
"url" : "http://www.ghostfact.com" | ||
"url" : "http://www.russellmcc.com" | ||
}, | ||
@@ -18,17 +18,10 @@ "description": "Minimalist numeric binary packing utilities for node.js", | ||
"type": "git", | ||
"url": "http://github.com/russellmcc/node-binpack.git" | ||
"url": "http://github.com/russellmcc/node-binpack.git" | ||
}, | ||
"dependencies" : { | ||
"bindings" : "*" | ||
}, | ||
"devDependencies" : { | ||
"vows" : "*", | ||
"coffee-script" : "*" | ||
"coffee-script" : "<1.7.0" | ||
}, | ||
"directories": { | ||
"src": "src" | ||
}, | ||
"engines": { | ||
"node": ">=0.6.0" | ||
}, | ||
"scripts": { | ||
@@ -35,0 +28,0 @@ "test" : "vows tests/*" |
@@ -0,8 +1,9 @@ | ||
[![build status](https://secure.travis-ci.org/russellmcc/node-binpack.png)](http://travis-ci.org/russellmcc/node-binpack) | ||
# binpack | ||
_Minimalist numeric binary packing utilities for node.js_ | ||
_Deprecated binary packing utilities for node.js_ | ||
## What's all this? | ||
This is an intentionally simple binary packing/unpacking package for node.js for programmers who prefer to write most of their parsing code in javascript. This exposes some common binary formats for numbers. | ||
node now actually contains native code for packing binary buffers so this module is no longer needed. do not use in new code. | ||
@@ -20,7 +21,5 @@ see the included COPYING file for licensing. | ||
Int32 | ||
Int64 | ||
UInt8 | ||
UInt16 | ||
UInt32 | ||
UInt64 | ||
@@ -31,6 +30,2 @@ Each `pack*` function takes a javascript number and outputs a node.js Buffer. | ||
Both types of functions take an optional second argument. If this argument is `"big"`, the output is put in big endian format. If the argument is `"little"`, the output is put in little endian format. If the argument is anything else or non-existent, we default to your machine's native encoding. | ||
## How is this different than the `binary` module on npm? | ||
It contains floating point values, and it has packing functions | ||
Both types of functions take an optional second argument. If this argument is `"big"`, the output is put in big endian format. If the argument is `"little"`, the output is put in little endian format. If the argument is anything else or non-existent, we default to "little" endian [THIS IS NEW BEHAVIOR IN 0.0.15 - previous version would default to the native encoding.]. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
0
80
1
0
7936
8
30
- Removedbindings@*
- Removedbindings@1.5.0(transitive)
- Removedfile-uri-to-path@1.0.0(transitive)