Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync reader with Seek+Read implementation #5

Merged
merged 14 commits into from
Aug 31, 2023
22 changes: 9 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- wasm32-unknown-unknown

name: Build Check ${{ matrix.target }}
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
Expand All @@ -28,7 +28,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: check
args: --target ${{matrix.target}} --all-features
args: --target ${{matrix.target}} --no-default-features --features=reqwest-async

test:
strategy:
Expand All @@ -37,7 +37,7 @@ jobs:
- x86_64-unknown-linux-gnu

name: Test ${{ matrix.target }}
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
Expand All @@ -60,14 +60,10 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --target ${{matrix.target}} --all-features

# This is currently broken because
# reqwest is not actually optional
#
# - name: test --no-default-features
# uses: actions-rs/cargo@v1
# with:
# command: test
# args: --target ${{matrix.target}} --no-default-features
args: --target ${{matrix.target}} --all-features -- --test-threads 1

- name: test --no-default-features
uses: actions-rs/cargo@v1
with:
command: test
args: --target ${{matrix.target}} --no-default-features
14 changes: 10 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ license = "MIT/Apache-2.0"
keywords = ["http", "reader", "buffer"]

[features]
default = ["reqwest"]
default = ["reqwest-sync", "reqwest-async"]
reqwest-async = ["reqwest"]
reqwest-sync = ["reqwest/blocking"]

[dependencies]
async-trait = "0.1.51"
byteorder = "1.4.2"
bytes = "1.0.1"
log = "0.4.13"
reqwest = { version = "0.11.0", default-features = false, features = ["default-tls"], optional = true }
bytes = { version = "1.0.1" }
thiserror = "1.0"
log = "0.4.13"
async-trait = "0.1.51"

[dev-dependencies]
env_logger = "0.10.0"
tokio = { version = "1.0.2", default-features = false, features = ["rt-multi-thread", "macros"] }

[package.metadata.docs.rs]
all-features = true
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@

HTTP client for HTTP Range requests with a buffer optimized for sequential requests.

Implements Seek+Read for blocking clients, which makes it a drop-in replacement for local files.

Usage example:
Usage examples:

use http_range_client::*;

let mut client = BufferedHttpRangeClient::new("https://flatgeobuf.org/test/data/countries.fgb");
let bytes = client.get_range(0, 3, 256).await?;
assert_eq!(bytes, "fgb".as_bytes());
let bytes = client.min_req_size(256).get_range(0, 3).await?;
assert_eq!(bytes, b"fgb");
let version = client.get_bytes(1).await?; // From buffer - no HTTP request!
assert_eq!(version, [3]);

let mut client =
HttpReader::new("https://www.rust-lang.org/static/images/favicon-32x32.png");
client.seek(SeekFrom::Start(1)).ok();
let mut bytes = [0; 3];
client.read_exact(&mut bytes)?;
assert_eq!(&bytes, b"PNG");
Loading
Loading