Comparing version 0.0.2 to 0.0.3
48
index.js
module.exports = varint | ||
varint.encode = encode | ||
varint.encode = require('./encode.js'); | ||
var EE = require('events').EventEmitter | ||
, MSB = 0x80 | ||
, REST = 0x7F | ||
, MSBALL = ~REST | ||
, Decoder = require('./decode.js') | ||
function varint() { | ||
var ee = new EE | ||
, dec = new Decoder | ||
ee.write = write | ||
ee.accum = [] | ||
return ee | ||
} | ||
function encode(num, out, offset) { | ||
out = out || [] | ||
offset = offset || 0 | ||
while(num & MSBALL) { | ||
out[offset++] = (num & 0xFF) | MSB | ||
num >>>= 7 | ||
dec.ondata = function (item) { | ||
ee.emit("data", item) | ||
} | ||
out[offset] = num | ||
return out | ||
} | ||
function write(byte) { | ||
var msb = byte & MSB | ||
, accum = this.accum | ||
, len | ||
, out | ||
accum[accum.length] = byte & REST | ||
if(msb) { | ||
return | ||
ee.write = function (item) { | ||
dec.write(item); | ||
} | ||
len = accum.length | ||
out = 0 | ||
return ee | ||
} | ||
for(var i = 0; i < len; ++i) { | ||
out |= accum[i] << (7 * i) | ||
} | ||
accum.length = 0 | ||
this.emit('data', out) | ||
return | ||
} |
{ | ||
"name": "varint", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "use msb to create integer values of varying sizes", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
4359
6
118