diff options
Diffstat (limited to 'policy/_policies/src/lib.rs')
| -rw-r--r-- | policy/_policies/src/lib.rs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/policy/_policies/src/lib.rs b/policy/_policies/src/lib.rs new file mode 100644 index 0000000..397579a --- /dev/null +++ b/policy/_policies/src/lib.rs @@ -0,0 +1,75 @@ +// 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<Vec<u32>, 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, + params: &HashMap<&str, &str>, +) -> Result<Vec<u32>, ChunkFailed> { + match policy_name { + "butck_fixed_size" => { + let mut stream = butck_fixed_size::FixedSizeStream::default(); + chunk_stream_process( + 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 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<u32> { + 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<u32> { + butck_fixed_size::chunk_fixed_size_stream(current_data, len, stream, params).await + } +}
\ No newline at end of file |
