Io.Copy
io.Copy is a Go standard-library function that copies bytes from an io.Reader to an io.Writer until input is exhausted or an error occurs.
Go by Example
io.Copy is a Go standard-library function that copies bytes from an io.Reader to an io.Writer and returns the number of bytes copied and any error.
- How it is used
- Counts or transfers streaming data while avoiding full-content buffering, especially when processing HTTP response bodies.
- How deep it goes
- Explains the Reader-to-Writer contract, 32 KB buffering, return values, EOF handling, and CopyBuffer trade-offs.
- Examples
- Uses discarded HTTP downloads, a complete Send helper, configurable buffers, and exercises with custom Reader and Writer implementations.
- What you can do after
- Apply io.Copy to stream HTTP bodies and other I/O sources while measuring transferred bytes and controlling memory use.
Go in Action, Second Edition
io.Copy transfers data from a Reader to a Writer until the input reaches end of file or an error occurs.
- How it is used
- Transfers streams between interchangeable readers and writers for file-copying and data-pipeline operations.
- How deep it goes
- Defines efficient Reader-to-Writer transfer and its EOF-or-error boundary, but defers implementation internals.
- Examples
- Uses file copying, streaming between sources and sinks, and partial-stream copying as practical cases.
- What you can do after
- Apply it via io.Copy to move data between any compatible Reader and Writer.
Also covered in
Related concepts
- io.Readeruses · io.Reader is a Go interface for reading bytes from a data source into a caller-provided buffer, reporting the number of bytes read and any error.
- io.Writeruses · io.Writer is a Go interface for writing bytes from a caller-provided sequence to a destination, reporting the number of bytes written and any error.
- bufferinguses · Buffering is the temporary storage of data between processing or transfer steps, often to accommodate differences in rates or reduce operation costs.
- payloaduses · A payload is the substantive data or code carried or delivered by a message, request, token, or other system component, apart from its descriptive or control information.
Questions about io.Copy
What is io.Copy?
io.Copy is a Go standard-library function that copies bytes from an io.Reader to an io.Writer until input is exhausted or an error occurs.
Which Manning books explain io.Copy?
Go by Example and Go in Action, Second Edition.
What is the difference between io.Copy and io.ReadAll?
io.Copy is a Go standard-library function that copies bytes from an io.Reader to an io.Writer until input is exhausted or an error occurs. io.ReadAll is a Go standard-library function that reads all available bytes from an io.Reader until EOF and returns them as a byte slice.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

