// Auto generated dependencies // If you find issues with the dependencies, please // 1. Delete all code after this comment // 2. Clear the auto generated part in `policy/_policies/Cargo.toml` // 3. Run `cargo run --bin butckrepo-refresh` in the Butchunker root directory pub mod error; pub mod stream_read; use error::ChunkFailed; use std::{collections::HashMap, path::Path}; use crate::stream_read::chunk_stream_process; /// Chunks the specified raw data using the specified chunking policy /// /// # Parameters /// - `policy_name`: Chunking policy name, currently supports 1 policies /// - `raw_data`: Raw data byte slice /// - `params`: Hashmap of parameters required by the chunking policy pub async fn chunk_with( policy_name: &str, raw_data: &[u8], params: &HashMap<&str, &str>, ) -> Result, ChunkFailed> { match policy_name { "butck_fixed_size" => Ok(butck_fixed_size::chunk(raw_data, params).await), _ => Err(ChunkFailed::PolicyNotFound), } } pub async fn chunk_stream_with( policy_name: &str, size: u32, path: &Path, callback: F, params: &HashMap<&str, &str>, ) -> Result<(), ChunkFailed> where F: FnMut(Vec) -> std::pin::Pin> + Send>>, { match policy_name { "butck_fixed_size" => { let mut stream = butck_fixed_size::FixedSizeStream::default(); chunk_stream_process( path, &mut stream, size, callback, params, async |current_data, len, stream, params| { butck_fixed_size::chunk_stream(current_data, len, stream, params).await }, ) .await } _ => Err(ChunkFailed::PolicyNotFound), } } pub async fn chunk_stream_display_boundaries( policy_name: &str, size: u32, path: &Path, params: &HashMap<&str, &str>, ) -> Result, ChunkFailed> { match policy_name { "butck_fixed_size" => { let mut stream = butck_fixed_size::FixedSizeStream::default(); crate::stream_read::chunk_stream_display_boundaries( path, &mut stream, size, params, async |current_data, len, stream, params| { butck_fixed_size::chunk_stream(current_data, len, stream, params).await }, ) .await } _ => Err(ChunkFailed::PolicyNotFound), } } pub fn policies() -> Vec<&'static str> { vec![ // butck_fixed_size "butck_fixed_size", ] } pub fn stream_policies() -> Vec<&'static str> { vec![ // butck_fixed_size "butck_fixed_size", ] } pub mod butck_fixed_size { pub use butck_fixed_size::FixedSizeStream; use std::collections::HashMap; pub async fn chunk(raw_data: &[u8], params: &HashMap<&str, &str>) -> Vec { butck_fixed_size::chunk_fixed_size(raw_data, params).await } pub async fn chunk_stream( current_data: &[u8], len: u32, stream: &mut butck_fixed_size::FixedSizeStream, params: &HashMap<&str, &str>, ) -> Option { butck_fixed_size::chunk_fixed_size_stream(current_data, len, stream, params).await } }