Standard library / bytes

bytes.NewReader()

Creates a reader over the supplied byte slice; the reader does not copy the input, so avoid mutation while reading. Supports seeking and ReaderAt. Expected stdout: '2 2\n'.

Formal Syntax & Structure

go syntaxgo
func NewReader(b []byte) *Reader

Parameters & Attributes

NameTypeDescription
b[]byteByte slice to read without copying.

Return Value

*Reader

Creates a reader over the supplied byte slice; the reader does not copy the input, so avoid mutation while reading. Supports seeking and ReaderAt.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt")
func main() {  r := bytes.NewReader([]byte("go"))  fmt.Println(r.Len(), r.Size())}
Go Reference