Standard library / io

io.SectionReader.Read()

Reads sequentially within the section and advances its cursor; does not read beyond the section. Expected stdout: '2 bc <nil>\n'.

Formal Syntax & Structure

go syntaxgo
func (s *SectionReader) Read(p []byte) (n int, err error)

Parameters & Attributes

NameTypeDescription
p[]byteByte slice supplied by the caller.

Return Value

(n int, err error)

Reads sequentially within the section and advances its cursor; does not read beyond the section.

Working Example

Example Snippetgo
package main
import (  "fmt"  "io"  "strings")
func main() {  s := io.NewSectionReader(strings.NewReader("abcd"), 1, 2)  b := make([]byte, 2)  n, e := s.Read(b)  fmt.Println(n, string(b), e)}
Go Reference