MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / chunk_content

Function chunk_content

atomic-core/src/change/format_v3/chunking.rs:481–515  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

479/// }
480/// ```
481pub 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///

Callers 15

serializeMethod · 0.85
chunk_content_with_statsFunction · 0.85
test_chunk_empty_dataFunction · 0.85
test_chunk_tiny_dataFunction · 0.85
test_chunk_medium_dataFunction · 0.85
test_chunk_large_dataFunction · 0.85

Calls 4

hashFunction · 0.85
is_emptyMethod · 0.45
lenMethod · 0.45
as_bytesMethod · 0.45