summaryrefslogtreecommitdiff
path: root/js/blob.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/blob.ts')
-rw-r--r--js/blob.ts7
1 files changed, 7 insertions, 0 deletions
diff --git a/js/blob.ts b/js/blob.ts
index f2668b642..94d03c97f 100644
--- a/js/blob.ts
+++ b/js/blob.ts
@@ -118,6 +118,10 @@ function processBlobParts(
return bytes;
}
+// A WeakMap holding blob to byte array mapping.
+// Ensures it does not impact garbage collection.
+export const blobBytesWeakMap = new WeakMap<domTypes.Blob, Uint8Array>();
+
export class DenoBlob implements domTypes.Blob {
private readonly [bytesSymbol]: Uint8Array;
readonly size: number = 0;
@@ -161,6 +165,9 @@ export class DenoBlob implements domTypes.Blob {
this[bytesSymbol] = bytes;
this.size = bytes.byteLength;
this.type = type;
+
+ // Register bytes for internal private use.
+ blobBytesWeakMap.set(this, bytes);
}
slice(start?: number, end?: number, contentType?: string): DenoBlob {