Struct zarrs::storage::store::HTTPStore

source ·
pub struct HTTPStore { /* private fields */ }
Available on crate feature http only.
Expand description

A synchronous HTTP store.

Implementations§

source§

impl HTTPStore

source

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(())
}
source

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.

source

pub fn key_to_url(&self, key: &StoreKey) -> Result<Url, ParseError>

Maps a StoreKey to a HTTP Url.

§Errors

Returns an error if the URL is invalid.

Trait Implementations§

source§

impl Debug for HTTPStore

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl ReadableStorageTraits for HTTPStore

source§

fn get(&self, key: &StoreKey) -> Result<MaybeBytes, StorageError>

Retrieve the value (bytes) associated with a given StoreKey. Read more
source§

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>

Retrieve partial bytes from a list of StoreKeyRange. Read more
source§

fn size_prefix(&self, _prefix: &StorePrefix) -> Result<u64, StorageError>

Return the size in bytes of all keys under prefix. Read more
source§

fn size_key(&self, key: &StoreKey) -> Result<Option<u64>, StorageError>

Return the size in bytes of the value at key. Read more
source§

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>

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 more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more