-
|
I made this page (source code here) to demonstrate what seems to be a bug to me: Pulling a single svg out of a zip file works, with const logos = await FileAttachment("zip").zip();
await logos.file("image.svg").image();that will fail here in stdlib, trying to convert the file to an Is it expected that this should work, or do I have a mistaken expectation? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Unfortunately, I don’t think The You can workaround this by constructing the Blob yourself with the appropriate const logos = await FileAttachment("logos.zip").zip();
const data = await logos.file("_tbd.svg").arrayBuffer();
const blob = new Blob([data], {type: "image/svg+xml"});
const url = URL.createObjectURL(blob);
const image = new Image;
image.src = url;
display(image); |
Beta Was this translation helpful? Give feedback.
Unfortunately, I don’t think
file.image()can work with an SVG image within a ZIP file because the MIME type of the data isn’t known, so the browser can’t infer that you’re trying to display an SVG image.The
file.image()method is implemented usingfile.url()which callsfile.blob(), and the Blob that is constructed by JSZip doesn’t specify a MIME type (because JSZip doesn’t know that_tbd.svgis an SVG file and it doesn’t have an internal database mapping file extensions to MIME types). And so the browser doesn’t know how to display the resulting image.You can workaround this by constructing the Blob yourself with the appropriate
image/svg+xmlMIME type: