UNPKG

@gmod/cram

Version:

read CRAM files with pure Javascript

46 lines 1.8 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")); class ByteArrayLengthCodec extends _base_ts_1.default { instantiateCodec; _lengthCodecCache; _dataCodecCache; constructor(parameters, dataType, instantiateCodec) { super(parameters, dataType); this.instantiateCodec = instantiateCodec; } decode(slice, coreDataBlock, blocksByContentId, cursors) { const lengthCodec = this._getLengthCodec(); const arrayLength = lengthCodec.decode(slice, coreDataBlock, blocksByContentId, cursors); if (arrayLength > 0) { const dataCodec = this._getDataCodec(); const subarray = dataCodec.getBytesSubarray(blocksByContentId, cursors, arrayLength); if (subarray) { return subarray; } else { const data = new Uint8Array(arrayLength); for (let i = 0; i < arrayLength; i += 1) { data[i] = dataCodec.decode(slice, coreDataBlock, blocksByContentId, cursors); } return data; } } else { return new Uint8Array(0); } } _getLengthCodec() { this._lengthCodecCache ??= this.instantiateCodec(this.parameters.lengthsEncoding, 'int'); return this._lengthCodecCache; } _getDataCodec() { this._dataCodecCache ??= this.instantiateCodec(this.parameters.valuesEncoding, 'byte'); return this._dataCodecCache; } } exports.default = ByteArrayLengthCodec; //# sourceMappingURL=byteArrayLength.js.map