### Dtype Examples Source: https://docs.rs/blosc2/0.2.2/blosc2/nd/struct.Dtype.html Illustrative examples of creating Dtype for various data structures like structs and arrays. ```APIDOC ## §Examples ```rust use blosc2::nd::{Dtype, Dtyped, DtypeScalarKind}; use std::collections::HashMap; #[derive(Debug, Clone, Copy, PartialEq)] #[repr(C, packed)] pub(crate) struct Point { x: i32, y: u32, z: i32, } unsafe impl Dtyped for Point { fn dtype() -> Dtype { Dtype::of_struct(HashMap::from([ ("x".into(), (0, Dtype::of_scalar(DtypeScalarKind::I32))), ("y".into(), (4, Dtype::of_scalar(DtypeScalarKind::U32))), ("z".into(), (8, Dtype::of_scalar(DtypeScalarKind::I32))), ])) .unwrap() } } #[derive(Debug, Clone, Copy, PartialEq)] #[repr(C, packed)] pub(crate) struct Person { height: i32, weight: i64, } unsafe impl Dtyped for Person { fn dtype() -> Dtype { Dtype::of_struct(HashMap::from([ ("height".into(), (0, Dtype::of_scalar(DtypeScalarKind::I32))), ("weight".into(), (4, Dtype::of_scalar(DtypeScalarKind::I64))), ])) .unwrap() } } #[derive(Debug, Clone, Copy, PartialEq)] #[repr(C)] pub(crate) struct PersonAligned { height: i32, weight: i64, } unsafe impl Dtyped for PersonAligned { fn dtype() -> Dtype { Dtype::of_struct(HashMap::from([ ("height".into(), (0, Dtype::of_scalar(DtypeScalarKind::I32))), ("weight".into(), (8, Dtype::of_scalar(DtypeScalarKind::I64))), ])) .unwrap() } } #[derive(Debug, Clone, Copy, PartialEq)] #[repr(C)] pub(crate) struct AudioSample([[f32; 2]; 16]); unsafe impl Dtyped for AudioSample { fn dtype() -> Dtype { Dtype::of_scalar(DtypeScalarKind::F32) .with_shape(vec![16, 2]) .unwrap() } } ``` ``` -------------------------------- ### Get first element Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Example usage of the first method on a slice. ```rust let v = [10, 40, 30]; assert_eq!(Some(&10), v.first()); let w: &[i32] = &[]; assert_eq!(None, w.first()); ``` -------------------------------- ### Get element or subslice Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Example usage of the get method on a slice. ```rust let v = [10, 40, 30]; assert_eq!(Some(&40), v.get(1)); assert_eq!(Some(&[10, 40][..]), v.get(0..2)); assert_eq!(None, v.get(3)); assert_eq!(None, v.get(0..4)); ``` -------------------------------- ### Get first chunk Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Example usage of the first_chunk method on a slice. ```rust let u = [10, 40, 30]; assert_eq!(Some(&[10, 40]), u.first_chunk::<2>()); let v: &[i32] = &[10]; assert_eq!(None, v.first_chunk::<2>()); let w: &[i32] = &[]; assert_eq!(Some(&[]), w.first_chunk::<0>()); ``` -------------------------------- ### starts_with Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Checks if the slice starts with the given needle. ```APIDOC ## starts_with ### Description Returns true if `needle` is a prefix of the slice or equal to the slice. ### Parameters - **needle** (&[T]) - Required - The prefix to check for. ``` -------------------------------- ### List Available Compressors Source: https://docs.rs/blosc2/0.2.2/blosc2/all.html Get a list of all compressors that Blosc2 can utilize. ```APIDOC ## GET /list_compressors ### Description Returns a list of all compressor algorithms available in the Blosc2 library. ### Method GET ### Endpoint /list_compressors ### Response #### Success Response (200) - **compressors** (array of strings) - A list of compressor names. #### Response Example ```json { "compressors": [ "lz4", "zstd", "blosclz" ] } ``` ``` -------------------------------- ### Split first chunk Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Example usage of the split_first_chunk method on a slice. ```rust let x = &[0, 1, 2]; if let Some((first, elements)) = x.split_first_chunk::<2>() { assert_eq!(first, &[0, 1]); assert_eq!(elements, &[2]); } assert_eq!(None, x.split_first_chunk::<4>()); ``` -------------------------------- ### Split first element Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Example usage of the split_first method on a slice. ```rust let x = &[0, 1, 2]; if let Some((first, elements)) = x.split_first() { assert_eq!(first, &0); assert_eq!(elements, &[1, 2]); } ``` -------------------------------- ### Get last element Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Example usage of the last method on a slice. ```rust let v = [10, 40, 30]; assert_eq!(Some(&30), v.last()); let w: &[i32] = &[]; assert_eq!(None, w.last()); ``` -------------------------------- ### GET items Source: https://docs.rs/blosc2/0.2.2/blosc2/chunk/struct.SChunk.html Retrieves a range of items from the SChunk as a vector of bytes. ```APIDOC ## GET items ### Description Get a range of items specified by the index range. Each item is typesize bytes long. ### Parameters #### Path Parameters - **idx** (Range) - Required - The index range of the items to retrieve. Must be in range [0, items_num()). ### Response #### Success Response (200) - **Result, Error>** - The decompressed items as a vector of bytes, of size typesize * idx.len(). ``` -------------------------------- ### Get Compressor from CParams Source: https://docs.rs/blosc2/0.2.2/blosc2/struct.CParams.html Retrieves the currently set compressor algorithm from the parameters. ```rust pub fn get_compressor(&self) -> CompressAlgo ``` -------------------------------- ### GET items_into Source: https://docs.rs/blosc2/0.2.2/blosc2/chunk/struct.SChunk.html Retrieves a range of items and copies them into a provided destination buffer. ```APIDOC ## GET items_into ### Description Get a range of items specified by the index range and copy them into the provided destination buffer. ### Parameters #### Path Parameters - **idx** (Range) - Required - The index range of the items to retrieve. - **dst** (&mut [MaybeUninit]) - Required - The destination buffer. ### Response #### Success Response (200) - **Result** - The number of bytes copied into the destination buffer. ``` -------------------------------- ### Split last chunk Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Example usage of the split_last_chunk method on a slice. ```rust let x = &[0, 1, 2]; if let Some((elements, last)) = x.split_last_chunk::<2>() { assert_eq!(elements, &[0]); assert_eq!(last, &[1, 2]); } assert_eq!(None, x.split_last_chunk::<4>()); ``` -------------------------------- ### Check slice length Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Example usage of the len method on a slice. ```rust let a = [1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### Get Compressor Library Info Source: https://docs.rs/blosc2/0.2.2/blosc2/fn.compressor_lib_info.html Retrieves the name and version of a specified compression library included in the Blosc2 build. ```APIDOC ## compressor_lib_info ### Description Get info from a compression library included in the current build. ### Method GET (Conceptual - this is a function call, not a REST endpoint) ### Endpoint N/A (Function call) ### Parameters #### Arguments - **compressor** (CompressAlgo) - Required - The compressor algorithm to get info from. ### Returns #### Success Response - **tuple** (String, String) - A tuple containing the compression library name and its version. ### Response Example ```json ["libname", "version"] ``` ``` -------------------------------- ### Check if Slice Starts With Prefix Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Use `starts_with` to determine if a slice begins with a given sequence of elements. An empty slice is always considered a prefix. ```rust let v = [10, 40, 30]; assert!(v.starts_with(&[10])); assert!(v.starts_with(&[10, 40])); assert!(v.starts_with(&v)); assert!(!v.starts_with(&[50])); assert!(!v.starts_with(&[10, 50])); ``` ```rust let v = &[10, 40, 30]; assert!(v.starts_with(&[])); let v: &[u8] = &[]; assert!(v.starts_with(&[])); ``` -------------------------------- ### SChunk Opening and Loading Source: https://docs.rs/blosc2/0.2.2/blosc2/chunk/struct.SChunk.html Methods for opening existing SChunk instances from disk or from a buffer. ```APIDOC ### pub fn open(urlpath: &Path) -> Result Open an existing super chunk from the specified path. ### pub fn open_with_options( urlpath: &Path, options: &SChunkOpenOptions, ) -> Result Open an existing super chunk from the given options. ### pub fn from_buffer(buffer: CowVec<'_, u8>) -> Result Create a super chunk from an existing in-memory buffer. ``` -------------------------------- ### Get last chunk Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Example usage of the last_chunk method on a slice. ```rust let u = [10, 40, 30]; assert_eq!(Some(&[40, 30]), u.last_chunk::<2>()); let v: &[i32] = &[10]; assert_eq!(None, v.last_chunk::<2>()); let w: &[i32] = &[]; assert_eq!(Some(&[]), w.last_chunk::<0>()); ``` -------------------------------- ### f16 Initialization and Zeroing Source: https://docs.rs/blosc2/0.2.2/blosc2/util/struct.f16.html Covers methods for initializing f16 values, including creating zeroed instances and overwriting with zeros. ```APIDOC ## impl FromZeros for f16 ### Description Provides methods for creating and manipulating zeroed f16 values. ### Methods #### fn zero(&mut self) Overwrites `self` with zeros. #### fn new_zeroed() -> Self Creates an instance of `Self` from zeroed bytes. ``` -------------------------------- ### Compress and Decompress Data with Chunk Source: https://docs.rs/blosc2/0.2.2/blosc2/chunk/struct.Chunk.html Demonstrates compressing an array of i32 into a Chunk and then decompressing it. Shows how to set compression parameters and verify the data. Requires `blosc2` crate. ```rust use blosc2::{CParams, DParams}; use blosc2::chunk::{Chunk, Decoder, Encoder}; let data: [i32; 7] = [1, 2, 3, 4, 5, 6, 7]; let i32len = std::mem::size_of::(); let data_bytes = unsafe { std::slice::from_raw_parts(data.as_ptr() as *const u8, data.len() * i32len) }; // Compress the data into a Chunk let cparams = CParams::default() .typesize(i32len) .unwrap() .clevel(5) .nthreads(2) .clone(); let chunk: Chunk = Encoder::new(cparams) .unwrap() .compress(&data_bytes) .unwrap(); let chunk_bytes: &[u8] = chunk.as_bytes(); // Decompress the Chunk let dparams = DParams::default(); let decompressed = Decoder::new(dparams) .unwrap() .decompress(chunk_bytes) .unwrap(); // Check that the decompressed data matches the original assert_eq!(data_bytes, decompressed); // A chunk support random access to individual items assert_eq!(&data_bytes[0..4], chunk.item(0).expect("failed to get the 0-th item")); assert_eq!(&data_bytes[12..16], chunk.item(3).expect("failed to get the 3-th item")); assert_eq!(&data_bytes[4..20], chunk.items(1..5).expect("failed to get items 1 to 4")); ``` -------------------------------- ### SChunkOpenOptions API Source: https://docs.rs/blosc2/0.2.2/blosc2/chunk/struct.SChunkOpenOptions.html Methods for configuring and initializing SChunkOpenOptions. ```APIDOC ## SChunkOpenOptions ### Description Options for opening a super chunk, also used by `Ndarray`. ### Methods - **new() -> Self** Create an options struct with default options. - **offset(&mut self, offset: u64) -> &mut Self** Set the offset in the file from which to read the super chunk. - **mmap(&mut self, mmap: Option) -> &mut Self** Set the memory-mapped mode for the super chunk. `None` means that no memory mapping will be used. *Note: This function is marked unsafe due to potential Undefined Behavior if the underlying file is modified.* ``` -------------------------------- ### Remove a prefix from a slice Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Use `strip_prefix` to get a subslice after removing a specified prefix. Returns `None` if the slice does not start with the prefix. An empty prefix returns the original slice. ```rust let v = &[10, 40, 30]; assert_eq!(v.strip_prefix(&[10]), Some(&[40, 30][..])); assert_eq!(v.strip_prefix(&[10, 40]), Some(&[30][..])); assert_eq!(v.strip_prefix(&[10, 40, 30]), Some(&[][..])); assert_eq!(v.strip_prefix(&[50]), None); assert_eq!(v.strip_prefix(&[10, 50]), None); ``` ```rust let prefix : &str = "he"; assert_eq!(b"hello".strip_prefix(prefix.as_bytes()), Some(b"llo".as_ref())); ``` -------------------------------- ### FfiVec Implementations Source: https://docs.rs/blosc2/0.2.2/blosc2/util/struct.FfiVec.html Provides methods for creating, accessing, and managing FfiVec instances. ```APIDOC ## impl FfiVec ### pub unsafe fn from_raw_parts(ptr: NonNull, len: usize) -> Self Creates a new `FfiVec` from a raw pointer and length. **Note:** The `len` is not the length of allocation, but rather the number of valid elements in the vector. The ‘capacity’ is not passed, as it is not required by C’s `free` and resizing is not supported. #### Safety The caller must ensure that the pointer is valid and points to a memory region of at least `len` elements of type `T`. The memory must have been allocated using `malloc` and it will be freed using `free` when the `FfiVec` is dropped. ### pub fn as_slice(&self) -> &[T] Get a slice of the elements in the vector. ### pub fn as_mut_slice(&mut self) -> &mut [T] Get a mutable slice of the elements in the vector. ## impl FfiVec ### pub fn copy_of(buf: &[u8]) -> Self Creates a new `FfiVec` from a byte slice by allocating memory using `malloc` and copying the bytes data. ``` -------------------------------- ### Create and Manipulate SChunk Source: https://docs.rs/blosc2/0.2.2/blosc2/chunk/struct.SChunk.html Demonstrates creating an SChunk, appending data as raw bytes and compressed chunks, and accessing data randomly. Ensure typesizes match when appending pre-compressed data. ```rust use blosc2::{CParams, DParams}; use blosc2::chunk::{SChunk, Encoder}; let i32len = std::mem::size_of::(); let cparams = CParams::default() .typesize(i32len) .unwrap() .clone(); let mut schunk = SChunk::new(cparams.clone(), DParams::default()).unwrap(); // Create two data arrays let data1: [i32; 7] = [1, 2, 3, 4, 5, 6, 7]; let data2: [i32; 7] = [8, 9, 10, 11, 12, 13, 14]; let data1_bytes = unsafe { std::slice::from_raw_parts(data1.as_ptr() as *const u8, data1.len() * i32len) }; let data2_bytes = unsafe { std::slice::from_raw_parts(data2.as_ptr() as *const u8, data2.len() * i32len) }; // Append the first data array to the SChunk, which will be compressed using SChunk's CParams schunk.append(data1_bytes).unwrap(); assert_eq!(schunk.num_chunks(), 1); assert_eq!(7, schunk.items_num()); // Append the second data array to the SChunk, as already compressed data let data2_cparams = CParams::default() .typesize(i32len) // typesize must match the SChunk's CParams .unwrap() .clevel(9) .clone(); let data2_chunk = Encoder::new(data2_cparams) .unwrap() .compress(data2_bytes) .unwrap(); schunk.append_chunk(data2_chunk.shallow_clone()).unwrap(); assert_eq!(schunk.num_chunks(), 2); assert_eq!(14, schunk.items_num()); // Random access a whole chunk within the super-chunk assert_eq!( data2_chunk.decompress().unwrap(), schunk.get_chunk(1).unwrap().decompress().unwrap() ); // Random access individual items within the super-chunk assert_eq!(5, i32::from_ne_bytes(schunk.item(4).unwrap().try_into().unwrap())); assert_eq!(12, i32::from_ne_bytes(schunk.item(11).unwrap().try_into().unwrap())); ``` -------------------------------- ### SChunk Creation Source: https://docs.rs/blosc2/0.2.2/blosc2/chunk/struct.SChunk.html Methods for creating new SChunk instances, either in-memory or on disk. ```APIDOC ## impl SChunk ### pub fn new(cparams: CParams, dparams: DParams) -> Result Create a new in-memory super chunk. ### pub fn new_on_disk( urlpath: &Path, cparams: CParams, dparams: DParams, ) -> Result Create a new on-disk super chunk at the given path. ### pub fn new_at( storage: SChunkStorageParams<'_>, cparams: CParams, dparams: DParams, ) -> Result Create a new super chunk with the specified parameters. #### Arguments * `storage` - parameters specifying the storage location and layout of the super chunk. See `SChunkStorageParams`. * `cparams` - Compression parameters used to compress new chunks added to the super chunk. * `dparams` - Decompression parameters used to decompress chunks from the super chunk. ``` -------------------------------- ### Get f16 signum Source: https://docs.rs/blosc2/0.2.2/blosc2/util/struct.f16.html Returns a number representing the sign of the input. ```rust let f = f16::from_f32(3.5_f32); assert_eq!(f.signum(), f16::from_f32(1.0)); assert_eq!(f16::NEG_INFINITY.signum(), f16::from_f32(-1.0)); assert!(f16::NAN.signum().is_nan()); ``` -------------------------------- ### fn try_into Source: https://docs.rs/blosc2/0.2.2/blosc2/struct.CParams.html Documentation for the try_into conversion method within the Blosc2 library. ```APIDOC ## fn try_into(self) -> Result>::Error> ### Description Performs the conversion from the current type to the target type U, returning a Result containing the converted value or an error if the conversion fails. ### Parameters - **self** (T) - Required - The instance to be converted. ### Response - **Result>::Error>** - The result of the conversion, either the converted type U or a conversion error. ``` -------------------------------- ### Get Typesize from CParams Source: https://docs.rs/blosc2/0.2.2/blosc2/struct.CParams.html Retrieves the currently set typesize in bytes. ```rust pub fn get_typesize(&self) -> usize ``` -------------------------------- ### GET /items Source: https://docs.rs/blosc2/0.2.2/blosc2/chunk/struct.Chunk.html Retrieves a range of items from the chunk as a vector of bytes. ```APIDOC ## GET /items ### Description Get a range of items specified by the index range. Each item is typesize bytes long. ### Parameters #### Path Parameters - **idx** (Range) - Required - The index range of the items to retrieve. Must be in range [0, items_num()). ### Response #### Success Response (200) - **Result, Error>** - The decompressed items as a vector of bytes, of size typesize * idx.len(). ``` -------------------------------- ### SChunk Raw Pointer Handling Source: https://docs.rs/blosc2/0.2.2/blosc2/chunk/struct.SChunk.html Methods for creating an SChunk from a raw pointer, useful for FFI. ```APIDOC ### pub unsafe fn from_raw_ptr(ptr: *mut ()) -> Result Create a new super chunk from a raw pointer. The ownership of the underlying memory is transferred to the new super chunk, and it will be freed once the super chunk is dropped using `blosc2_sys::blosc2_schunk_free`. This function can be useful if a user wants to accept a schunk across ffi boundaries. #### Safety The caller must ensure that the pointer is valid and points to a valid `blosc2_sys::blosc2_schunk`, and that no other references to the same memory exist. ``` -------------------------------- ### Create Blosc2 Encoder Source: https://docs.rs/blosc2/0.2.2/blosc2/chunk/struct.Encoder.html Initializes a new Blosc2 Encoder with specified compression parameters. Ensure CParams are correctly configured before use. ```rust pub fn new(params: CParams) -> Result ``` -------------------------------- ### Create and access an Ndarray Source: https://docs.rs/blosc2 Demonstrates initializing an Ndarray from an ndarray crate array and performing element access and slicing operations. ```rust use blosc2::nd::{Ndarray, NdarrayParams}; let arr = Ndarray::from_ndarray( &ndarray::array!([1_i32, 2, 3], [4, 5, 6], [7, 8, 9]), NdarrayParams::default() .chunkshape(Some(&[2, 2])) .blockshape(Some(&[1, 1])), ).unwrap(); assert_eq!(4, arr.get::(&[1, 0]).unwrap()); assert_eq!(9, arr.get::(&[2, 2]).unwrap()); let slice_arr: ndarray::Array2 = arr.slice(&[0..2, 1..3]).unwrap(); assert_eq!(slice_arr, ndarray::array![[2, 3], [5, 6]]); ``` -------------------------------- ### Split last element Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Example usage of the split_last method on a slice. ```rust let x = &[0, 1, 2]; if let Some((last, elements)) = x.split_last() { assert_eq!(last, &2); assert_eq!(elements, &[0, 1]); } ``` -------------------------------- ### CParams Configuration Methods Source: https://docs.rs/blosc2/0.2.2/blosc2/struct.CParams.html Methods for configuring and retrieving compression parameters for blosc2 encoders. ```APIDOC ## Configuration Methods ### compressor(compressor: CompressAlgo) -> &mut Self Sets the compression algorithm. Default is `Blosclz`. ### clevel(clevel: u32) -> &mut Self Sets the compression level in range [0, 9]. Default is 5. ### typesize(typesize: usize) -> Result<&mut Self, Error> Sets the typesize of data in bytes [1, 255]. Default is 8. ### nthreads(nthreads: usize) -> &mut Self Sets the number of threads for compression. Default is 1. ### blocksize(blocksize: Option) -> &mut Self Sets the block size. `None` enables automatic block size. ### splitmode(splitmode: SplitMode) -> &mut Self Sets the split mode. Default is `ForwardCompat`. ### filters(filters: &[Filter]) -> Result<&mut Self, Error> Sets filters to apply before compression. Max 6 filters. Default is `ByteShuffle`. ``` -------------------------------- ### Check if slice is empty Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Example usage of the is_empty method on a slice. ```rust let a = [1, 2, 3]; assert!(!a.is_empty()); let b: &[i32] = &[]; assert!(b.is_empty()); ``` -------------------------------- ### Ndarray Initialization Methods Source: https://docs.rs/blosc2/0.2.2/blosc2/nd/struct.Ndarray.html Methods for creating new ndarrays from various sources including memory buffers, serialized bytes, and existing ndarray objects. ```APIDOC ## new_at ### Description Creates a new ndarray at the given storage with a special value (zero/nan/uninit) or a repeated value. ### Parameters - **value** (NdarrayInitValue) - Required - The initial value for all elements. - **shape** (&[usize]) - Required - The shape of the new ndarray. - **storage** (SChunkStorageParams) - Required - Storage parameters for location and layout. - **params** (NdarrayParams) - Required - Parameters including chunkshape and blockshape. ## from_items ### Description Creates a new in-memory ndarray from a contiguous buffer of items. ### Parameters - **items** (&[T]) - Required - Buffer containing item data. - **shape** (&[usize]) - Required - The shape of the new ndarray. - **params** (NdarrayParams) - Required - Parameters including chunkshape and blockshape. ## from_ndarray ### Description Creates a new blosc ndarray from an existing ndarray::ArrayBase (requires ndarray feature). ### Parameters - **ndarray** (&ArrayBase) - Required - The source ndarray to copy data from. - **params** (NdarrayParams) - Required - Parameters including chunkshape and blockshape. ``` -------------------------------- ### Get Filters from CParams Source: https://docs.rs/blosc2/0.2.2/blosc2/struct.CParams.html Retrieves an iterator over the filters currently set in the parameters. ```rust pub fn get_filters(&self) -> impl Iterator ``` -------------------------------- ### unsafe fn clone_to_uninit Source: https://docs.rs/blosc2/0.2.2/blosc2/util/struct.Complex.html Performs a copy-assignment from the current instance to a raw pointer destination. This is a nightly-only experimental API. ```APIDOC ## unsafe fn clone_to_uninit ### Description Performs copy-assignment from `self` to `dest`. This is a nightly-only experimental API. ### Parameters - **dest** (*mut u8) - Required - A raw pointer to the uninitialized memory destination. ``` -------------------------------- ### Get Compression Level from CParams Source: https://docs.rs/blosc2/0.2.2/blosc2/struct.CParams.html Retrieves the currently set compression level. ```rust pub fn get_clevel(&self) -> u32 ``` -------------------------------- ### SChunk Serialization Source: https://docs.rs/blosc2/0.2.2/blosc2/chunk/struct.SChunk.html Methods for serializing SChunk instances to disk or to a buffer. ```APIDOC ### pub fn to_buffer(&mut self) -> Result, Error> Serialize the super chunk to an in-memory buffer. ### pub fn to_file(&mut self, urlpath: &Path, append: bool) -> Result<(), Error> Serialize the super chunk to a file. Either a single file or a directory will be created at `urlpath`, depending if the schunk is sparse or contiguous. See `SChunkStorageParams` #### Arguments * `urlpath` - The path to the file where the super chunk will be saved. * `append` - If true, the super chunk will be appended to the file. If false, the file should not exist, otherwise an error will be returned. ``` -------------------------------- ### DtypeScalarKind Implementations Source: https://docs.rs/blosc2/0.2.2/blosc2/nd/enum.DtypeScalarKind.html Provides methods for DtypeScalarKind, such as getting the size and alignment of a scalar. ```APIDOC ## impl DtypeScalarKind ### Methods - **itemsize() -> usize**: Get the size of the scalar in bytes. - **alignment() -> usize**: Get the alignment of the scalar in bytes. ``` -------------------------------- ### Create and Access Blosc2 Ndarray from ndarray Source: https://docs.rs/blosc2/0.2.2/blosc2/nd/struct.Ndarray.html Demonstrates creating a blosc2 Ndarray from an ndarray::ArrayBase, specifying chunk and block shapes, and accessing elements. Also shows slicing the blosc2 Ndarray. ```rust use blosc2::nd::{Ndarray, NdarrayParams}; let arr = Ndarray::from_ndarray( &ndarray::array!([1_i32, 2, 3], [4, 5, 6], [7, 8, 9]), NdarrayParams::default() .chunkshape(Some(&[2, 2])) .blockshape(Some(&[1, 1])), ).unwrap(); assert_eq!(4, arr.get::(&[1, 0]).unwrap()); assert_eq!(9, arr.get::(&[2, 2]).unwrap()); let slice_arr: ndarray::Array2 = arr.slice(&[0..2, 1..3]).unwrap(); assert_eq!(slice_arr, ndarray::array!([[2, 3], [5, 6]])); ``` -------------------------------- ### rchunks Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Returns an iterator over chunk_size elements of the slice at a time, starting at the end. ```APIDOC ## rchunks ### Description Returns an iterator over chunk_size elements of the slice at a time, starting at the end of the slice. The chunks are slices and do not overlap. ### Parameters #### Query Parameters - **chunk_size** (usize) - Required - The size of each chunk. ### Panics Panics if chunk_size is zero. ``` -------------------------------- ### f16 Formatting Implementations Source: https://docs.rs/blosc2/0.2.2/blosc2/util/struct.f16.html Implementations for formatting f16 values in upper hexadecimal and standard formats. ```APIDOC ## impl UpperExp for f16 ### Description Formats the f16 value using the given formatter, likely for scientific notation. ### Method `fmt` ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (Result) - **()** - Indicates successful formatting. - **Error** - An error type if formatting fails. #### Response Example N/A ``` ```APIDOC ## impl UpperHex for f16 ### Description Formats the f16 value using the given formatter in upper hexadecimal representation. ### Method `fmt` ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (Result) - **()** - Indicates successful formatting. - **Error** - An error type if formatting fails. #### Response Example N/A ``` -------------------------------- ### Get Split Mode from CParams Source: https://docs.rs/blosc2/0.2.2/blosc2/struct.CParams.html Retrieves the currently set split mode for the encoder. ```rust pub fn get_splitmode(&self) -> SplitMode ``` -------------------------------- ### POST /items_into Source: https://docs.rs/blosc2/0.2.2/blosc2/chunk/struct.Chunk.html Retrieves a range of items and copies them into a provided destination buffer. ```APIDOC ## POST /items_into ### Description Get a range of items specified by the index range and copy them into the provided destination buffer. ### Parameters #### Path Parameters - **idx** (Range) - Required - The index range of the items to retrieve. - **dst** (&mut [MaybeUninit]) - Required - The destination buffer to copy data into. ### Response #### Success Response (200) - **Result** - The number of bytes copied into the destination buffer. ``` -------------------------------- ### FfiVec Trait Implementations Source: https://docs.rs/blosc2/0.2.2/blosc2/util/struct.FfiVec.html Details the trait implementations for FfiVec, including Clone, Debug, Drop, and conversions. ```APIDOC ## Trait Implementations for FfiVec ### impl Clone for FfiVec #### fn clone(&self) -> Self Returns a duplicate of the value. #### fn clone_from(&mut self, source: &Self) Performs copy-assignment from `source`. ### impl Debug for FfiVec where T: Debug, #### fn fmt(&self, f: &mut Formatter<'_>) -> Result Formats the value using the given formatter. ### impl Drop for FfiVec #### fn drop(&mut self) Executes the destructor for this type. ### impl From> for CowVec<'_, T> #### fn from(value: FfiVec) -> Self Converts to this type from the input type. ``` -------------------------------- ### Get Number of Threads from CParams Source: https://docs.rs/blosc2/0.2.2/blosc2/struct.CParams.html Retrieves the currently set number of threads for compression. ```rust pub fn get_nthreads(&self) -> usize ``` -------------------------------- ### rsplit Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Returns an iterator over subslices separated by elements that match a predicate, starting from the end. ```APIDOC ## rsplit ### Description Returns an iterator over subslices separated by elements that match `pred`, starting at the end of the slice and working backwards. The matched element is not contained in the subslices. ### Parameters - **pred** (FnMut(&T) -> bool) - Required - The predicate function used to match elements. ``` -------------------------------- ### total_cmp Method Source: https://docs.rs/blosc2/0.2.2/blosc2/util/struct.f16.html The total_cmp method provides a total ordering for f16 values according to the IEEE 754 (2008) standard, which differs from standard PartialOrd implementations by including NaNs and distinguishing between positive and negative zeros. ```APIDOC ## pub fn total_cmp(&self, other: &f16) -> Ordering ### Description Returns the ordering between `self` and `other` based on the IEEE 754 (2008) totalOrder predicate. ### Parameters #### Path Parameters - **self** (f16) - Required - The primary value to compare. - **other** (&f16) - Required - The value to compare against. ### Response - **Ordering** (enum) - Returns Less, Equal, or Greater. ``` -------------------------------- ### SChunkStorageParams Implementations Source: https://docs.rs/blosc2/0.2.2/blosc2/chunk/struct.SChunkStorageParams.html Details on the implementations for SChunkStorageParams, including Clone, Debug, and various blanket implementations. ```APIDOC ## Implementations for SChunkStorageParams ### `Clone` Trait - **`clone(&self) -> SChunkStorageParams<'a>`**: Returns a duplicate of the value. - **`clone_from(&mut self, source: &Self)`**: Performs copy-assignment from `source`. ### `Debug` Trait - **`fmt(&self, f: &mut Formatter<'_>) -> Result`**: Formats the value using the given formatter. ### Auto Trait Implementations - `Freeze` - `RefUnwindSafe` - `Send` - `Sync` - `Unpin` - `UnwindSafe` ### Blanket Implementations - `Any` - `Borrow` - `BorrowMut` - `CloneToUninit` (Nightly-only experimental) - `From` - `Into` - `ToOwned` - `TryFrom` - `TryInto` ``` -------------------------------- ### array_windows Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Returns an iterator over overlapping windows of N elements of a slice, starting at the beginning. ```APIDOC ## array_windows ### Description Returns an iterator over overlapping windows of N elements of a slice, starting at the beginning of the slice. This is the const generic equivalent of windows. ### Parameters #### Path Parameters - **N** (usize) - Required - The size of the windows. ### Panics Panics if N is zero. ``` -------------------------------- ### Create Overlapping N-Element Windows from Slice (Nightly) Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html The `array_windows` method provides an iterator over overlapping windows of `N` elements from a slice. This is a nightly-only experimental API. Panics if `N` is zero. ```rust #![feature(array_windows)] let slice = [0, 1, 2, 3]; let mut iter = slice.array_windows(); assert_eq!(iter.next().unwrap(), &[0, 1]); assert_eq!(iter.next().unwrap(), &[1, 2]); assert_eq!(iter.next().unwrap(), &[2, 3]); assert!(iter.next().is_none()); ``` -------------------------------- ### rchunks_exact Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Returns an iterator over chunk_size elements of the slice at a time, starting at the end, omitting the remainder. ```APIDOC ## rchunks_exact ### Description Returns an iterator over chunk_size elements of the slice at a time, starting at the end of the slice. If chunk_size does not divide the length of the slice, the remainder is omitted. ### Parameters #### Query Parameters - **chunk_size** (usize) - Required - The size of each chunk. ### Panics Panics if chunk_size is zero. ``` -------------------------------- ### as_simd Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Splits a slice into a prefix, a middle section of aligned SIMD types, and a suffix. This is a safe wrapper around `slice::align_to` and is currently an experimental, nightly-only API. ```APIDOC ## pub fn as_simd(&self) -> (&[T], &[Simd], &[T]) ### Description Splits a slice into a prefix, a middle of aligned SIMD types, and a suffix. This is a safe wrapper around `slice::align_to`, so inherits the same guarantees as that method. ### Panics This will panic if the size of the SIMD type is different from `LANES` times that of the scalar. At the time of writing, the trait restrictions on `Simd` keeps that from ever happening, as only power-of-two numbers of lanes are supported. It’s possible that, in the future, those restrictions might be lifted in a way that would make it possible to see panics from this method for something like `LANES == 3`. ### Examples ```rust #![feature(portable_simd)] use core::simd::prelude::*; let short = &[1, 2, 3]; let (prefix, middle, suffix) = short.as_simd::<4>(); assert_eq!(middle, []); // Not enough elements for anything in the middle // They might be split in any possible way between prefix and suffix let it = prefix.iter().chain(suffix).copied(); assert_eq!(it.collect::>(), vec![1, 2, 3]); fn basic_simd_sum(x: &[f32]) -> f32 { use std::ops::Add; let (prefix, middle, suffix) = x.as_simd(); let sums = f32x4::from_array([ prefix.iter().copied().sum(), 0.0, 0.0, suffix.iter().copied().sum(), ]); let sums = middle.iter().copied().fold(sums, f32x4::add); sums.reduce_sum() } let numbers: Vec = (1..101).map(|x| x as _).collect(); assert_eq!(basic_simd_sum(&numbers[1..99]), 4949.0); ``` ``` -------------------------------- ### as_rchunks Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Splits a slice into a slice of N-element arrays starting from the end, returning a remainder and the chunks. ```APIDOC ## as_rchunks ### Description Splits the slice into a slice of N-element arrays, starting at the end of the slice, and a remainder slice with length strictly less than N. ### Parameters #### Path Parameters - **N** (usize) - Required - The size of the arrays in the returned chunks. ### Panics Panics if N is zero. ``` -------------------------------- ### Iterate over slice elements Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Returns an iterator that yields references to all items in the slice from start to end. ```rust let x = &[1, 2, 4]; let mut iterator = x.iter(); assert_eq!(iterator.next(), Some(&1)); assert_eq!(iterator.next(), Some(&2)); assert_eq!(iterator.next(), Some(&4)); assert_eq!(iterator.next(), None); ``` -------------------------------- ### Get blosc2 Crate Version Source: https://docs.rs/blosc2/0.2.2/blosc2/constant.VERSION.html Access the version of the blosc2 crate. This constant is available for direct use. ```rust pub const VERSION: &str = "0.2.2"; ``` -------------------------------- ### DParams Configuration Methods Source: https://docs.rs/blosc2/0.2.2/blosc2/struct.DParams.html Methods for configuring and retrieving decompression parameters such as thread count. ```APIDOC ## DParams Configuration ### Description Methods to manage decompression settings for Decoder, SChunk, and Ndarray components. ### Methods - **nthreads(nthreads: usize) -> &mut Self**: Sets the number of threads to use for decompression. Default is 1. - **get_nthreads() -> usize**: Returns the current number of threads configured for decompression. ``` -------------------------------- ### Dtype Creation Methods Source: https://docs.rs/blosc2/0.2.2/blosc2/nd/struct.Dtype.html Methods for creating Dtype instances, including scalar types, structs, and explicit definitions. ```APIDOC ### impl Dtype #### pub fn of_scalar(kind: DtypeScalarKind) -> Self Creates a new scalar dtype. The created dtype will use the native endianness. #### pub fn of_struct( fields: HashMap, ) -> Result Creates a new struct dtype from a set of fields definitions. ##### Arguments * `fields` - A map of field names to tuple `(offset, dtype)`. The fields should be either in packed or aligned offsets, custom offsets are not supported. There are some cases in which it is ambiguous whether the offsets are packed or aligned, and it may affect the computed total itemsize of the struct. In these cases, consider using the explicit `Self::new`. #### pub fn new( kind: DtypeKind, shape: Vec, itemsize: usize, alignment: usize, ) -> Result Creates a new dtype by specifying all of the parameters explicitly. Thw shape, itemsize and alignment will be validated against the kind. See `DtypeError` for their constraints. ``` -------------------------------- ### rsplitn Source: https://docs.rs/blosc2/0.2.2/blosc2/util/enum.CowVec.html Returns an iterator over subslices separated by elements that match a predicate, limited to n items, starting from the end. ```APIDOC ## rsplitn ### Description Returns an iterator over subslices separated by elements that match `pred` limited to returning at most `n` items. This starts at the end of the slice and works backwards. ### Parameters - **n** (usize) - Required - Maximum number of items to return. - **pred** (FnMut(&T) -> bool) - Required - The predicate function used to match elements. ``` -------------------------------- ### NdarrayParams Configuration Methods Source: https://docs.rs/blosc2/0.2.2/blosc2/nd/struct.NdarrayParams.html Methods for initializing and configuring NdarrayParams for blosc2 ndarray operations. ```APIDOC ## NdarrayParams Configuration ### Description Methods to create and configure parameters for creating or manipulating blosc2 ndarrays. ### Methods - **new()**: Creates a new set of parameters with default values. - **cparams(cparams: CParams)**: Sets the compression parameters. - **dparams(dparams: DParams)**: Sets the decompression parameters. - **chunkshape(chunkshape: Option<&[usize]>)**: Sets the chunk shape of the array. Panics if shape exceeds MAX_DIM. - **blockshape(blockshape: Option<&[usize]>)**: Sets the block shape of the array. Panics if shape exceeds MAX_DIM. ### Parameters #### Request Body - **cparams** (CParams) - Optional - Compression parameters. - **dparams** (DParams) - Optional - Decompression parameters. - **chunkshape** (Option<&[usize]>) - Optional - The chunk shape of the array; None means automatic. - **blockshape** (Option<&[usize]>) - Optional - The block shape of the array; None means automatic. ``` -------------------------------- ### Define Audio Sample Struct for Blosc2 Source: https://docs.rs/blosc2/0.2.2/blosc2/nd/struct.Dtype.html Defines a 2D array struct `AudioSample` representing audio data. It implements `Dtyped` for Blosc2, specifying the dtype as a 16x2 array of `f32`. ```rust // An audio sample with two channels and 16 samples, represented as an `f32` 2D array. #[derive(Debug, Clone, Copy, PartialEq)] #[repr(C)] struct AudioSample([[f32; 2]; 16]); unsafe impl Dtyped for AudioSample { fn dtype() -> Dtype { Dtype::from_numpy_str("(' Option ``` -------------------------------- ### Declare Extern Function with Complex Source: https://docs.rs/blosc2/0.2.2/blosc2/util/struct.Complex.html Example of using Complex types within an extern C function declaration for FFI. ```rust use num_complex::Complex; use std::os::raw::c_int; extern "C" { fn zaxpy_(n: *const c_int, alpha: *const Complex, x: *const Complex, incx: *const c_int, y: *mut Complex, incy: *const c_int); } ``` -------------------------------- ### Create FfiVec from Raw Parts Source: https://docs.rs/blosc2/0.2.2/blosc2/util/struct.FfiVec.html Creates a new FfiVec from a raw pointer and length. The pointer must be valid and point to memory allocated with malloc, which will be freed by FfiVec's Drop implementation. The length specifies the number of valid elements, not the allocation capacity. ```rust pub unsafe fn from_raw_parts(ptr: NonNull, len: usize) -> Self ``` -------------------------------- ### List Compressors Source: https://docs.rs/blosc2/0.2.2/blosc2/fn.list_compressors.html Retrieves a list of compressor names that are supported in the current build of the Blosc2 library. ```APIDOC ## list_compressors ### Description Get a list of compressors names supported in the current build. ### Method GET ### Endpoint /blosc2/compressors ### Parameters None ### Request Example None ### Response #### Success Response (200) - **compressors** (array of strings) - A list of supported compressor names. #### Response Example { "compressors": ["blosclz", "lz4", "lz4hc", "zlib", "zstd"] } ``` -------------------------------- ### Get FfiVec as Mutable Slice Source: https://docs.rs/blosc2/0.2.2/blosc2/util/struct.FfiVec.html Provides a mutable slice view of the elements within the FfiVec. This allows modifying the data in place. ```rust pub fn as_mut_slice(&mut self) -> &mut [T] ``` -------------------------------- ### Get FfiVec as Slice Source: https://docs.rs/blosc2/0.2.2/blosc2/util/struct.FfiVec.html Provides an immutable slice view of the elements within the FfiVec. This allows reading the data without modifying it. ```rust pub fn as_slice(&self) -> &[T] ``` -------------------------------- ### Get Native Endianness Source: https://docs.rs/blosc2/0.2.2/blosc2/nd/enum.Endianness.html Retrieves the native endianness of the current system. This is useful for ensuring data is processed with the correct byte order. ```rust pub fn native() -> Self ```