Skip to content

Commit

Permalink
Add seek test
Browse files Browse the repository at this point in the history
  • Loading branch information
pka committed Aug 29, 2023
1 parent e093487 commit cfd957a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
9 changes: 3 additions & 6 deletions src/buffered_range_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ mod test_async {
#[cfg(feature = "sync")]
mod test_sync {
use crate::{BufferedHttpRangeClient, Result};
use std::io::Read;
use std::io::{Read, Seek, SeekFrom};

#[test]
fn http_read_sync() -> Result<()> {
Expand All @@ -199,12 +199,9 @@ mod test_sync {

let mut client =
BufferedHttpRangeClient::new("https://flatgeobuf.org/test/data/countries.fgb");
let mut bytes = [0; 3];
client.min_req_size(256).read_exact(&mut bytes)?;
assert_eq!(&bytes, b"fgb");

let _pos = client.seek(SeekFrom::Start(3));
let mut version = [0; 1];
client.read_exact(&mut version)?;
client.min_req_size(256).read_exact(&mut version)?;
assert_eq!(&version, &[3]);

let mut bytes = [0; 3];
Expand Down
11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@
//! // Seek+Read API (with feature `sync`):
//! # #[cfg(feature = "sync")]
//! # fn read() -> std::io::Result<()> {
//! use std::io::Read;
//! use std::io::{Read, Seek, SeekFrom};
//! let mut client = BufferedHttpRangeClient::new("https://flatgeobuf.org/test/data/countries.fgb");
//! let mut bytes = [0; 3];
//! client.min_req_size(256).read_exact(&mut bytes)?;
//! assert_eq!(&bytes, b"fgb");
//! let _pos = client.seek(SeekFrom::Start(3));
//! let mut version = [0; 1];
//! client.read_exact(&mut version)?;
//! client.min_req_size(256).read_exact(&mut version)?;
//! assert_eq!(&version, &[3]);
//! let mut bytes = [0; 3];
//! client.read_exact(&mut bytes)?;
//! assert_eq!(&bytes, b"fgb");
//! # Ok(())
//! # }
//! ```
Expand Down

0 comments on commit cfd957a

Please sign in to comment.