Skip to content

Commit

Permalink
Ensure web-stream is released after detection (#680)
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit authored Oct 13, 2024
1 parent 0e91f7b commit 9945877
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class NodeFileTypeParser extends FileTypeParser {
async fromStream(stream) {
const tokenizer = await (stream instanceof WebReadableStream ? strtok3.fromWebStream(stream, this.tokenizerOptions) : strtok3.fromStream(stream, this.tokenizerOptions));
try {
return super.fromTokenizer(tokenizer);
return await super.fromTokenizer(tokenizer);
} finally {
await tokenizer.close();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
],
"dependencies": {
"get-stream": "^9.0.1",
"strtok3": "^9.0.0",
"strtok3": "^9.0.1",
"token-types": "^6.0.0",
"uint8array-extras": "^1.3.0"
},
Expand Down
2 changes: 2 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ async function testStreamWithWebStream(t, ext, name) {
// Create a Blob from the buffer
const blob = new Blob([fileBuffer]);
const webStream = await fileTypeStream(blob.stream());
t.false(webStream.locked);
const webStreamResult = await getStreamAsUint8Array(webStream);
t.false(webStream.locked, 'Ensure web-stream is released');
t.true(areUint8ArraysEqual(fileBuffer, webStreamResult));
}

Expand Down

0 comments on commit 9945877

Please sign in to comment.