Skip to content

Commit

Permalink
buffer: initialize TextDecoder once on blob.text()
Browse files Browse the repository at this point in the history
PR-URL: #44787
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
  • Loading branch information
anonrig authored and danielleadams committed Oct 11, 2022
1 parent 281fd7a commit 725be0e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/internal/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ let ReadableStream;
let URL;

const enc = new TextEncoder();
let dec;

// Yes, lazy loading is annoying but because of circular
// references between the url, internal/blob, and buffer
Expand Down Expand Up @@ -311,7 +312,8 @@ class Blob {
if (!isBlob(this))
throw new ERR_INVALID_THIS('Blob');

const dec = new TextDecoder();
dec ??= new TextDecoder();

return dec.decode(await this.arrayBuffer());
}

Expand Down

0 comments on commit 725be0e

Please sign in to comment.