Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
"genomics"
],
"devDependencies": {
"@types/node": "^22.15.3",
"@types/node": "^24.3.1",
"@types/range-parser": "^1.2.7",
"@vitest/coverage-v8": "^3.0.1",
"eslint": "^9.16.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-unicorn": "^59.0.0",
"eslint-plugin-unicorn": "^60.0.0",
"prettier": "^3.4.1",
"range-parser": "^1.2.1",
"rimraf": "^6.0.0",
Expand Down
16 changes: 12 additions & 4 deletions src/localFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ export default class LocalFile implements GenericFilehandle {

public async read(length: number, position = 0) {
const arr = new Uint8Array(length)
const fd = await open(this.filename, 'r')
const res = await fd.read(arr, 0, length, position)
await fd.close()
return res.buffer.subarray(0, res.bytesRead)
let fd // Declare fd outside the try block so it's accessible in finally
try {
fd = await open(this.filename, 'r')
const res = await fd.read(arr, 0, length, position)
return res.buffer.subarray(0, res.bytesRead)
} finally {
// This block will always execute, regardless of success or error
if (fd) {
// Only close if the fd was successfully opened
await fd.close()
}
}
}

public async readFile(): Promise<Uint8Array<ArrayBuffer>>
Expand Down
Loading