I wrote a download elixir package which does exactly what its name about - an easy way to download files.
I saw solutions about how to do it with HTTPoison but these solutions have disadvantages:
The whole response is loading to the RAM, and only after then is going to the File.write/1. You have to choose async HTTPoison request to escape high memory consumption.
There is no restriction of the file size to download. If you handle, saying, user input and then you’re trying to download any file user provided, your server can go down for downloading a file which has 1TB size.
download depends on HTTPoison and successfully sidestep these issues.
I do not like that page you linked @Eiji, it seems to confuse metric and binary prefixes.
Even gives megabyte as an example for binary and mebibyte as example while on the linked pages about binary and metric prefixes they are the other way round.
So I am not sure what you exactly mean by “traditional units”?
ehh, you don’t heard about lots of sites then … you are so lucky!
Imagine that you need something like:
a) go to main page (yes, it’s important)
b) click links + follow redirects + follow redirects to https version + follow redirects in JavaScript
c) submit some forms
d) look for download link (generated for current session, that is initialized at main page)
e) FINALLY: download this file - APS.NET old pages
*) optionally JavaScript code could be minimized, so it’s harder to search what it do
*) really often pages like that have invalid HTML, so your parser needs to be really well tested
Imagine that you want to download video from youtube page and you call this method with normal video page url and then finder is looking for video.
This project is about downloading a single resource from the specified URL. It does not any magic to determine what the resource actually is. It gets saved as is and then you get path of the saved file.
This is in contrast to using HTTPoison without thinking about it and loading the full response into RAM.
One can get the same behaviour with HTTPosion directly though using async requests, but this package makes it a bit easier to process those.
just as a question is that possible in Elixir and with HTTPoison to download something from Youtube? as we have dlls build in Python, Can Elixir do that too? I want to build that, But I have no clue where to start it.
At the end, it is just reading a socket and dumping received data to disk.
Important part is, that you probably need to implement the protocol used from scratch. I’m not what youtube actually uses to stream and therefore I can’t know if this protol has already been implemented in elixir or erlang.
Also to be honest, I’d just delegate to one of the many available ready-made and well supported command line downloaders and orchestrate them through a worker pool.