Standard library / io

io.NopCloser()

Wraps a Reader with a Close method that does nothing; does not close an underlying resource. Expected stdout: 'x <nil>\n'.

Formal Syntax & Structure

go syntaxgo
func NopCloser(r Reader) ReadCloser

Parameters & Attributes

NameTypeDescription
rReaderSource reader.

Return Value

ReadCloser

Wraps a Reader with a Close method that does nothing; does not close an underlying resource.

Working Example

Example Snippetgo
package main
import (  "fmt"  "io"  "strings")
func main() {  r := io.NopCloser(strings.NewReader("x"))  b, _ := io.ReadAll(r)  fmt.Println(string(b), r.Close())}
Go Reference