@gmod/cram
Version:
read CRAM files with pure Javascript
43 lines • 1.84 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const _base_ts_1 = __importDefault(require("./_base.js"));
const errors_ts_1 = require("../../errors.js");
const util_ts_1 = require("../util.js");
const getBits_ts_1 = require("./getBits.js");
class ExternalCodec extends _base_ts_1.default {
constructor(parameters, dataType) {
super(parameters, dataType);
if (this.dataType === 'int') {
this._decodeData = this._decodeInt;
}
else if (this.dataType === 'byte') {
this._decodeData = this._decodeByte;
}
else {
throw new errors_ts_1.CramUnimplementedError(`${this.dataType} decoding not yet implemented by EXTERNAL codec`);
}
}
decode(_slice, _coreDataBlock, blocksByContentId, cursors) {
const { blockContentId } = this.parameters;
const contentBlock = blocksByContentId[blockContentId];
return contentBlock
? this._decodeData(contentBlock, cursors.externalBlocks.getCursor(blockContentId))
: undefined;
}
_decodeInt(contentBlock, cursor) {
const [result, bytesRead] = (0, util_ts_1.parseItf8)(contentBlock.content, cursor.bytePosition);
cursor.bytePosition = cursor.bytePosition + bytesRead;
return result;
}
_decodeByte(contentBlock, cursor) {
if (cursor.bytePosition >= contentBlock.content.length) {
throw new getBits_ts_1.CramBufferOverrunError('attempted to read beyond end of block. this file seems truncated.');
}
return contentBlock.content[cursor.bytePosition++];
}
}
exports.default = ExternalCodec;
//# sourceMappingURL=external.js.map