file, err := os.Open("example.txt") if err != nil { log.Fatal(err) } defer file.Close() readSeeker := io.ReadSeeker(file) buffer := make([]byte, 10) readSeeker.Read(buffer) readSeeker.Seek(0, io.SeekStart)
bytesReader := bytes.NewReader([]byte("Hello, world!")) readSeeker := io.ReadSeeker(bytesReader) buffer1 := make([]byte, 5) readSeeker.Read(buffer1) readSeeker.Seek(0, io.SeekStart) buffer2 := make([]byte, 10) readSeeker.Read(buffer2)In this example, we create a byte reader and a read seeker using that reader. We then read the first 5 bytes into a buffer, seek back to the start of the stream, and read the next 10 bytes into a separate buffer. The ReadSeeker interface is part of the io package in Go's standard library.