UNPKG

@gmod/cram

Version:

read CRAM files with pure Javascript

37 lines 1.56 kB
import CramCodec from "./_base.js"; import { CramUnimplementedError } from "../../errors.js"; import { parseItf8 } from "../util.js"; import { CramBufferOverrunError } from "./getBits.js"; export default class ExternalCodec extends CramCodec { 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 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] = parseItf8(contentBlock.content, cursor.bytePosition); cursor.bytePosition = cursor.bytePosition + bytesRead; return result; } _decodeByte(contentBlock, cursor) { if (cursor.bytePosition >= contentBlock.content.length) { throw new CramBufferOverrunError('attempted to read beyond end of block. this file seems truncated.'); } return contentBlock.content[cursor.bytePosition++]; } } //# sourceMappingURL=external.js.map