Skip to content
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

How to use Open.url with native "fetch"? #292

Open
lucasrmendonca opened this issue Feb 4, 2024 · 8 comments
Open

How to use Open.url with native "fetch"? #292

lucasrmendonca opened this issue Feb 4, 2024 · 8 comments

Comments

@lucasrmendonca
Copy link

How do I use Open.url with native "fetch" on Node.js v20.9.0 ?

const directory = await unzipper.Open.url(fetch, 'https://www.dwsamplefiles.com/?dl_id=559');
TypeError: Failed to parse URL from [object Object]
    at Object.fetch (node:internal/deps/undici/undici:11372:11) {
  [cause]: TypeError: Invalid URL
      at new URL (node:internal/url:775:36)
      at new _Request (node:internal/deps/undici/undici:5055:25)
      at fetch2 (node:internal/deps/undici/undici:9195:25)
      at Object.fetch (node:internal/deps/undici/undici:11370:18)
      at fetch (node:internal/process/pre_execution:282:25)
      at /home/<user>/<project>/node_modules/unzipper/lib/Open/index.js:59:21
      at Promise._execute (/home/<user>/<project>/node_modules/bluebird/js/release/debuggability.js:300:9)
      at Promise._resolveFromExecutor (/home/<user>/<project>/node_modules/bluebird/js/release/promise.js:481:18)
      at new Promise (/home/<user>/<project>/node_modules/bluebird/js/release/promise.js:77:14)
      at Object.size (/home/<user>/<project>/node_modules/unzipper/lib/Open/index.js:58:16)
      at centralDirectory (/home/<user>/<project>/node_modules/unzipper/lib/Open/directory.js:93:17)
      at Object.url (/home/<user>/<project>/node_modules/unzipper/lib/Open/index.js:71:12)
      at start (file:///home/<user>/<project>/index.js:120:45) {
    code: 'ERR_INVALID_URL',
    input: '[object Object]'
  }
}
@sethtjf
Copy link

sethtjf commented Mar 17, 2024

did you ever get this working?

@lucasrmendonca
Copy link
Author

lucasrmendonca commented Mar 19, 2024

Nope, I went with Open.file instead of Open.url since the latter seems to only work with the "requests" library and I didn't want to install an extra dependency just for that

@ZJONSSON
Copy link
Owner

It would make sense to move to fetch (ideally with backward compatibility for request)

@rdsedmundo
Copy link

I was also looking for that because request is now deprecated and also has an open CVE.

@ZJONSSON
Copy link
Owner

Open to PRs, if not I will find time to do this at some point, hopefully soon!

@jpambrun
Copy link

I just stumbled on this issue.

It's not a complete solution, but I have a start of an implementation with fetch in this issue #309 (comment). I needs better error handling which I am struggling with.

@sethtjf
Copy link

sethtjf commented Apr 28, 2024

I was able to hack something together using got but found it unreliable for my use case bc of the location of the central directory at the end of the zip file.

@ecofi
Copy link

ecofi commented Jul 22, 2024

May I ask whether the .url method would have any benefits compared to .buffer()?

Am I write that the received directory variable would be of same size regardless whether .url() or .buffer() is used?
In this case, the only benefit for .url() would be to save memory in avoiding the zip file fully loaded to a buffer first?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants