io.PipeWriter.Close() Function in Golang with Examples Last Updated : 05 May, 2020 Comments Improve Suggest changes Like Article Like Report In Go language, io packages supply fundamental interfaces to the I/O primitives. And its principal job is to enclose the ongoing implementations of such king of primitives. The PipeWriter.Close() function in Go language is used to close the writer. However, successive reads from the PipeReader i.e, read half of the pipe will not return any bytes and an EOF error is returned. Moreover, this function is defined under the io package. Here, you need to import the "io" package in order to use these functions. Syntax: func (w *PipeWriter) Close() error Here, "w" is a pointer to the PipeWriter. Where PipeWriter is the write half of a pipe. Return value: It returns the content written before Close method. And successive reads from the PipeReader i.e read half of the pipe will not return any bytes after calling Close() method and an EOF error will be returned. Example 1: C // Golang program to illustrate the usage of // io.PipeWriter.Close() function // Including main package package main // Importing fmt and io import ( "fmt" "io" ) // Calling main func main() { // Calling Pipe method pipeReader, pipeWriter := io.Pipe() // Calling Close method in go function after // two Write operations go func() { pipeWriter.Write([]byte("GfG")) pipeWriter.Write([]byte("GeeksforGeeks")) pipeWriter.Close() // Again calling Write method pipeWriter.Write([]byte("GfG is a CS-Portal.")) }() // Creating buffer using make keyword // of specified length buffer := make([]byte, 50) // Using for loop for i := 0; i < 4; i++ { // Reading the contents in buffer n, err := pipeReader.Read(buffer) // If error is not nil panic if err != nil { panic(err) } // Prints the content read in buffer fmt.Printf("%s\n", buffer[:n]) } } Output: GfG GeeksforGeeks panic: EOF goroutine 1 [running]: main.main() /tmp/sandbox342418232/prog.go:42 +0x2d1 Here, the content of the two Write operations are returned as they are written before the Close() method but the content written after the Close method is not returned and an EOF error is thrown instead. Example 2: C // Golang program to illustrate the usage of // io.PipeWriter.Close() function // Including main package package main // Importing fmt and io import ( "fmt" "io" ) // Calling main func main() { // Calling Pipe method pipeReader, pipeWriter := io.Pipe() // Calling Close method in go function go func() { pipeWriter.Close() // Calling Write method pipeWriter.Write([]byte("GfG is a CS-Portal.")) }() // Creating buffer using make keyword // of specified length buffer := make([]byte, 50) // Using for loop for i := 0; i < 4; i++ { // Reading the contents in buffer n, err := pipeReader.Read(buffer) // If error is not nil panic if err != nil { panic(err) } // Prints the content read in buffer fmt.Printf("%s\n", buffer[:n]) } } Output: panic: EOF goroutine 1 [running]: main.main() /tmp/sandbox173042396/prog.go:40 +0x2d1 Here, no Write operation is performed before Close method so no content is returned and an EOF error is thrown. Comment More infoAdvertise with us Next Article io.PipeWriter.Close() Function in Golang with Examples nidhi1352singh Follow Improve Article Tags : Go Language Golang-io Similar Reads Go Tutorial Go or you say Golang is a procedural and statically typed programming language having the syntax similar to C programming language. It was developed in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson at Google but launched in 2009 as an open-source programming language and mainly used in Google 2 min read Go Programming Language (Introduction) Go is a procedural programming language. It was developed in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson at Google but launched in 2009 as an open-source programming language. Programs are assembled by using packages, for efficient management of dependencies. This language also supports env 11 min read time.Sleep() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Sleep() function in Go language is used to stop the latest go-routine for at least the stated duration d. And a negative or zero duration of sleep will cause this method to return instantly. Moreover, t 3 min read Learn Free Programming Languages In this rapidly growing world, programming languages are also rapidly expanding, and it is very hard to determine the exact number of programming languages. Programming languages are an essential part of software development because they create a communication bridge between humans and computers. No 9 min read Golang Tutorial - Learn Go Programming Language This Golang tutorial provides you with all the insights into Go Language programming, Here we provide the basics, from how to install Golang to advanced concepts of Go programming with stable examples. So, if you are a professional and a beginner, this free Golang tutorial is the best place for your 10 min read strings.Contains Function in Golang with Examples strings.Contains Function in Golang is used to check the given letters present in the given string or not. If the letter is present in the given string, then it will return true, otherwise, return false. Syntax:Â func Contains(str, substr string) bool Here, str is the original string and substr is t 2 min read Interfaces in Golang In Go, an interface is a type that lists methods without providing their code. You canât create an instance of an interface directly, but you can make a variable of the interface type to store any value that has the needed methods.Exampletype Shape interface { Area() float64 Perimeter() float64}In t 3 min read Top 10 Golang Project Ideas with Source Code in 2025 Golang, or Go, a programming language was created by Google. It's widely used for building different kinds of applications like websites and cloud services. The fastest way to master this language is by building projects related to it. This article introduces 10 beginner-friendly to medium-difficult 8 min read fmt.Sprintf() Function in Golang With Examples In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.Sprintf() function in Go language formats according to a format specifier and returns the resulting string. Moreover, this function is defined under the fmt package. Here, you 2 min read Top 10 Golang Frameworks in 2025 Golang (or Go) is an open-source compiled programming language that is used to build simple, systematic, and secure software. It was designed by Google in the year 2007 and has been readily adopted by developers all over the world due to its features like memory safety, structural typing, garbage co 9 min read Like