( mediaPath: string, data: Uint8Array | ArrayBuffer, cache: Map<string, string> )
| 51 | * @returns The blob URL string |
| 52 | */ |
| 53 | export function getOrCreateBlobUrl( |
| 54 | mediaPath: string, |
| 55 | data: Uint8Array | ArrayBuffer, |
| 56 | cache: Map<string, string> |
| 57 | ): string { |
| 58 | let url = cache.get(mediaPath) |
| 59 | if (!url) { |
| 60 | const mime = getMimeType(mediaPath) |
| 61 | const blobPart = data instanceof ArrayBuffer ? data : copyToArrayBuffer(data) |
| 62 | const blob = new Blob([blobPart], { type: mime }) |
| 63 | url = URL.createObjectURL(blob) |
| 64 | cache.set(mediaPath, url) |
| 65 | } |
| 66 | return url |
| 67 | } |
| 68 | |
| 69 | function copyToArrayBuffer(data: Uint8Array): ArrayBuffer { |
| 70 | const copy = new Uint8Array(data.byteLength) |
no test coverage detected