-
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.
* Fix lint. * Bump rust-s3 dependency. * Implement read_exact in trait. * Add aws-sdk-based S3 backend. * Update CI to use Justfile. * Fix lint. * Don't use async in trait. * Bump MSRV. * Restore necessary prefix. * Fix mismatch of MSRV and prefix lint. * Fix changed feature name. * Justfile cleanup * Don't run tests with incompatible features. * Export AWS backend. * Use async fn to avoid incorrect marker types. * Desugar async fn to add trait bounds. * Fix semver. * Fix semver features. * MR Nit fixes.
- Loading branch information
1 parent
3012fc4
commit 87c30f1
Showing
10 changed files
with
174 additions
and
66 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,13 +1,13 @@ | ||
[package] | ||
name = "pmtiles" | ||
version = "0.10.0" | ||
version = "0.11.0" | ||
edition = "2021" | ||
authors = ["Luke Seelenbinder <[email protected]>"] | ||
license = "MIT OR Apache-2.0" | ||
description = "Implementation of the PMTiles v3 spec with multiple sync and async backends." | ||
repository = "https://github.com/stadiamaps/pmtiles-rs" | ||
keywords = ["pmtiles", "gis", "geo"] | ||
rust-version = "1.77.0" | ||
rust-version = "1.81.0" | ||
categories = ["science::geo"] | ||
|
||
[features] | ||
|
@@ -16,6 +16,7 @@ http-async = ["__async", "dep:reqwest"] | |
mmap-async-tokio = ["__async", "dep:fmmap", "fmmap?/tokio-async"] | ||
s3-async-native = ["__async-s3", "__async-s3-nativetls"] | ||
s3-async-rustls = ["__async-s3", "__async-s3-rustls"] | ||
aws-s3-async = ["__async-aws-s3"] | ||
tilejson = ["dep:tilejson", "dep:serde", "dep:serde_json"] | ||
|
||
# Forward some of the common features to reqwest dependency | ||
|
@@ -28,17 +29,19 @@ reqwest-rustls-tls-webpki-roots = ["reqwest?/rustls-tls-webpki-roots"] | |
# Internal features, do not use | ||
__async = ["dep:tokio", "async-compression/tokio"] | ||
__async-s3 = ["__async", "dep:rust-s3"] | ||
__async-s3-nativetls = ["rust-s3?/tokio-native-tls"] | ||
__async-s3-nativetls = ["rust-s3?/use-tokio-native-tls"] | ||
__async-s3-rustls = ["rust-s3?/tokio-rustls-tls"] | ||
__async-aws-s3 = ["__async", "dep:aws-sdk-s3"] | ||
|
||
[dependencies] | ||
# TODO: determine how we want to handle compression in async & sync environments | ||
aws-sdk-s3 = { version = "1.49.0", optional = true } | ||
async-compression = { version = "0.4", features = ["gzip"] } | ||
bytes = "1" | ||
fmmap = { version = "0.3", default-features = false, optional = true } | ||
hilbert_2d = "1" | ||
reqwest = { version = "0.12.4", default-features = false, optional = true } | ||
rust-s3 = { version = "0.33.0", optional = true, default-features = false, features = ["fail-on-err"] } | ||
rust-s3 = { version = "0.35.1", optional = true, default-features = false, features = ["fail-on-err"] } | ||
serde = { version = "1", optional = true } | ||
serde_json = { version = "1", optional = true } | ||
thiserror = "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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use crate::{ | ||
async_reader::{AsyncBackend, AsyncPmTilesReader}, | ||
cache::{DirectoryCache, NoCache}, | ||
PmtError, PmtResult, | ||
}; | ||
use aws_sdk_s3::Client; | ||
use bytes::Bytes; | ||
|
||
impl AsyncPmTilesReader<AwsS3Backend, NoCache> { | ||
/// Creates a new `PMTiles` reader from a client, bucket and key to the | ||
/// archive using the `aws-sdk-s3` backend. | ||
/// | ||
/// Fails if the [bucket] or [key] does not exist or is an invalid | ||
/// archive. | ||
/// (Note: S3 requests are made to validate it.) | ||
pub async fn new_with_client_bucket_and_path( | ||
client: Client, | ||
bucket: String, | ||
key: String, | ||
) -> PmtResult<Self> { | ||
Self::new_with_cached_client_bucket_and_path(NoCache, client, bucket, key).await | ||
} | ||
} | ||
|
||
impl<C: DirectoryCache + Sync + Send> AsyncPmTilesReader<AwsS3Backend, C> { | ||
/// Creates a new `PMTiles` reader from a client, bucket and key to the | ||
/// archive using the `aws-sdk-s3` backend. Caches using the designated | ||
/// [cache]. | ||
/// | ||
/// Fails if the [bucket] or [key] does not exist or is an invalid | ||
/// archive. | ||
/// (Note: S3 requests are made to validate it.) | ||
pub async fn new_with_cached_client_bucket_and_path( | ||
cache: C, | ||
client: Client, | ||
bucket: String, | ||
key: String, | ||
) -> PmtResult<Self> { | ||
let backend = AwsS3Backend::from(client, bucket, key); | ||
|
||
Self::try_from_cached_source(backend, cache).await | ||
} | ||
} | ||
|
||
pub struct AwsS3Backend { | ||
client: Client, | ||
bucket: String, | ||
key: String, | ||
} | ||
|
||
impl AwsS3Backend { | ||
#[must_use] | ||
pub fn from(client: Client, bucket: String, key: String) -> Self { | ||
Self { | ||
client, | ||
bucket, | ||
key, | ||
} | ||
} | ||
} | ||
|
||
impl AsyncBackend for AwsS3Backend { | ||
async fn read(&self, offset: usize, length: usize) -> PmtResult<Bytes> { | ||
let range_end = offset + length - 1; | ||
let range = format!("bytes={offset}-{range_end}"); | ||
|
||
let obj = self | ||
.client | ||
.get_object() | ||
.bucket(self.bucket.clone()) | ||
.key(self.key.clone()) | ||
.range(range) | ||
.send() | ||
.await?; | ||
|
||
let response_bytes = obj | ||
.body | ||
.collect() | ||
.await | ||
.map_err(|e| PmtError::Reading(e.into()))? | ||
.into_bytes(); | ||
|
||
if response_bytes.len() > length { | ||
Err(PmtError::ResponseBodyTooLong(response_bytes.len(), length)) | ||
} else { | ||
Ok(response_bytes) | ||
} | ||
} | ||
} |
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.