Skip to main content

copy_reader

Function copy_reader 

Source
pub fn copy_reader(
    reader: impl Read,
    writer: &mut impl Write,
    max_bytes: u64,
) -> Result<ArtifactIdentity, CopyError>
Expand description

Copy one bounded source stream and identify its bytes with constant memory.

Shares the read traversal used by super::hash_reader and super::read_reader: observes at most max_bytes + 1 bytes, detects overflow before writing the overflowing chunk, and retries interrupted reads only. Writes each accepted chunk through Write::write_all, which handles short writes and interrupted writes according to the standard IO contract. The shared BoundedWriter validates accepted-byte counts before advancing through output. Impossible reader/writer counts return IO io::ErrorKind::InvalidData through the corresponding error variant. A blocking reader or writer’s deadlines remain caller-owned.

Bytes reach the sink before the complete source is known. Supply a private staging sink, check the returned identity against your admitted digest, and validate it before publication. Copying does not freeze source contents or independently re-read the sink. On every failure, partial output remains available to the caller; no identity for the complete input is returned.

This function never opens paths, flushes, synchronizes, renames or deletes files. It chooses no filesystem authority or publication/recovery policy.

§Errors

Returns distinct typed source/limit and sink failures. Output may contain a prefix even when the source is oversized or a write fails.