@huggingface/blob
Version:
Utilities to convert URLs and files to Blobs, internally used by Hugging Face libs
30 lines (26 loc) • 908 B
JavaScript
import {
WebBlob
} from "./chunk-WIMQPORG.mjs";
// src/utils/isBackend.ts
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
var isWebWorker = typeof self === "object" && self.constructor && self.constructor.name === "DedicatedWorkerGlobalScope";
var isBackend = !isBrowser && !isWebWorker;
// src/utils/isFrontend.ts
var isFrontend = !isBackend;
// src/utils/createBlob.ts
async function createBlob(url, opts) {
if (url.protocol === "http:" || url.protocol === "https:") {
return WebBlob.create(url, { fetch: opts?.fetch });
}
if (isFrontend) {
throw new TypeError(`Unsupported URL protocol "${url.protocol}"`);
}
if (url.protocol === "file:") {
const { FileBlob } = await import("./src/utils/FileBlob.mjs");
return FileBlob.create(url);
}
throw new TypeError(`Unsupported URL protocol "${url.protocol}"`);
}
export {
createBlob
};