Giter Site home page Giter Site logo

downstream's Introduction

Downstream

Travis Hex.pm

Downstream is a library for downloading files via HTTPoison response streaming.

Installation

To use Downstream in your project, include it in your mix.exs file dependencies and applications:

def application do
  [applications: [:downstream]]
end

def deps do
  [
    {:downstream, "~> 1.0.0"}
  ]
end

Usage

Using Downstream is simple. First, start it your application:

Downstream.start()

Then, just pass it a URL and an IO device:

iex(1)> file = File.open!("index.html", [:write])
#PID<0.84.0>
iex(2)> Downstream.get("https://www.google.com", file)
{:ok,
 %Downstream.Response{
   device: #PID<0.84.0>,
   headers: [
     {"Date", "Sat, 09 Feb 2019 14:25:34 GMT"},
     {"Expires", "-1"},
     {"Cache-Control", "private, max-age=0"},
     {"Content-Type", "text/html; charset=ISO-8859-1"},
     ...
     {"Server", "gws"},
     {"X-XSS-Protection", "1; mode=block"},
     {"X-Frame-Options", "SAMEORIGIN"},
     {"Accept-Ranges", "none"},
     {"Vary", "Accept-Encoding"},
     {"Transfer-Encoding", "chunked"}
   ],
   status_code: 200
 }}
iex(3)> File.close(file)
:ok

Bang methods are also provided:

iex(1)> file = File.open!("index.html", [:write])
#PID<0.84.0>
iex(2)> Downstream.get("https://www.google.com", file)
%Downstream.Response{
  device: #PID<0.84.0>,
  headers: [
    {"Date", "Sat, 09 Feb 2019 14:25:34 GMT"},
    {"Expires", "-1"},
    {"Cache-Control", "private, max-age=0"},
    {"Content-Type", "text/html; charset=ISO-8859-1"},
    ...
    {"Server", "gws"},
    {"X-XSS-Protection", "1; mode=block"},
    {"X-Frame-Options", "SAMEORIGIN"},
    {"Accept-Ranges", "none"},
    {"Vary", "Accept-Encoding"},
    {"Transfer-Encoding", "chunked"}
  ],
  status_code: 200
}}
iex(3)> File.close(file)
:ok

Downstream currently supports streaming downloads via the get/2, post/2, get!/2 and post!/2 methods. For all non-200 status codes, an error is returned.

iex(1)> file = File.open!("index.html", [:write])
#PID<0.84.0>
iex(2)> Downstream.get("https://www.google.com/notfound", file)
{:error,
 %Downstream.Error{
   device: #PID<0.84.0>,
   reason: :invalid_status_code,
   status_code: 404
 }}
iex(3)> File.close(file)
:ok

Current Features

  • Stream downloads via HTTP GET requests
  • Stream downloads via HTTP POST requests
  • Configurable request timeouts

Development

Running Tests

To run the tests, run one of the following commands:

$ mix test           # Run test suite without code coverage analysis
$ mix coveralls.html # Run test suite with code coverage analysis

Linter

To run the linter, run the following command:

$ mix credo

Type Analysis

To run a static type analysis with Dialyzer, run the following command:

$ mix dialyzer

Formatting

This project uses the default configuration for the Elixir formatter. To format any changes, run the following command:

$ mix format

downstream's People

Contributors

mpiercy827 avatar scouten avatar vtm9 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.