Skip to content

Commit 725be0e

Browse files
anonrigdanielleadams
authored andcommitted
buffer: initialize TextDecoder once on blob.text()
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>
1 parent 281fd7a commit 725be0e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/internal/blob.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ let ReadableStream;
7878
let URL;
7979

8080
const enc = new TextEncoder();
81+
let dec;
8182

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

314-
const dec = new TextDecoder();
315+
dec ??= new TextDecoder();
316+
315317
return dec.decode(await this.arrayBuffer());
316318
}
317319

0 commit comments

Comments
 (0)