Lazyfetch array with objects instead of urls #65
-
|
I've been using client-zip on deno to zip-on-the-fly some files on my origin server using the following code: However with this way I cannot put files in different folders. I would like to be able to have an array with an object for each file, for example: and lazyfetch it. Is this doable? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Absolutely. We get a Response as usual, and instead of yielding it by itself, we put it in an object with its desired filename: async function *lazyFetch() {
for (const { name, input } of files) yield { name, input: await fetch(input) }
}I didn't copy the 'size' property because it doesn't do anything when actually making the Zip. You can pass your original const zipResponse = downloadZip(lazyFetch(), { metadata: files }) |
Beta Was this translation helpful? Give feedback.
Absolutely. We get a Response as usual, and instead of yielding it by itself, we put it in an object with its desired filename:
I didn't copy the 'size' property because it doesn't do anything when actually making the Zip. You can pass your original
filesarray in themetadataoption, so thatdownloadZipwill set the correct Content-Length header (assuming your sizes are accurate, of course) :