#file-content #warp #range #filter #file-serving #mp3

warp-range

Warp filter for serving file content with range like mp3 audio or mp4 video

4 releases (stable)

2.0.0 Feb 17, 2022
1.0.1 Jan 22, 2022
0.1.0 Jun 17, 2021

#1160 in HTTP server

Download history 1/week @ 2024-04-26 9/week @ 2024-05-10 3/week @ 2024-05-17 40/week @ 2024-05-24 26/week @ 2024-05-31 1/week @ 2024-06-07 19/week @ 2024-06-21 19/week @ 2024-06-28 9/week @ 2024-07-05 50/week @ 2024-07-26

62 downloads per month

MIT license

12KB
98 lines

warp-range

A Rust library for creating a warp filter for serving file content with range like mp3 audio or mp4 video. This warp filter can be used in a HTTP server based on warp.

The content is served like streaming. If you view a movie served by this filter, you can seek through it even if the file is not completely downloaded.


lib.rs:

warp-range

A Rust library for creating a warp filter for serving file content with range like mp3 audio or mp4 video. This warp filter can be used in a HTTP server based on warp.

The content is served like streaming. If you view a movie served by this filter, you can seek through it even if the file is not completely downloaded.

Here is an easy example to add range to an existing warp server:

use hyper::{Body, Response};
use warp::{Filter, Reply, fs::{File, dir}};
use warp_range::{filter_range, get_range};

#[tokio::main]
async fn main() {
    let test_video = "/home/uwe/Videos/Drive.mkv";
    
    let port = 9860;
    println!("Running test server on http://localhost:{}", port);

    let route_get_range = 
        warp::path("getvideo")
        .and(warp::path::end())
        .and(filter_range())
        .and_then(move |range_header| get_range(range_header, test_video, "video/mp4"))

    let route_static = dir(".");
    
    let routes = route_get_range
        .or(route_static);

    warp::serve(routes)
        .run(([127, 0, 0, 1], port))
        .await;    
}

Dependencies

~9–19MB
~253K SLoC