Skip to content

Commit

Permalink
Long
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 18, 2024
1 parent 3bf2afb commit eec8f6d
Show file tree
Hide file tree
Showing 3 changed files with 225 additions and 244 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@
"bzip2": "^0.1.1",
"crc": "^4.3.2",
"generic-filehandle2": "^1.0.0",
"long": "^4.0.0",
"longfn": "^1.3.1",
"md5": "^2.2.1",
"pako": "^1.0.4",
"quick-lru": "^4.0.1",
"xz-decompress": "^0.2.1"
},
"devDependencies": {
"@gmod/indexedfasta": "^3.0.0",
"@types/long": "^4.0.0",
"@types/md5": "^2.3.2",
"@types/pako": "^1.0.3",
"@typescript-eslint/eslint-plugin": "^8.0.0",
Expand Down
28 changes: 6 additions & 22 deletions src/cramFile/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Long from 'long'
import { fromBytesBE, toNumber } from 'longfn'
import md5 from 'md5'

import { CramBufferOverrunError } from './codecs/getBits'
Expand Down Expand Up @@ -65,7 +65,7 @@ export function parseLtf8(buffer: Uint8Array, initialOffset: number) {
const dataView = new DataView(buffer.buffer)
let offset = initialOffset
const countFlags = buffer[offset]!
let n: number | Long
let n: number
if (countFlags < 0x80) {
n = countFlags
offset += 1
Expand Down Expand Up @@ -116,28 +116,12 @@ export function parseLtf8(buffer: Uint8Array, initialOffset: number) {
buffer[offset + 6]!)
offset += 7
} else if (countFlags < 0xff) {
n = Long.fromBytesBE(
buffer.slice(offset + 1, offset + 8) as unknown as number[],
)
if (
n.greaterThan(Number.MAX_SAFE_INTEGER) ||
n.lessThan(Number.MIN_SAFE_INTEGER)
) {
throw new Error('integer overflow')
}
n = n.toNumber()
n = toNumber(fromBytesBE(buffer.slice(offset + 1, offset + 8), false))

offset += 8
} else {
n = Long.fromBytesBE(
buffer.slice(offset + 1, offset + 9) as unknown as number[],
)
if (
n.greaterThan(Number.MAX_SAFE_INTEGER) ||
n.lessThan(Number.MIN_SAFE_INTEGER)
) {
throw new Error('integer overflow')
}
n = n.toNumber()
n = toNumber(fromBytesBE(buffer.subarray(offset + 1, offset + 9), false))

offset += 9
}
return [n, offset - initialOffset] as const
Expand Down
Loading

0 comments on commit eec8f6d

Please sign in to comment.