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) *SectionReaderParameters & Attributes
| Name | Type | Description |
|---|---|---|
| r | ReaderAt | Source reader. |
| off | int64 | Relative or base byte offset, as described above. |
| n | int64 | Requested 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)}