mirror of
https://github.com/nodejs/node.git
synced 2025-05-16 13:53:32 +00:00

Closes: https://github.com/nodejs/node/pull/16280 PR-URL: https://github.com/nodejs/node/pull/16509 Fixes: https://github.com/nodejs/node/issues/14161 Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com>
39 lines
696 B
JavaScript
39 lines
696 B
JavaScript
function QRBitBuffer() {
|
|
this.buffer = [];
|
|
this.length = 0;
|
|
}
|
|
|
|
QRBitBuffer.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 = QRBitBuffer;
|