Skip to content

Commit

Permalink
Properly close web-stream-tokenizer
Browse files Browse the repository at this point in the history
Add unit tests for web-stream
  • Loading branch information
Borewit committed Jan 4, 2025
1 parent ec914d1 commit 008b806
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ export async function parseBlob(blob: Blob, options: IOptions = {}): Promise<IAu
* @param fileInfo - File information object or MIME-type string
* @returns Metadata
*/
export function parseWebStream(webStream: AnyWebByteStream, fileInfo?: IFileInfo | string, options: IOptions = {}): Promise<IAudioMetadata> {
return parseFromTokenizer(fromWebStream(webStream, {fileInfo: typeof fileInfo === 'string' ? {mimeType: fileInfo} : fileInfo}), options);
export async function parseWebStream(webStream: AnyWebByteStream, fileInfo?: IFileInfo | string, options: IOptions = {}): Promise<IAudioMetadata> {
const tokenizer = fromWebStream(webStream, {fileInfo: typeof fileInfo === 'string' ? {mimeType: fileInfo} : fileInfo});
try {
return await parseFromTokenizer(tokenizer, options);
} finally {
await tokenizer.close();
}
}

/**
Expand Down

0 comments on commit 008b806

Please sign in to comment.