dsherret / dax

Cross-platform shell tools for Deno and Node.js inspired by zx.
MIT License
1.05k stars 35 forks source link

Add an api to download files to disk #54

Closed sigmaSd closed 1 year ago

sigmaSd commented 1 year ago

Maybe it could be another override to request

the advantage it would skip loading the file into memory while keeping the cool progress bar

sigmaSd commented 1 year ago

With fetch I can do

 const imageFile = Deno.createSync(imagePath);
await fetch(imageUrl).then((r) => r.body?.pipeTo(imageFile.writable));

but request doesn't seem to expose body in the response

dsherret commented 1 year ago

Good idea! There will be a pipeToPath method in the next release along with pipeTo and pipeThrough methods.

sigmaSd commented 1 year ago

thanks really cool!

sigmaSd commented 1 year ago

what about making pipeToPath defaults to figuring out the path from the url url.pathname.split('/').at(-1) I think wget act like this?

dsherret commented 1 year ago

I was wondering about it too and it seems reasonable. The one thing I wasn't sure about was what to do for a path that's just a domain like https://deno.land (so /)... I think in those cases it should just throw? Would you like to open a PR for that? Otherwise I can get to it soon.

sigmaSd commented 1 year ago

I'm not sure about the idea either, the current api you implemented is very clear though, maybe we give it some time and wait for more interesting use cases?

dsherret commented 1 year ago

I ended up implementing it in #59

sigmaSd commented 1 year ago

Nice