From 59bcaeac168dd56bbc9dbe8e987603c1852ce198 Mon Sep 17 00:00:00 2001 From: jrobinso <933148+jrobinso@users.noreply.github.com> Date: Tue, 10 Jan 2023 22:56:56 -0800 Subject: [PATCH] Fix block cache for small bam edge case --- js/bam/bgzBlockLoader.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/js/bam/bgzBlockLoader.js b/js/bam/bgzBlockLoader.js index 85838efb4..9deac70d6 100644 --- a/js/bam/bgzBlockLoader.js +++ b/js/bam/bgzBlockLoader.js @@ -69,8 +69,10 @@ class BGZBlockLoader { } else { const c = this.cache - if (c && (c.startBlock <= startBlock && c.endBlock >= endBlock)) { - //console.log("Complete overlap") + if (c && + c.startBlock <= startBlock && + (c.endBlock >= endBlock || skipEnd && c.nextEndBlock === endBlock)) { + console.log("Complete overlap") const startOffset = startBlock - c.startBlock const endOffset = endBlock - c.startBlock return inflateBlocks(c.buffer, startOffset, endOffset) @@ -127,12 +129,13 @@ class BGZBlockLoader { } // If skipEnd === true we need to find boundary of last block in cache + let nextEndBlock = endBlock if(skipEnd) { const boundaries = findBlockBoundaries(buffer) endBlock = boundaries[boundaries.length - 1] } - this.cache = {startBlock, endBlock, buffer} + this.cache = {startBlock, endBlock, nextEndBlock, buffer} return inflateBlocks(buffer) } }