Skip to content

Commit

Permalink
feat: πŸŽ‰ add support for resolving data URIs in files
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Jan 22, 2025
1 parent 5bb053c commit 4700c27
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/core/src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,13 @@ export async function resolveFileBytes(
filename: string,
options?: TraceOptions
): Promise<Uint8Array> {
if (/^data:/i.test(filename)) {
const matches = filename.match(/^data:[^;]+;base64,(.*)$/i)
if (!matches) throw new Error("Invalid data URI format")
return fromBase64(matches[1])
}
// Fetch file from URL or data-uri
if (/^https?:\/\//i.test(filename) || /^data:/i.test(filename)) {
if (/^https?:\/\//i.test(filename)) {
const fetch = await createFetch(options)
const resp = await fetch(filename)
const buffer = await resp.arrayBuffer()
Expand Down

0 comments on commit 4700c27

Please sign in to comment.