Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 9x 9x 5x 4x | import fs from 'node:fs/promises';
import url from 'node:url';
/**
* Fetch a blob of bytes from a URL
*
* This works like `fetch`, but handles `file:` URLs directly, since Node's
* `fetch` implementation chokes on those.
*
* @param blobURL - The URL of the blob to fetch.
*
* @returns a Response containing the requested blob.
*/
// eslint-disable-next-line n/no-unsupported-features/node-builtins
export async function fetchBlob(blobURL: string): Promise<Response> {
const parsedURL = new URL(blobURL);
if (parsedURL.protocol === 'file:') {
// eslint-disable-next-line n/no-unsupported-features/node-builtins
return new Response(await fs.readFile(url.fileURLToPath(parsedURL)));
}
return fetch(blobURL);
}
|