PlugByteServe 

This is a Plug module for adding HTTP Content-Range to a set of routes. Only single byte ranges are currently supported. Wikipedia entry on HTTP Byte Serving for more information.
Installation
Add plug_byte_serve to the deps function in your project's mix.exs file:
defp deps do
[{:plug_byte_serve, "~> 0.3.0"}]
end
Then run mix do deps.get, deps.compile inside your project's directory.
Usage
PlugByteServe can be used just as any other Plug. Add Plug.ByteServe after all of the other plugs you want to happen using the plug function.
When you know which file you want to serve
defmodule GetServed do
import Plug.Conn
use Plug.Router
plug PlugByteServe, path: "/tmp", file: "/tmp/file"
plug :match
plug :dispatch
get "/" do
conn
|> send_resp()
end
endWhen the file is dynamically found
defmodule GetServed do
import Plug.Conn
use Plug.Router
plug :match
plug :dispatch
get "/:file" do
path = "/path/to/files/"
conn
|> PlugByteServe.call([path: path, file: file])
|> send_resp()
end
endTODO
- Plug-ify byte serving code
- Proper handling of invalid range requests
-
Use
sendfilefor efficiency - Support multipart range requests
Contributing
- Fork it
-
Create your feature branch (
git checkout -b my-new-feature) -
Commit your changes (
git commit -am 'Add some feature') -
Push to the branch (
git push origin my-new-feature) - Create new Pull Request
License
Plug.BasicAuth uses the same license as Plug and the Elixir programming language. See the license file for more information.