Skip to content

Commit

Permalink
fix: Clean up stream reader for BIDSFileDeno.text()
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Jan 10, 2025
1 parent 9dc329a commit eb6e002
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/files/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,18 @@ export class BIDSFileDeno implements BIDSFile {
* Read the entire file and decode as utf-8 text
*/
async text(): Promise<string> {
let chunks: string[] = []
for await (const chunk of this.stream.pipeThrough(createUTF8Stream())) {
chunks.push(chunk)
const reader = this.stream.pipeThrough(createUTF8Stream()).getReader()
const chunks: string[] = []
try {
while (true) {
const { done, value } = await reader.read()
if (done) break
chunks.push(value)
}
return chunks.join('')
} finally {
reader.releaseLock()
}
return chunks.join('')
}

/**
Expand Down

0 comments on commit eb6e002

Please sign in to comment.