Commit 0a633c3b authored by Greg Poirier's avatar Greg Poirier Committed by Brad Fitzpatrick

io: Add example to io.Seeker's Seek() method.

While there's an example for SectionReader.Seek, if someone is
seeking documentation specifically about Seeker.Seek, they may
not immediately find the SectionReader example. Offset and whence
may not be entirely intuitive to new developers either, so include
examples of both positive/negative offsets and SeekStart/SeekEnd.

Change-Id: I5b7442ccf683d9706e9261c11bc0ea31a1ac21d4
Reviewed-on: https://go-review.googlesource.com/48873Reviewed-by: default avatarKevin Burke <kev@inburke.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 0593ad1e
......@@ -204,6 +204,28 @@ func ExampleSectionReader_Seek() {
// stream
}
func ExampleSeeker_Seek() {
r := strings.NewReader("some io.Reader stream to be read\n")
if _, err := io.Copy(os.Stdout, r); err != nil {
log.Fatal(err)
}
r.Seek(15, io.SeekStart)
if _, err := io.Copy(os.Stdout, r); err != nil {
log.Fatal(err)
}
r.Seek(-5, io.SeekEnd)
if _, err := io.Copy(os.Stdout, r); err != nil {
log.Fatal(err)
}
// Output:
// some io.Reader stream to be read
// stream to be read
// read
}
func ExampleMultiWriter() {
r := strings.NewReader("some io.Reader stream to be read\n")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment