mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
buffer: initialize TextDecoder once on blob.text()
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
78d280a768
commit
76229fc216
1 changed files with 3 additions and 1 deletions
|
@ -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
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue