Standard library / io
io.PipeWriter.Write()
Blocks until the reader consumes the bytes or the read end closes. Use a concurrent consumer. Expected stdout: '2 <nil> ab\n'.
Formal Syntax & Structure
go syntaxgo
func (w *PipeWriter) Write(data []byte) (n int, err error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| data | []byte | Input bytes or destination storage, according to operation. |
Return Value
(n int, err error)
Blocks until the reader consumes the bytes or the read end closes.
Working Example
Example Snippetgo
package main
import ( "fmt" "io")
func main() { r, w := io.Pipe() done := make(chan string, 1) go func() { defer r.Close(); b, _ := io.ReadAll(r); done <- string(b) }() n, e := w.Write([]byte("ab")) w.Close() fmt.Println(n, e, <-done)}