You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
515 B
JavaScript
31 lines
515 B
JavaScript
module.exports = read
|
|
|
|
var MSB = 0x80
|
|
, REST = 0x7F
|
|
|
|
function read(buf, offset) {
|
|
var res = 0
|
|
, offset = offset || 0
|
|
, shift = 0
|
|
, counter = offset
|
|
, b
|
|
, l = buf.length
|
|
|
|
do {
|
|
if(counter >= l) {
|
|
read.bytes = 0
|
|
read.bytesRead = 0 // DEPRECATED
|
|
return undefined
|
|
}
|
|
b = buf[counter++]
|
|
res += shift < 28
|
|
? (b & REST) << shift
|
|
: (b & REST) * Math.pow(2, shift)
|
|
shift += 7
|
|
} while (b >= MSB)
|
|
|
|
read.bytes = counter - offset
|
|
|
|
return res
|
|
}
|