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

Function copy_content_from_change

atomic-repository/src/changestore/mod.rs:136–164  ·  view source on GitHub ↗
(
    hash: &Hash,
    change: &Change,
    start: usize,
    end: usize,
    buf: &mut [u8],
)

Source from the content-addressed store, hash-verified

134}
135
136fn copy_content_from_change(
137 hash: &Hash,
138 change: &Change,
139 start: usize,
140 end: usize,
141 buf: &mut [u8],
142) -> ChangeStoreResult<usize> {
143 if end > change.contents.len() {
144 return Err(ChangeStoreError::ContentOutOfBounds {
145 hash: hash.to_base32(),
146 requested_start: start,
147 requested_end: end,
148 content_len: change.contents.len(),
149 });
150 }
151
152 let len = end - start;
153 if buf.len() < len {
154 return Err(ChangeStoreError::ContentOutOfBounds {
155 hash: hash.to_base32(),
156 requested_start: start,
157 requested_end: end,
158 content_len: buf.len(),
159 });
160 }
161
162 buf[..len].copy_from_slice(&change.contents[start..end]);
163 Ok(len)
164}
165
166impl ChangeStore {
167 /// Create a new change store with the given directory and cache capacity.

Callers 1

copy_content_spanMethod · 0.85

Calls 2

lenMethod · 0.45
to_base32Method · 0.45

Tested by

no test coverage detected