From 76229fc216ffefc9e470b79bcab1752fd78e68ae Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Mon, 10 Oct 2022 18:11:54 +0300 Subject: [PATCH] buffer: initialize TextDecoder once on blob.text() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/44787 Reviewed-By: Michaƫl Zasso Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Antoine du Hamel Reviewed-By: Trivikram Kamat --- lib/internal/blob.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/internal/blob.js b/lib/internal/blob.js index 8014a1bb5b0349..397bffabba7b5a 100644 --- a/lib/internal/blob.js +++ b/lib/internal/blob.js @@ -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()); }