* Split core lib into multiple files * Refactor data encoding methods * Refactor data masking process * Improve qr code generation process * Increase minimum required node version to 0.10 * Add linter * Add tests and tests coverage * Update travis config to fix compilation issues * Add examples folder * Add missing license tag in package.json * Update build script and add sourcemap support * Publish only strictly needed files on npm * Update readme
37 lines
715 B
JavaScript
37 lines
715 B
JavaScript
function BitBuffer () {
|
|
this.buffer = []
|
|
this.length = 0
|
|
}
|
|
|
|
BitBuffer.prototype = {
|
|
|
|
get: function (index) {
|
|
var bufIndex = Math.floor(index / 8)
|
|
return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) === 1
|
|
},
|
|
|
|
put: function (num, length) {
|
|
for (var i = 0; i < length; i++) {
|
|
this.putBit(((num >>> (length - i - 1)) & 1) === 1)
|
|
}
|
|
},
|
|
|
|
getLengthInBits: function () {
|
|
return this.length
|
|
},
|
|
|
|
putBit: function (bit) {
|
|
var bufIndex = Math.floor(this.length / 8)
|
|
if (this.buffer.length <= bufIndex) {
|
|
this.buffer.push(0)
|
|
}
|
|
|
|
if (bit) {
|
|
this.buffer[bufIndex] |= (0x80 >>> (this.length % 8))
|
|
}
|
|
|
|
this.length++
|
|
}
|
|
}
|
|
|
|
module.exports = BitBuffer
|