io: add examples for (*SectionReader) Read/Size

Change-Id: Ie804f9a5d1d6beec210d2f8075c030a5c60a78ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/352152
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Heschi Kreinick <heschi@google.com>
This commit is contained in:
jiahua wang 2021-09-25 09:24:04 +08:00 committed by Heschi Kreinick
parent 9c43872bd8
commit 7eb0dd289a

View file

@ -160,6 +160,21 @@ func ExampleSectionReader() {
// io.Reader stream
}
func ExampleSectionReader_Read() {
r := strings.NewReader("some io.Reader stream to be read\n")
s := io.NewSectionReader(r, 5, 17)
buf := make([]byte, 9)
if _, err := s.Read(buf); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", buf)
// Output:
// io.Reader
}
func ExampleSectionReader_ReadAt() {
r := strings.NewReader("some io.Reader stream to be read\n")
s := io.NewSectionReader(r, 5, 17)
@ -191,6 +206,16 @@ func ExampleSectionReader_Seek() {
// stream
}
func ExampleSectionReader_Size() {
r := strings.NewReader("some io.Reader stream to be read\n")
s := io.NewSectionReader(r, 5, 17)
fmt.Println(s.Size())
// Output:
// 17
}
func ExampleSeeker_Seek() {
r := strings.NewReader("some io.Reader stream to be read\n")