Crates.io | reqwest-file |
lib.rs | reqwest-file |
version | 0.2.1 |
source | src |
created_at | 2022-03-05 19:37:52.544947 |
updated_at | 2022-06-10 20:45:36.72548 |
description | Use web resources like regular async files |
homepage | https://github.com/alvra/reqwest-file |
repository | https://github.com/alvra/reqwest-file |
max_upload_size | |
id | 544204 |
size | 148,095 |
Use web resources like regular async files.
#[forbid(unsafe_code)]
)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");