URL.createObjectURL(blob)
稳定性: 1 - 实验性
创建一个 'blob:nodedata:...' URL 字符串,该字符串表示给定的 <Blob> 对象,并可用于稍后检索 Blob。
【Creates a 'blob:nodedata:...' URL string that represents the given <Blob>
object and can be used to retrieve the Blob later.】
const {
Blob,
resolveObjectURL,
} = require('node:buffer');
const blob = new Blob(['hello']);
const id = URL.createObjectURL(blob);
// later...
const otherBlob = resolveObjectURL(id);
console.log(otherBlob.size); 已注册的 <Blob> 存储的数据将保留在内存中,直到调用 URL.revokeObjectURL() 将其移除为止。
【The data stored by the registered <Blob> will be retained in memory until
URL.revokeObjectURL() is called to remove it.】
Blob 对象在当前线程中注册。如果使用 Worker 线程,在一个 Worker 中注册的 Blob 对象将无法在其他 Worker 或主线程中使用。