Skip to content

Commit a1fdaa7

Browse files
cmdcolinclaude
andcommitted
format
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent bf6e8ab commit a1fdaa7

11 files changed

Lines changed: 445 additions & 364 deletions

src/bgzfBlockScan.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export function scanBgzfBlocks(
2020

2121
while (offset + BGZF_MIN_BLOCK_SIZE <= input.length) {
2222
if (
23-
input[offset] !== 0x1F ||
24-
input[offset + 1] !== 0x8B ||
23+
input[offset] !== 0x1f ||
24+
input[offset + 1] !== 0x8b ||
2525
input[offset + 2] !== 8 ||
2626
input[offset + 3] !== 4
2727
) {
@@ -36,8 +36,7 @@ export function scanBgzfBlocks(
3636
break
3737
}
3838

39-
const bsize =
40-
(input[offset + 16]! | (input[offset + 17]! << 8)) + 1
39+
const bsize = (input[offset + 16]! | (input[offset + 17]! << 8)) + 1
4140

4241
if (bsize < BGZF_MIN_BLOCK_SIZE || offset + bsize > input.length) {
4342
break

src/unzip.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { ungzip } from 'pako-esm2'
22

3-
import {
4-
type BgzfBlockInfo,
5-
scanBgzfBlocks,
6-
} from './bgzfBlockScan.ts'
3+
import { type BgzfBlockInfo, scanBgzfBlocks } from './bgzfBlockScan.ts'
74
import { concatUint8Array } from './util.ts'
85
import {
96
decompressAll,
@@ -34,7 +31,7 @@ interface Chunk {
3431
}
3532

3633
function hasGzipHeader(data: Uint8Array) {
37-
return data.length >= 2 && data[0] === 0x1F && data[1] === 0x8B
34+
return data.length >= 2 && data[0] === 0x1f && data[1] === 0x8b
3835
}
3936

4037
async function decompressGzip(inputData: Uint8Array) {
@@ -152,7 +149,10 @@ export async function unzipChunkSlice(
152149

153150
if (blocks.length > 1) {
154151
let sharedBuf: SharedArrayBuffer
155-
if (inputData.buffer instanceof SharedArrayBuffer && inputData.byteOffset === 0) {
152+
if (
153+
inputData.buffer instanceof SharedArrayBuffer &&
154+
inputData.byteOffset === 0
155+
) {
156156
sharedBuf = inputData.buffer
157157
} else {
158158
sharedBuf = new SharedArrayBuffer(inputData.byteLength)
@@ -164,7 +164,12 @@ export async function unzipChunkSlice(
164164
blocks,
165165
)
166166
return {
167-
...assembleChunkSliceResult(decompressResult.blocks, blocks, minv, maxv),
167+
...assembleChunkSliceResult(
168+
decompressResult.blocks,
169+
blocks,
170+
minv,
171+
maxv,
172+
),
168173
timing: decompressResult.timing,
169174
}
170175
}

src/workerPool.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ export interface WorkerTiming {
2626

2727
type WorkerMessage =
2828
| { type: 'ready' }
29-
| { type: 'rangeResult'; batchId: number; data: Uint8Array; viewMs: number; wasmMs: number }
29+
| {
30+
type: 'rangeResult'
31+
batchId: number
32+
data: Uint8Array
33+
viewMs: number
34+
wasmMs: number
35+
}
3036
| { type: 'error'; message?: string }
3137

3238
interface RangeResult {
@@ -52,10 +58,10 @@ class ManagedWorker {
5258

5359
constructor(workerUrl: string | URL) {
5460
this.worker = new Worker(workerUrl)
55-
this.readyPromise = new Promise<void>((resolve) => {
61+
this.readyPromise = new Promise<void>(resolve => {
5662
this.readyResolve = resolve
5763
})
58-
this.worker.onmessage = (e) => {
64+
this.worker.onmessage = e => {
5965
this.handleMessage(e.data)
6066
}
6167
}
@@ -138,7 +144,7 @@ export function getSharedWorkerPool(
138144
}
139145
if (!sharedPoolPromise) {
140146
const gen = poolGeneration
141-
sharedPoolPromise = createBgzfWorkerPool(numWorkers).then((pool) => {
147+
sharedPoolPromise = createBgzfWorkerPool(numWorkers).then(pool => {
142148
if (gen !== poolGeneration) {
143149
pool.destroy()
144150
throw new Error('Worker pool was destroyed during initialization')
@@ -168,9 +174,7 @@ export async function createBgzfWorkerPool(
168174
}
169175

170176
const url = workerUrl ?? getWorkerBlobUrl()
171-
const count =
172-
numWorkers ??
173-
Math.min(navigator.hardwareConcurrency, 4)
177+
const count = numWorkers ?? Math.min(navigator.hardwareConcurrency, 4)
174178
const workers: ManagedWorker[] = []
175179

176180
for (let i = 0; i < count; i++) {
@@ -180,7 +184,7 @@ export async function createBgzfWorkerPool(
180184
for (const w of workers) {
181185
w.init()
182186
}
183-
await Promise.all(workers.map((w) => w.readyPromise))
187+
await Promise.all(workers.map(w => w.readyPromise))
184188

185189
let destroyed = false
186190

src/workerPoolClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class BgzfWorkerPoolClient implements BgzfWorkerPool {
1717

1818
constructor(port: MessagePort) {
1919
this.port = port
20-
this.port.onmessage = (e) => {
20+
this.port.onmessage = e => {
2121
this.handleResponse(e.data)
2222
}
2323
this.port.start()

src/workerPoolHost.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class BgzfWorkerPoolHost {
1818

1919
connectPort(port: MessagePort) {
2020
this.ports.add(port)
21-
port.onmessage = (e) => {
21+
port.onmessage = e => {
2222
void this.handleRequest(port, e.data)
2323
}
2424
port.start()

0 commit comments

Comments
 (0)