@gmod/cram
Version:
read CRAM files with pure Javascript
26 lines • 924 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CramBufferOverrunError = void 0;
exports.getBits = getBits;
class CramBufferOverrunError extends Error {
}
exports.CramBufferOverrunError = CramBufferOverrunError;
function getBits(data, cursor, numBits) {
let val = 0;
if (cursor.bytePosition + (7 - cursor.bitPosition + numBits) / 8 >
data.length) {
throw new CramBufferOverrunError('read error during decoding. the file seems to be truncated.');
}
for (let dlen = numBits; dlen; dlen--) {
// get the next `dlen` bits in the input, put them in val
val <<= 1;
val |= (data[cursor.bytePosition] >> cursor.bitPosition) & 1;
cursor.bitPosition -= 1;
if (cursor.bitPosition < 0) {
cursor.bytePosition += 1;
}
cursor.bitPosition &= 7;
}
return val;
}
//# sourceMappingURL=getBits.js.map