Skip to content

Commit

Permalink
Modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 19, 2024
1 parent e662b5f commit ffec22b
Show file tree
Hide file tree
Showing 14 changed files with 4,087 additions and 4,091 deletions.
16 changes: 0 additions & 16 deletions src/cramFile/long.ts

This file was deleted.

30 changes: 21 additions & 9 deletions src/cramFile/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import md5 from 'md5'

import { CramBufferOverrunError } from './codecs/getBits'
import { longFromBytesToUnsigned } from './long'

export function itf8Size(v: number) {
if (!(v & ~0x7f)) {
Expand All @@ -20,12 +19,6 @@ export function itf8Size(v: number) {
}

export function parseItf8(buffer: Uint8Array, initialOffset: number) {
if (initialOffset >= buffer.length) {
throw new CramBufferOverrunError(
'Attempted to read beyond end of buffer; this file seems truncated.',
)
}

let offset = initialOffset
const countFlags = buffer[offset]!
let result: number
Expand Down Expand Up @@ -139,12 +132,31 @@ export function parseLtf8(buffer: Uint8Array, initialOffset: number) {
}
// Eight byte value < 0xFF
else if (countFlags < 0xff) {
value = longFromBytesToUnsigned(buffer.subarray(offset + 1, offset + 8))
value =
((buffer[offset + 1]! << 24) |
(buffer[offset + 2]! << 16) |
(buffer[offset + 3]! << 8) |
buffer[offset + 4]!) *
Math.pow(2, 32) +
((buffer[offset + 5]! << 24) |
(buffer[offset + 6]! << 16) |
(buffer[offset + 7]! << 8) |
buffer[offset + 8]!)
offset += 8
}
// Nine byte value
else {
value = longFromBytesToUnsigned(buffer.subarray(offset + 1, offset + 9))
value =
buffer[offset + 1]! * Math.pow(2, 56) +
((buffer[offset + 2]! << 24) |
(buffer[offset + 3]! << 16) |
(buffer[offset + 4]! << 8) |
buffer[offset + 5]!) *
Math.pow(2, 32) +
((buffer[offset + 6]! << 24) |
(buffer[offset + 7]! << 16) |
(buffer[offset + 8]! << 8) |
buffer[offset + 9]!)
offset += 9
}

Expand Down
4 changes: 2 additions & 2 deletions test/snaps/__snapshots__/ce__large_seq.2.1.cram.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ exports[`can dump the whole ce#large_seq.2.1.cram without error 1`] = `
206,
],
"length": 91153,
"numBases": 994117,
"numBases": 1000747,
"numBlocks": 11,
"numLandmarks": 1,
"numRecords": 2,
Expand All @@ -396,7 +396,7 @@ exports[`can dump the whole ce#large_seq.2.1.cram without error 1`] = `
206,
],
"length": 91153,
"numBases": 994117,
"numBases": 1000747,
"numBlocks": 11,
"numLandmarks": 1,
"numRecords": 2,
Expand Down
Loading

0 comments on commit ffec22b

Please sign in to comment.