mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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/48873 Reviewed-by: Kevin Burke <kev@inburke.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
0593ad1e23
commit
0a633c3bbe
1 changed files with 22 additions and 0 deletions
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue