Skip to content

Commit f8e2997

Browse files
committed
fix(deno): Truncate BIDSFileDeno.readBytes() value on EOF
1 parent 9e8da14 commit f8e2997

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/files/deno.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,17 @@ export class BIDSFileDeno implements BIDSFile {
9393

9494
/**
9595
* Read bytes in a range efficiently from a given file
96+
*
97+
* Reads up to size bytes, starting at offset.
98+
* If EOF is encountered, the resulting array may be smaller.
9699
*/
97100
async readBytes(size: number, offset = 0): Promise<Uint8Array> {
98101
const handle = this.#openHandle()
99102
const buf = new Uint8Array(size)
100103
await handle.seek(offset, Deno.SeekMode.Start)
101-
await handle.read(buf)
104+
const nbytes = await handle.read(buf) ?? 0
102105
handle.close()
103-
return buf
106+
return buf.subarray(0, nbytes)
104107
}
105108

106109
/**

0 commit comments

Comments
 (0)