Skip to content

Commit

Permalink
buffer: initialize TextDecoder once on blob.text()
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Sep 25, 2022
1 parent dc4398c commit b37eaa1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/internal/blob.js
Expand Up @@ -78,6 +78,7 @@ let ReadableStream;
let URL;

const enc = new TextEncoder();
let dec = undefined;

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

const dec = new TextDecoder();
if (dec === undefined) {
dec = new TextDecoder();
}

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

Expand Down

0 comments on commit b37eaa1

Please sign in to comment.