Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] Lazyfetch array with objects instead of urls #60

Closed
StavrosHacker opened this issue Apr 10, 2023 · 1 comment
Closed

[QUESTION] Lazyfetch array with objects instead of urls #60

StavrosHacker opened this issue Apr 10, 2023 · 1 comment
Labels
question Further information is requested

Comments

@StavrosHacker
Copy link

StavrosHacker commented Apr 10, 2023

I've been using client-zip on deno to zip-on-the-fly some files on my origin server using the following code:

async function *lazyFetch() {
      for (const url of urls) yeild await fetch(url)
}

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:

let files = [
    {
        name: "folder1/file1.txt",
        size: 123,
        input: "https://file-download-url.com/file"
    }
]

and lazyfetch it. Is this doable?

Thank you.

@Touffy Touffy added the question Further information is requested label Apr 10, 2023
@Touffy
Copy link
Owner

Touffy commented Apr 10, 2023

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 files array in the metadata option, so that downloadZip will set the correct Content-Length header (assuming your sizes are accurate, of course) :

const zipResponse = downloadZip(lazyFetch(), { metadata: files })

@Touffy Touffy closed this as completed Apr 10, 2023
Repository owner locked and limited conversation to collaborators May 14, 2023
@Touffy Touffy converted this issue into discussion #65 May 14, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants