Skip to content

Commit eb6e002

Browse files
committed
fix: Clean up stream reader for BIDSFileDeno.text()
1 parent 9dc329a commit eb6e002

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/files/deno.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,18 @@ export class BIDSFileDeno implements BIDSFile {
5858
* Read the entire file and decode as utf-8 text
5959
*/
6060
async text(): Promise<string> {
61-
let chunks: string[] = []
62-
for await (const chunk of this.stream.pipeThrough(createUTF8Stream())) {
63-
chunks.push(chunk)
61+
const reader = this.stream.pipeThrough(createUTF8Stream()).getReader()
62+
const chunks: string[] = []
63+
try {
64+
while (true) {
65+
const { done, value } = await reader.read()
66+
if (done) break
67+
chunks.push(value)
68+
}
69+
return chunks.join('')
70+
} finally {
71+
reader.releaseLock()
6472
}
65-
return chunks.join('')
6673
}
6774

6875
/**

0 commit comments

Comments
 (0)