From 99458778b529b79d5025a1a6d782a774b5163a5a Mon Sep 17 00:00:00 2001 From: Borewit Date: Sun, 13 Oct 2024 22:02:05 +0200 Subject: [PATCH] Ensure web-stream is released after detection (#680) --- index.js | 2 +- package.json | 2 +- test.js | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 2dcea75e..3c93e822 100644 --- a/index.js +++ b/index.js @@ -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(); } diff --git a/package.json b/package.json index 16e10a3b..334741bc 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test.js b/test.js index b76651af..8fe883d8 100644 --- a/test.js +++ b/test.js @@ -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)); }