-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
rust-s3
backend. (#30)
* Add support for `rust-s3` backend. * Significantly simplify error code. * Re-export s3 and reqwest crates. * Update README.
- Loading branch information
1 parent
e95a0a3
commit 29be5e0
Showing
14 changed files
with
190 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "pmtiles" | ||
version = "0.5.2" | ||
version = "0.6.0" | ||
edition = "2021" | ||
authors = ["Luke Seelenbinder <[email protected]>"] | ||
license = "MIT OR Apache-2.0" | ||
|
@@ -13,6 +13,8 @@ categories = ["science::geo"] | |
[features] | ||
default = [] | ||
http-async = ["dep:tokio", "dep:reqwest"] | ||
s3-async-native = ["dep:tokio", "dep:rust-s3", "rust-s3/tokio-native-tls"] | ||
s3-async-rustls = ["dep:tokio", "dep:rust-s3", "rust-s3/tokio-rustls-tls"] | ||
mmap-async-tokio = ["dep:tokio", "dep:fmmap", "fmmap?/tokio-async"] | ||
tilejson = ["dep:tilejson", "dep:serde", "dep:serde_json"] | ||
|
||
|
@@ -34,6 +36,7 @@ thiserror = "1" | |
tilejson = { version = "0.4", optional = true } | ||
tokio = { version = "1", default-features = false, features = ["io-util"], optional = true } | ||
varint-rs = "2" | ||
rust-s3 = { version = "0.33.0", optional = true, default-features = false, features = ["fail-on-err"] } | ||
|
||
[dev-dependencies] | ||
flate2 = "1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#[cfg(any(feature = "s3-async-native", feature = "s3-async-rustls"))] | ||
mod s3; | ||
|
||
#[cfg(any(feature = "s3-async-native", feature = "s3-async-rustls"))] | ||
pub use s3::S3Backend; | ||
|
||
#[cfg(feature = "http-async")] | ||
mod http; | ||
|
||
#[cfg(feature = "http-async")] | ||
pub use http::HttpBackend; | ||
|
||
#[cfg(feature = "mmap-async-tokio")] | ||
mod mmap; | ||
|
||
#[cfg(feature = "mmap-async-tokio")] | ||
pub use mmap::MmapBackend; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use async_trait::async_trait; | ||
use bytes::Bytes; | ||
use s3::Bucket; | ||
|
||
use crate::{ | ||
async_reader::AsyncBackend, | ||
error::PmtError::{ResponseBodyTooLong, UnexpectedNumberOfBytesReturned}, | ||
}; | ||
|
||
pub struct S3Backend { | ||
bucket: Bucket, | ||
pmtiles_path: String, | ||
} | ||
|
||
impl S3Backend { | ||
#[must_use] | ||
pub fn from(bucket: Bucket, pmtiles_path: String) -> S3Backend { | ||
Self { | ||
bucket, | ||
pmtiles_path, | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl AsyncBackend for S3Backend { | ||
async fn read_exact(&self, offset: usize, length: usize) -> crate::error::PmtResult<Bytes> { | ||
let data = self.read(offset, length).await?; | ||
|
||
if data.len() == length { | ||
Ok(data) | ||
} else { | ||
Err(UnexpectedNumberOfBytesReturned(length, data.len())) | ||
} | ||
} | ||
|
||
async fn read(&self, offset: usize, length: usize) -> crate::error::PmtResult<Bytes> { | ||
let response = self | ||
.bucket | ||
.get_object_range( | ||
self.pmtiles_path.as_str(), | ||
offset as _, | ||
Some((offset + length - 1) as _), | ||
) | ||
.await?; | ||
|
||
let response_bytes = response.bytes(); | ||
|
||
if response_bytes.len() > length { | ||
Err(ResponseBodyTooLong(response_bytes.len(), length)) | ||
} else { | ||
Ok(response_bytes.clone()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.