I'm trying to find an interface which allows me to create a stream which allows seeking (just a Reader is fine, too) from either a file or []byte
, but can't seem to find anything in the godoc. Some of the types in the bufio
package would work quite well, but they don't appear to support seeking.
Is there something I overlooked which would fit what I'm looking for?
Both *os.File
(for files) and *bytes.Reader
(for having an io.Reader
from a []byte
) implement the io.Seeker
interface and thus have a Seek
method.
io.Seeker is implemented by...
*bytes.Reader
*io.SectionReader
io.ReadSeeker
io.WriteSeeker
io.ReadWriteSeeker
mime/multipart.File
net/http.File
*os.File
*strings.Reader
So if you're working with a file, thus very likely *os.File
, you don't need to do anything additional to be able to seek it. Just make sure that if you're using interfaces instead of concrete types that you do not want an io.Reader
but an io.ReadSeeker
.