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.
Related concepts
- io.Readeruses · io.Reader is a Go standard-library interface whose Read method reads bytes into a supplied buffer and reports the number read and any error.
- io.Writeruses · io.Writer is a Go interface whose Write method accepts a byte sequence and returns the number of bytes written and any error.
- bufferinguses · Buffering is the temporary storage of data or work between production and consumption to accommodate differences in processing rates, absorb interruptions, or improve transfer efficiency.
- payloaduses · A payload is the data, code, or other material carried by or attached to a message, token, system, or operation.
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.

