pub struct HTTPStore { /* private fields */ }
Available on crate feature
http
only.Expand description
A synchronous HTTP store.
Implementations§
source§impl HTTPStore
impl HTTPStore
sourcepub fn new(base_url: &str) -> Result<Self, HTTPStoreCreateError>
pub fn new(base_url: &str) -> Result<Self, HTTPStoreCreateError>
Create a new HTTP store at a given base_url
.
§Errors
Returns a HTTPStoreCreateError
if base_url
is not a valid URL.
Examples found in repository?
examples/http_array_read.rs (line 19)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
fn http_array_read() -> Result<(), Box<dyn std::error::Error>> {
use std::sync::Arc;
use zarrs::{
array::Array,
array_subset::ArraySubset,
storage::{
storage_transformer::{StorageTransformerExtension, UsageLogStorageTransformer},
store,
},
};
const HTTP_URL: &str =
"https://raw.githubusercontent.com/LDeakin/zarrs/main/tests/data/array_write_read.zarr";
const ARRAY_PATH: &str = "/group/array";
// Create a HTTP store
let mut store: ReadableStorage = Arc::new(store::HTTPStore::new(HTTP_URL)?);
if let Some(arg1) = std::env::args().collect::<Vec<_>>().get(1) {
if arg1 == "--usage-log" {
let log_writer = Arc::new(std::sync::Mutex::new(
// std::io::BufWriter::new(
std::io::stdout(),
// )
));
let usage_log = Arc::new(UsageLogStorageTransformer::new(log_writer, || {
chrono::Utc::now().format("[%T%.3f] ").to_string()
}));
store = usage_log.clone().create_readable_transformer(store);
}
}
// Init the existing array, reading metadata
let array = Array::new(store, ARRAY_PATH)?;
println!(
"The array metadata is:\n{}\n",
serde_json::to_string_pretty(&array.metadata()).unwrap()
);
// Read the whole array
let subset_all = ArraySubset::new_with_shape(array.shape().to_vec());
let data_all = array.retrieve_array_subset_ndarray::<f32>(&subset_all)?;
println!("The whole array is:\n{data_all}\n");
// Read a chunk back from the store
let chunk_indices = vec![1, 0];
let data_chunk = array.retrieve_chunk_ndarray::<f32>(&chunk_indices)?;
println!("Chunk [1,0] is:\n{data_chunk}\n");
// Read the central 4x2 subset of the array
let subset_4x2 = ArraySubset::new_with_ranges(&[2..6, 3..5]); // the center 4x2 region
let data_4x2 = array.retrieve_array_subset_ndarray::<f32>(&subset_4x2)?;
println!("The middle 4x2 subset is:\n{data_4x2}\n");
Ok(())
}
sourcepub fn set_batch_range_requests(&mut self, batch_range_requests: bool)
pub fn set_batch_range_requests(&mut self, batch_range_requests: bool)
Set whether to batch range requests.
Defaults to true. Some servers do not fully support multipart ranges and might return an entire resource given such a request. It may be preferable to disable batched range requests in this case, so that each range request is a single part range.
sourcepub fn key_to_url(&self, key: &StoreKey) -> Result<Url, ParseError>
pub fn key_to_url(&self, key: &StoreKey) -> Result<Url, ParseError>
Trait Implementations§
source§impl ReadableStorageTraits for HTTPStore
impl ReadableStorageTraits for HTTPStore
source§fn get(&self, key: &StoreKey) -> Result<MaybeBytes, StorageError>
fn get(&self, key: &StoreKey) -> Result<MaybeBytes, StorageError>
source§fn get_partial_values_key(
&self,
key: &StoreKey,
byte_ranges: &[ByteRange]
) -> Result<Option<Vec<Vec<u8>>>, StorageError>
fn get_partial_values_key( &self, key: &StoreKey, byte_ranges: &[ByteRange] ) -> Result<Option<Vec<Vec<u8>>>, StorageError>
Retrieve partial bytes from a list of byte ranges for a store key. Read more
source§fn get_partial_values(
&self,
key_ranges: &[StoreKeyRange]
) -> Result<Vec<MaybeBytes>, StorageError>
fn get_partial_values( &self, key_ranges: &[StoreKeyRange] ) -> Result<Vec<MaybeBytes>, StorageError>
Retrieve partial bytes from a list of
StoreKeyRange
. Read moresource§fn size_prefix(&self, _prefix: &StorePrefix) -> Result<u64, StorageError>
fn size_prefix(&self, _prefix: &StorePrefix) -> Result<u64, StorageError>
Return the size in bytes of all keys under
prefix
. Read moresource§fn size_key(&self, key: &StoreKey) -> Result<Option<u64>, StorageError>
fn size_key(&self, key: &StoreKey) -> Result<Option<u64>, StorageError>
Return the size in bytes of the value at
key
. Read moresource§fn size(&self) -> Result<u64, StorageError>
fn size(&self) -> Result<u64, StorageError>
Return the total size in bytes of the storage. Read more
source§fn get_partial_values_batched_by_key(
&self,
key_ranges: &[StoreKeyRange]
) -> Result<Vec<MaybeBytes>, StorageError>
fn get_partial_values_batched_by_key( &self, key_ranges: &[StoreKeyRange] ) -> Result<Vec<MaybeBytes>, StorageError>
A utility method with the same input and output as
get_partial_values
that internally calls get_partial_values_key
with byte ranges grouped by key. Read moreAuto Trait Implementations§
impl Freeze for HTTPStore
impl RefUnwindSafe for HTTPStore
impl Send for HTTPStore
impl Sync for HTTPStore
impl Unpin for HTTPStore
impl UnwindSafe for HTTPStore
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more