#async-http #http-request #http-file #range #streaming #requests #file-access

async_http_range_reader

A library for streaming reading of files over HTTP using range requests

11 releases (7 breaking)

0.9.1 Nov 12, 2024
0.8.0 May 7, 2024
0.7.0 Feb 23, 2024
0.3.0 Oct 26, 2023

#311 in Network programming

Download history 3527/week @ 2024-08-16 3655/week @ 2024-08-23 3766/week @ 2024-08-30 2951/week @ 2024-09-06 2449/week @ 2024-09-13 2601/week @ 2024-09-20 3335/week @ 2024-09-27 3100/week @ 2024-10-04 2661/week @ 2024-10-11 2843/week @ 2024-10-18 3031/week @ 2024-10-25 2621/week @ 2024-11-01 2796/week @ 2024-11-08 2884/week @ 2024-11-15 2381/week @ 2024-11-22 2694/week @ 2024-11-29

11,154 downloads per month
Used in 4 crates (2 directly)

MIT license

47KB
841 lines

Async HTTP Range Reader

Crates.io docs.rs GitHub Workflow Status (branch) GitHub

A crate that provides the AsyncHttpRangeReader struct, which allows streaming files over HTTP using range requests.


lib.rs:

This library provides the AsyncHttpRangeReader type.

It allows streaming a file over HTTP while also allow random access. The type implements both AsyncRead as well as AsyncSeek. This is supported through the use of range requests. Each individual read will request a portion of the file using an HTTP range request.

Requesting numerous small reads might turn out to be relatively slow because each reads needs to perform an HTTP request. To alleviate this issue AsyncHttpRangeReader::prefetch is provided. Using this method you can prefect a number of bytes which will be streamed in on the background. If a read operation is reading from already (pre)fetched ranges it will stream from the internal cache instead.

Internally the AsyncHttpRangeReader stores a memory map which allows sparsely reading the data into memory without actually requiring all memory for file to be resident in memory.

The primary use-case for this library is to be able to sparsely stream a zip archive over HTTP but its designed in a generic fashion.

Dependencies

~8–18MB
~242K SLoC