Skip to content

Commit e2cd381

Browse files
committed
Bump deps
1 parent adc024b commit e2cd381

15 files changed

+1307
-945
lines changed

.github/workflows/push.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ on: push
44

55
jobs:
66
test:
7-
name: Lint, build, and test on node 14.x and ubuntu-latest
7+
name: Lint, build, and test on node 20.x and ubuntu-latest
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v2
11-
- name: Use Node.js 14.x
12-
uses: actions/setup-node@v1
10+
- uses: actions/checkout@v4
11+
- name: Use Node.js 20.x
12+
uses: actions/setup-node@v4
1313
with:
14-
node-version: 14.x
14+
node-version: 20.x
1515
- name: Install deps (with cache)
1616
uses: bahmutov/npm-install@v1
1717
- name: Lint codebase

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![Coverage Status](https://img.shields.io/codecov/c/github/GMOD/bgzf-filehandle/master.svg?style=flat-square)](https://codecov.io/gh/GMOD/bgzf-filehandle/branch/master)
33
[![Build Status](https://img.shields.io/github/actions/workflow/status/GMOD/bgzf-filehandle/push.yml?branch=master)](https://github.com/GMOD/bgzf-filehandle/actions)
44

5-
Transparently read [indexed block-gzipped (BGZF)](http://www.htslib.org/doc/bgzip.html) files, such as those created by bgzip, using coordinates from the uncompressed file. The module is used in @gmod/indexedfasta to read bgzip-indexed fasta files (with gzi index, fai index, and fa).
5+
Transparently read [indexed block-gzipped (BGZF)](http://www.htslib.org/doc/bgzip.html) files, such as those created by bgzip, using coordinates from the uncompressed file. The module is used in @gmod/indexedfasta to read bgzip-indexed fasta files (with gzi index, fai index, and fa).
66

77
Users can also use the `unzip` function to unzip bgzip files whole (which pako has trouble with natively)
88

eslint.config.mjs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import prettier from 'eslint-plugin-prettier'
2+
import typescriptEslint from '@typescript-eslint/eslint-plugin'
3+
import tsParser from '@typescript-eslint/parser'
4+
import path from 'node:path'
5+
import { fileURLToPath } from 'node:url'
6+
import js from '@eslint/js'
7+
import { FlatCompat } from '@eslint/eslintrc'
8+
9+
const __filename = fileURLToPath(import.meta.url)
10+
const __dirname = path.dirname(__filename)
11+
const compat = new FlatCompat({
12+
baseDirectory: __dirname,
13+
recommendedConfig: js.configs.recommended,
14+
allConfig: js.configs.all,
15+
})
16+
17+
export default [
18+
...compat.extends(
19+
'plugin:@typescript-eslint/recommended',
20+
'plugin:@typescript-eslint/recommended-type-checked',
21+
'plugin:@typescript-eslint/stylistic-type-checked',
22+
'plugin:prettier/recommended',
23+
'plugin:unicorn/recommended',
24+
),
25+
{
26+
plugins: {
27+
prettier,
28+
'@typescript-eslint': typescriptEslint,
29+
},
30+
31+
languageOptions: {
32+
parser: tsParser,
33+
ecmaVersion: 5,
34+
sourceType: 'script',
35+
36+
parserOptions: {
37+
project: './tsconfig.lint.json',
38+
},
39+
},
40+
41+
rules: {
42+
'no-underscore-dangle': 0,
43+
curly: 'error',
44+
'unicorn/prefer-node-protocol': 0,
45+
'unicorn/numeric-separators-style': 0,
46+
'unicorn/prevent-abbreviations': 0,
47+
'unicorn/no-new-array': 0,
48+
'unicorn/filename-case': 0,
49+
'@typescript-eslint/restrict-template-expressions': 0,
50+
'@typescript-eslint/no-explicit-any': 0,
51+
'@typescript-eslint/explicit-module-boundary-types': 0,
52+
'@typescript-eslint/ban-ts-comment': 0,
53+
semi: ['error', 'never'],
54+
},
55+
},
56+
]

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
module.exports = {
33
preset: 'ts-jest',
44
testEnvironment: 'node',
5-
};
5+
}

package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
],
2222
"scripts": {
2323
"test": "jest",
24-
"lint": "eslint src test",
24+
"lint": "eslint --report-unused-disable-directives --max-warnings 0 src test",
2525
"clean": "rimraf dist esm",
2626
"prebuild": "npm run clean",
2727
"build:esm": "tsc --target es2018 --outDir esm",
@@ -44,17 +44,18 @@
4444
"@types/es6-promisify": "^6.0.0",
4545
"@types/jest": "^29.5.2",
4646
"@types/long": "^4.0.1",
47-
"@types/node": "^18.11.16",
47+
"@types/node": "^20.14.11",
4848
"@types/pako": "^2.0.0",
49-
"@typescript-eslint/eslint-plugin": "^5.59.9",
50-
"@typescript-eslint/parser": "^5.59.9",
51-
"eslint": "^8.42.0",
52-
"eslint-config-prettier": "^8.8.0",
49+
"@typescript-eslint/eslint-plugin": "^7.7.1",
50+
"@typescript-eslint/parser": "^7.7.1",
51+
"eslint": "^9.7.0",
52+
"eslint-config-prettier": "^9.1.0",
5353
"eslint-plugin-import": "^2.27.5",
54-
"eslint-plugin-prettier": "^4.2.1",
54+
"eslint-plugin-prettier": "^5.1.3",
55+
"eslint-plugin-unicorn": "^54.0.0",
5556
"jest": "^29.5.0",
56-
"prettier": "^2.8.8",
57-
"rimraf": "^5.0.1",
57+
"prettier": "^3.2.5",
58+
"rimraf": "^6.0.1",
5859
"ts-jest": "^29.1.0",
5960
"typescript": "^5.1.3"
6061
},

src/bgzFilehandle.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ export default class BgzFilehandle {
5050
async getUncompressedFileSize() {
5151
// read the last block's ISIZE (see gzip RFC),
5252
// and add it to its uncompressedPosition
53-
const [, uncompressedPosition] = await this.gzi.getLastBlock()
53+
const ret = await this.gzi.getLastBlock()
54+
if (!ret) {
55+
throw new Error('no blocks')
56+
}
57+
const [, uncompressedPosition] = ret
5458

5559
const { size } = await this.filehandle.stat()
5660

@@ -72,7 +76,8 @@ export default class BgzFilehandle {
7276
) {
7377
let next = nextCompressedPosition
7478
if (!next) {
75-
next = (await this.filehandle.stat()).size
79+
const stat = await this.filehandle.stat()
80+
next = stat.size
7681
}
7782

7883
// read the compressed data into the block buffer
@@ -90,7 +95,7 @@ export default class BgzFilehandle {
9095
blockBuffer.slice(0, blockCompressedLength),
9196
)
9297

93-
return unzippedBuffer as Buffer
98+
return unzippedBuffer
9499
}
95100

96101
async read(buf: Buffer, offset: number, length: number, position: number) {
@@ -108,7 +113,6 @@ export default class BgzFilehandle {
108113
blockNum < blockPositions.length - 1;
109114
blockNum += 1
110115
) {
111-
// eslint-disable-next-line no-await-in-loop
112116
const uncompressedBuffer = await this._readAndUncompressBlock(
113117
blockBuffer,
114118
blockPositions[blockNum],

src/gziIndex.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const UNCOMPRESSED_POSITION = 1
88
export default class GziIndex {
99
filehandle: GenericFilehandle
1010

11-
index?: any
11+
index?: Promise<[number, number][]>
1212

1313
constructor({
1414
filehandle,
@@ -46,15 +46,15 @@ export default class GziIndex {
4646
return this.index
4747
}
4848

49-
async _readIndex() {
49+
async _readIndex(): Promise<[number, number][]> {
5050
let buf = Buffer.allocUnsafe(8)
5151
await this.filehandle.read(buf, 0, 8, 0)
5252
const numEntries = this._readLongWithOverflow(buf, 0, true)
5353
if (!numEntries) {
5454
return [[0, 0]]
5555
}
5656

57-
const entries = new Array(numEntries + 1)
57+
const entries = new Array(numEntries + 1) as [number, number][]
5858
entries[0] = [0, 0]
5959

6060
// TODO rewrite this to make an index-index that stays in memory
@@ -81,10 +81,7 @@ export default class GziIndex {
8181

8282
async getLastBlock() {
8383
const entries = await this._getIndex()
84-
if (!entries.length) {
85-
return undefined
86-
}
87-
return entries[entries.length - 1]
84+
return entries.at(-1)!
8885
}
8986

9087
async getRelevantBlocksForRead(length: number, position: number) {
@@ -93,11 +90,11 @@ export default class GziIndex {
9390
return []
9491
}
9592
const entries = await this._getIndex()
96-
const relevant = []
93+
const relevant = [] as [number, number][]
9794

9895
// binary search to find the block that the
9996
// read starts in and extend forward from that
100-
const compare = (entry: any, nextEntry: any) => {
97+
const compare = (entry: number[], nextEntry: number[]) => {
10198
const uncompressedPosition = entry[UNCOMPRESSED_POSITION]
10299
const nextUncompressedPosition = nextEntry
103100
? nextEntry[UNCOMPRESSED_POSITION]
@@ -144,9 +141,9 @@ export default class GziIndex {
144141
break
145142
}
146143
}
147-
if (relevant[relevant.length - 1][UNCOMPRESSED_POSITION] < endPosition) {
148-
relevant.push([])
149-
}
144+
// if (relevant.at(-1)![UNCOMPRESSED_POSITION] < endPosition) {
145+
// relevant.push([])
146+
// }
150147
return relevant
151148
}
152149
}

src/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
import BgzfFilehandle from './bgzFilehandle'
2-
import { unzip, unzipChunk, unzipChunkSlice } from './unzip'
3-
4-
export { BgzfFilehandle, unzip, unzipChunk, unzipChunkSlice }
1+
export { default as BgzfFilehandle } from './bgzFilehandle'
2+
export { unzip, unzipChunkSlice, unzipChunk } from './unzip'

src/unzip-pako.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ interface Chunk {
1212
}
1313

1414
// browserify-zlib, which is the zlib shim used by default in webpacked code,
15-
// does not properly uncompress bgzf chunks that contain more than
16-
// one bgzf block, so export an unzip function that uses pako directly
17-
// if we are running in a browser.
15+
// does not properly uncompress bgzf chunks that contain more than one bgzf
16+
// block, so export an unzip function that uses pako directly if we are running
17+
// in a browser.
18+
//
19+
//
20+
// eslint-disable-next-line @typescript-eslint/require-await
1821
async function unzip(inputData: Buffer) {
1922
try {
2023
let strm
@@ -28,15 +31,18 @@ async function unzip(inputData: Buffer) {
2831
inflator = new Inflate()
2932
//@ts-ignore
3033
;({ strm } = inflator)
34+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
3135
inflator.push(remainingInput, Z_SYNC_FLUSH)
3236
if (inflator.err) {
3337
throw new Error(inflator.msg)
3438
}
3539

40+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
3641
pos += strm.next_in
3742
chunks[i] = inflator.result as Uint8Array
3843
totalSize += chunks[i].length
3944
i += 1
45+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
4046
} while (strm.avail_in)
4147

4248
const result = new Uint8Array(totalSize)
@@ -45,20 +51,21 @@ async function unzip(inputData: Buffer) {
4551
offset += chunks[i].length
4652
}
4753
return Buffer.from(result)
48-
} catch (e) {
54+
} catch (error) {
4955
//cleanup error message
50-
if (`${e}`.match(/incorrect header check/)) {
56+
if (/incorrect header check/.test(`${error}`)) {
5157
throw new Error(
5258
'problem decompressing block: incorrect gzip header check',
5359
)
5460
}
55-
throw e
61+
throw error
5662
}
5763
}
5864

59-
// similar to pakounzip, except it does extra counting
60-
// to return the positions of compressed and decompressed
61-
// data offsets
65+
// similar to pakounzip, except it does extra counting to return the positions
66+
// of compressed and decompressed data offsets
67+
//
68+
// eslint-disable-next-line @typescript-eslint/require-await
6269
async function unzipChunk(inputData: Buffer) {
6370
try {
6471
let strm
@@ -72,6 +79,7 @@ async function unzipChunk(inputData: Buffer) {
7279
const inflator = new Inflate()
7380
// @ts-ignore
7481
;({ strm } = inflator)
82+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
7583
inflator.push(remainingInput, Z_SYNC_FLUSH)
7684
if (inflator.err) {
7785
throw new Error(inflator.msg)
@@ -83,25 +91,29 @@ async function unzipChunk(inputData: Buffer) {
8391
cpositions.push(cpos)
8492
dpositions.push(dpos)
8593

94+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
8695
cpos += strm.next_in
8796
dpos += buffer.length
97+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
8898
} while (strm.avail_in)
8999

90100
const buffer = Buffer.concat(blocks)
91101
return { buffer, cpositions, dpositions }
92-
} catch (e) {
102+
} catch (error) {
93103
//cleanup error message
94-
if (`${e}`.match(/incorrect header check/)) {
104+
if (/incorrect header check/.test(`${error}`)) {
95105
throw new Error(
96106
'problem decompressing block: incorrect gzip header check',
97107
)
98108
}
99-
throw e
109+
throw error
100110
}
101111
}
102112

103113
// similar to unzipChunk above but slices (0,minv.dataPosition) and
104114
// (maxv.dataPosition,end) off
115+
//
116+
// eslint-disable-next-line @typescript-eslint/require-await
105117
async function unzipChunkSlice(inputData: Buffer, chunk: Chunk) {
106118
try {
107119
let strm
@@ -119,6 +131,7 @@ async function unzipChunkSlice(inputData: Buffer, chunk: Chunk) {
119131
const inflator = new Inflate()
120132
// @ts-ignore
121133
;({ strm } = inflator)
134+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
122135
inflator.push(remainingInput, Z_SYNC_FLUSH)
123136
if (inflator.err) {
124137
throw new Error(inflator.msg)
@@ -136,6 +149,7 @@ async function unzipChunkSlice(inputData: Buffer, chunk: Chunk) {
136149
len = chunks[0].length
137150
}
138151
const origCpos = cpos
152+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
139153
cpos += strm.next_in
140154
dpos += len
141155

@@ -158,6 +172,7 @@ async function unzipChunkSlice(inputData: Buffer, chunk: Chunk) {
158172
}
159173
totalSize += chunks[i].length
160174
i++
175+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
161176
} while (strm.avail_in)
162177

163178
const result = new Uint8Array(totalSize)
@@ -168,14 +183,14 @@ async function unzipChunkSlice(inputData: Buffer, chunk: Chunk) {
168183
const buffer = Buffer.from(result)
169184

170185
return { buffer, cpositions, dpositions }
171-
} catch (e) {
186+
} catch (error) {
172187
//cleanup error message
173-
if (`${e}`.match(/incorrect header check/)) {
188+
if (/incorrect header check/.test(`${error}`)) {
174189
throw new Error(
175190
'problem decompressing block: incorrect gzip header check',
176191
)
177192
}
178-
throw e
193+
throw error
179194
}
180195
}
181196

0 commit comments

Comments
 (0)