How to use Open.url with native "fetch"?
lucasrmendonca opened this issue · 8 comments
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]'
}
}
did you ever get this working?
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
It would make sense to move to fetch (ideally with backward compatibility for request)
I was also looking for that because request
is now deprecated and also has an open CVE.
Open to PRs, if not I will find time to do this at some point, hopefully soon!
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.
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.
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?