UNPKG

@gmod/cram

Version:

read CRAM files with pure Javascript

37 lines 1.71 kB
"use strict"; 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 getBits_ts_1 = require("./getBits.js"); class ByteArrayStopCodec extends _base_ts_1.default { decode(_slice, _coreDataBlock, blocksByContentId, cursors) { const { blockContentId } = this.parameters; const contentBlock = blocksByContentId[blockContentId]; if (!contentBlock) { throw new errors_ts_1.CramMalformedError(`no block found with content ID ${blockContentId}`); } const cursor = cursors.externalBlocks.getCursor(blockContentId); return this._decodeByteArray(contentBlock, cursor); } _decodeByteArray(contentBlock, cursor) { const dataBuffer = contentBlock.content; const { stopByte } = this.parameters; // scan to the next stop byte const startPosition = cursor.bytePosition; let stopPosition = cursor.bytePosition; while (dataBuffer[stopPosition] !== stopByte && stopPosition < dataBuffer.length) { if (stopPosition === dataBuffer.length) { throw new getBits_ts_1.CramBufferOverrunError('byteArrayStop reading beyond length of data buffer?'); } stopPosition = stopPosition + 1; } cursor.bytePosition = stopPosition + 1; return dataBuffer.subarray(startPosition, stopPosition); } } exports.default = ByteArrayStopCodec; //# sourceMappingURL=byteArrayStop.js.map