From 008b806d8453a50bbddd5f2cb9201de9cbff0561 Mon Sep 17 00:00:00 2001 From: Borewit Date: Sat, 4 Jan 2025 18:33:32 +0100 Subject: [PATCH] Properly close web-stream-tokenizer Add unit tests for web-stream --- lib/core.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/core.ts b/lib/core.ts index 91e787530..b2441108e 100644 --- a/lib/core.ts +++ b/lib/core.ts @@ -39,8 +39,13 @@ export async function parseBlob(blob: Blob, options: IOptions = {}): Promise { - return parseFromTokenizer(fromWebStream(webStream, {fileInfo: typeof fileInfo === 'string' ? {mimeType: fileInfo} : fileInfo}), options); +export async function parseWebStream(webStream: AnyWebByteStream, fileInfo?: IFileInfo | string, options: IOptions = {}): Promise { + const tokenizer = fromWebStream(webStream, {fileInfo: typeof fileInfo === 'string' ? {mimeType: fileInfo} : fileInfo}); + try { + return await parseFromTokenizer(tokenizer, options); + } finally { + await tokenizer.close(); + } } /**