Split content into variable-size chunks using FastCDC. Returns a list of [`ContentChunk`] descriptors. Each chunk's data can be accessed via `&data[chunk.offset..chunk.offset + chunk.length]` or via [`ContentChunk::data`]. # Small Data Handling If the input data is smaller than `options.min_size`, a single chunk is returned covering the entire input. If the input is empty, an empty vector is re
(data: &[u8], options: &ChunkingOptions)
| 479 | /// } |
| 480 | /// ``` |
| 481 | pub fn chunk_content(data: &[u8], options: &ChunkingOptions) -> Vec<ContentChunk> { |
| 482 | if data.is_empty() { |
| 483 | return Vec::new(); |
| 484 | } |
| 485 | |
| 486 | // For data smaller than min_size, return a single chunk |
| 487 | if data.len() <= options.min_size { |
| 488 | return vec![ContentChunk { |
| 489 | offset: 0, |
| 490 | length: data.len(), |
| 491 | hash: *blake3::hash(data).as_bytes(), |
| 492 | index: 0, |
| 493 | }]; |
| 494 | } |
| 495 | |
| 496 | let chunker = fastcdc::v2020::FastCDC::new( |
| 497 | data, |
| 498 | options.min_size as u32, |
| 499 | options.avg_size as u32, |
| 500 | options.max_size as u32, |
| 501 | ); |
| 502 | |
| 503 | chunker |
| 504 | .enumerate() |
| 505 | .map(|(i, chunk)| { |
| 506 | let chunk_data = &data[chunk.offset..chunk.offset + chunk.length]; |
| 507 | ContentChunk { |
| 508 | offset: chunk.offset, |
| 509 | length: chunk.length, |
| 510 | hash: *blake3::hash(chunk_data).as_bytes(), |
| 511 | index: i as u32, |
| 512 | } |
| 513 | }) |
| 514 | .collect() |
| 515 | } |
| 516 | |
| 517 | /// Split content into chunks and return chunking statistics. |
| 518 | /// |