Skip to content
Prev Previous commit
Next Next commit
Move encoder initialization outside the loop
  • Loading branch information
octet-stream committed Sep 27, 2021
commit 238c2fb445986e4317099e6071ed0f7c23a59af8
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const _Blob = class Blob {

if (options === null) options = {};

const encoder = new TextEncoder()
for (const element of blobParts) {
let part;
if (ArrayBuffer.isView(element)) {
Expand All @@ -119,7 +120,7 @@ const _Blob = class Blob {
} else if (element instanceof Blob) {
part = element;
} else {
part = new TextEncoder().encode(element);
part = encoder.encode(element);
}

this.#size += ArrayBuffer.isView(part) ? part.byteLength : part.size;
Expand Down