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 <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
anonrig authored Oct 10, 2022
1 parent 78d280a commit 76229fc
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 76229fc

Please sign in to comment.