Downstream is a thin wrapper around hackney that turns the response body of an HTTP/S request into an Elixir stream.
It also provides a convenience wrapper Downstream.download/2 that will take
care of streaming the data directly to a file at the provided output path.
Several more functions are available as well:
-
download/3allows you to provide a callback that will fire every chunk with metadata for the purposes of doing things like showing a progress indicator, but still handles streaming of the data directly to a file likedownload/2. -
stream/3returns an Elixir stream of chunks containing iodata that can be piped directly into aFile.stream!or otherCollectable. If themetadata: trueoption is provided, then these chunks will instead be aDownstream.Chunkstruct containing keys:dataand:metadatawhich may be transformed for more advanced behavior.
def deps do
[
{:downstream, "~> 0.1.0"}
]
endDownstream operates by transforming the output of repeated calls to
:hackney.stream_body/1 into an Elixir stream using Stream.resource/3, and
packaging this with the the status code and headers returned by the initial
call to :hackney.get/3, along with some useful metadata like total file
length, length downloaded, and length remaining.