2022-09-05 23:57:11 +03:00
|
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
exports.decodeBits = void 0;
|
|
|
|
const Base64 = ")!@#$%^&*(ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_";
|
2022-11-30 23:44:23 +03:00
|
|
|
/**
|
|
|
|
* @_ignore
|
|
|
|
*/
|
2022-09-05 23:57:11 +03:00
|
|
|
function decodeBits(width, data) {
|
|
|
|
const maxValue = (1 << width) - 1;
|
|
|
|
const result = [];
|
|
|
|
let accum = 0, bits = 0, flood = 0;
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
// Accumulate 6 bits of data
|
|
|
|
accum = ((accum << 6) | Base64.indexOf(data[i]));
|
|
|
|
bits += 6;
|
|
|
|
// While we have enough for a word...
|
|
|
|
while (bits >= width) {
|
|
|
|
// ...read the word
|
|
|
|
const value = (accum >> (bits - width));
|
|
|
|
accum &= (1 << (bits - width)) - 1;
|
|
|
|
bits -= width;
|
|
|
|
// A value of 0 indicates we exceeded maxValue, it
|
|
|
|
// floods over into the next value
|
|
|
|
if (value === 0) {
|
|
|
|
flood += maxValue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result.push(value + flood);
|
|
|
|
flood = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
exports.decodeBits = decodeBits;
|
|
|
|
//# sourceMappingURL=bit-reader.js.map
|