Standard library / io

io.NewSectionReader()

Exposes a bounded section of a ReaderAt, with offsets relative to the section start. Expected stdout: 'cde <nil>\n'.

Formal Syntax & Structure

go syntaxgo
func NewSectionReader(r ReaderAt, off int64, n int64) *SectionReader

Parameters & Attributes

NameTypeDescription
rReaderAtSource reader.
offint64Relative or base byte offset, as described above.
nint64Requested byte count or bound.

Return Value

*SectionReader

Exposes a bounded section of a ReaderAt, with offsets relative to the section start.

Working Example

Example Snippetgo
package main
import (  "fmt"  "io"  "strings")
func main() {  r := io.NewSectionReader(strings.NewReader("abcdef"), 2, 3)  b, e := io.ReadAll(r)  fmt.Println(string(b), e)}
Go Reference