Standard library / io

io.PipeReader.Read()

Reads bytes from the synchronous pipe, blocking until a writer or closure is available. Expected stdout: '2 ab <nil>\n'.

Formal Syntax & Structure

go syntaxgo
func (r *PipeReader) Read(data []byte) (n int, err error)

Parameters & Attributes

NameTypeDescription
data[]byteInput bytes or destination storage, according to operation.

Return Value

(n int, err error)

Reads bytes from the synchronous pipe, blocking until a writer or closure is available.

Working Example

Example Snippetgo
package main
import (  "fmt"  "io")
func main() {  r, w := io.Pipe()  defer r.Close()  go func() { defer w.Close(); w.Write([]byte("ab")) }()  b := make([]byte, 2)  n, e := r.Read(b)  fmt.Println(n, string(b[:n]), e)}
Go Reference