How to Use io.Copy, io.CopyN, and io.CopyBuffer

Use io.Copy for full transfers, io.CopyN for fixed sizes, and io.CopyBuffer for high-performance streaming with a reusable buffer.

Use io.Copy to transfer all data, io.CopyN to transfer a fixed byte count, and io.CopyBuffer to reuse a buffer for performance.

// Copy all data from src to dst
n, err := io.Copy(dst, src)

// Copy exactly 1024 bytes
n, err := io.CopyN(dst, src, 1024)

// Copy all data using a reusable 32KB buffer
buf := make([]byte, 32<<10)
n, err := io.CopyBuffer(dst, src, buf)