rseek

Crates.iorseek
lib.rsrseek
version0.3.0
created_at2025-03-20 17:46:18.885283+00
updated_at2025-06-10 04:01:22.379272+00
descriptionrseek is an adapter for reqwest that allows seeking in the response body stream using AsyncSeek
homepage
repositoryhttps://github.com/sam0x17/rseek
max_upload_size
id1599517
size62,395
Sam Johnson (sam0x17)

documentation

https://docs.rs/rseek/latest/rseek/

README

Crates.io docs.rs Build Status MIT License

Provides a seekable and asynchronous read interface for reqwest HTTP streams that allows you to seek forward or backward in an HTTP stream without having to download all the intermediate data. This is useful for handling large files over HTTP where random access is required.

Example

use reqwest::Client;
use tokio::io::{AsyncReadExt, AsyncSeekExt, SeekFrom};

#[tokio::main]
async fn main() {
    use rseek::Seekable;
    let client = Client::new();
    let mut stream = Seekable::new(move || client.get("https://example.com/largefile.bin")).await;

    let mut buf = vec![0u8; 16];
    stream.read_exact(&mut buf).await.unwrap();
    println!("First 16 bytes: {:?}", buf);

    stream.seek(SeekFrom::Start(1_000_000)).await.unwrap();
    stream.read_exact(&mut buf).await.unwrap();
    println!("Bytes after seeking to 1MB: {:?}", buf);
 }

Notes

  • This implementation assumes the server supports HTTP range requests. Servers that do not support range requests are still usable, however certain seeking features will be unavailable.
  • If the file size cannot be determined, the implementation will attempt to fetch data without bounds, relying on the server to handle the request appropriately.

Errors

  • Returns UnexpectedEof if attempting to read past the end of the file.
  • Returns InvalidInput if seeking to a negative position.
  • Returns Unsupported if seeking from the end when the file size is unknown.
Commit count: 54

cargo fmt