Skip to content

Commit

Permalink
Merge pull request goplus#571 from xushiwei/x
Browse files Browse the repository at this point in the history
pipedemo: todo
  • Loading branch information
xushiwei authored Jul 26, 2024
2 parents af06983 + c5d18d9 commit ec95d06
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions _cmptest/_pipedemo/pipe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"fmt"
"io"
)

func main() {
data := []byte("This is some data that needs to be stored in Body.")
pr, pw := io.Pipe()
go func() {
defer pw.Close()
if _, err := pw.Write(data); err != nil {
fmt.Println("Error writing to pipe:", err)
return
}
}()
defer pr.Close()

readData, err := io.ReadAll(pr)
if err != nil {
fmt.Println("Error reading from Body:", err)
return
}
fmt.Println("Body:", string(readData))
}

0 comments on commit ec95d06

Please sign in to comment.