-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathblob.js
33 lines (28 loc) · 912 Bytes
/
blob.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { randomUUID } from 'node:crypto';
// Map to store Blob URLs and their associated Blobs
const blobUrlRegistry = new Map();
// Simulate URL.createObjectURL
function createObjectURL(blob) {
// console.log('createObjectURL', blob);
const uniqueId = randomUUID(); // Generate a unique ID for the Blob
const blobUrl = `blob:nodedata:${uniqueId}`;
blobUrlRegistry.set(blobUrl, blob);
return blobUrl;
}
// Simulate URL.revokeObjectURL
function revokeObjectURL(blobUrl) {
if (blobUrlRegistry.has(blobUrl)) {
blobUrlRegistry.delete(blobUrl);
} else {
console.warn(`Blob URL not found: ${blobUrl}`);
}
}
// Simulate fetching data from a Blob URL
function fetchBlobFromUrl(blobUrl) {
const blob = blobUrlRegistry.get(blobUrl);
if (!blob) {
throw new Error(`Blob not found for URL: ${blobUrl}`);
}
return blob;
}
export { createObjectURL, revokeObjectURL, fetchBlobFromUrl };