3 unstable releases
0.2.1 | Jun 10, 2022 |
---|---|
0.2.0 | Mar 5, 2022 |
0.1.0 | Mar 5, 2022 |
#189 in #request
39KB
804 lines
Reqwest-File
Use web resources like regular async files.
Features
- No unsafe code (
#[forbid(unsafe_code)]
) - Tested; code coverage: 100%
Example
use reqwest_file::RequestFile;
use tokio::io::{AsyncReadExt, AsyncSeekExt};
let client = reqwest::Client::new();
let request = client.get("http://httpbin.org/base64/aGVsbG8gd29ybGQ=");
let mut file: RequestFile = RequestFile::new(request);
let mut buffer = [0; 5];
assert_eq!(file.read(&mut buffer).await.unwrap(), 5);
assert_eq!(&buffer, b"hello");
let mut buffer = [0; 5];
assert_eq!(file.seek(std::io::SeekFrom::Current(1)).await.unwrap(), 6);
assert_eq!(file.read(&mut buffer).await.unwrap(), 5);
assert_eq!(&buffer, b"world");
Documentation
lib.rs
:
This library provides the RequestFile
type that
provides an asynchronous file-like interface to a web resource.
Features
- No unsafe code (
#[forbid(unsafe_code)]
) - Tested; code coverage: 100%
Examples
use reqwest_file::RequestFile;
use tokio::io::{AsyncReadExt, AsyncSeekExt};
let client = reqwest::Client::new();
let request = client.get("http://httpbin.org/base64/aGVsbG8gd29ybGQ=");
let mut file: RequestFile = RequestFile::new(request);
let mut buffer = [0; 5];
assert_eq!(file.read(&mut buffer).await.unwrap(), 5);
assert_eq!(&buffer, b"hello");
let mut buffer = [0; 5];
assert_eq!(file.seek(std::io::SeekFrom::Current(1)).await.unwrap(), 6);
assert_eq!(file.read(&mut buffer).await.unwrap(), 5);
assert_eq!(&buffer, b"world");
Dependencies
~6–18MB
~240K SLoC