Skip to content

Commit

Permalink
Refactor to make sure all encodings get requested uncompressedSize, f…
Browse files Browse the repository at this point in the history
…ollow up to #151
  • Loading branch information
cmdcolin committed Feb 13, 2025
1 parent 67acfa7 commit c606253
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/cramFile/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export default class CramFile {
return data
}

async _uncompress(
async _uncompressPre(
compressionMethod: CompressionMethod,
inputBuffer: Uint8Array,
uncompressedSize: number,
Expand All @@ -295,10 +295,7 @@ export default class CramFile {
size -= chunk.length
}
} while (chunk !== -1)
const ret = new Uint8Array(uncompressedSize)
const r2 = concatUint8Array(chunks)
ret.set(r2, 0)
return ret
return concatUint8Array(chunks)
} else if (compressionMethod === 'lzma') {
const decompressedResponse = new Response(
new XzReadableStream(bufferToStream(inputBuffer)),
Expand All @@ -325,6 +322,24 @@ export default class CramFile {
}
}

async _uncompress(
compressionMethod: CompressionMethod,
inputBuffer: Uint8Array,
uncompressedSize: number,
) {
const buf = await this._uncompressPre(
compressionMethod,
inputBuffer,
uncompressedSize,
)
if (buf.length !== uncompressedSize) {
const ret = new Uint8Array(uncompressedSize)
ret.set(buf, 0)
return ret
}
return buf
}

async readBlock(position: number) {
const { majorVersion } = await this.getDefinition()
const sectionParsers = getSectionParsers(majorVersion)
Expand Down

0 comments on commit c606253

Please sign in to comment.