]> Cypherpunks repositories - gostls13.git/commitdiff
embed: guarantee the returned file of FS.Open implements io.Seeker
authorHajime Hoshi <hajimehoshi@gmail.com>
Mon, 26 Apr 2021 13:32:21 +0000 (22:32 +0900)
committerHajime Hoshi <hajimehoshi@gmail.com>
Fri, 10 Sep 2021 13:30:50 +0000 (13:30 +0000)
Fixes golang/go#45745

Change-Id: Ib49a9605a38074f544a5d28116862e191cea8c0f
Reviewed-on: https://go-review.googlesource.com/c/go/+/313352
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Than McIntosh <thanm@google.com>

src/embed/embed.go

index 5dcd7f227d888063a6615b3913b283624ab6abd0..f87cc5b963912fbdfcf3f5be3e227d3a8412c412 100644 (file)
@@ -291,6 +291,8 @@ func (f FS) readDir(dir string) []file {
 }
 
 // Open opens the named file for reading and returns it as an fs.File.
+//
+// The returned file implements io.Seeker when the file is not a directory.
 func (f FS) Open(name string) (fs.File, error) {
        file := f.lookup(name)
        if file == nil {
@@ -338,6 +340,10 @@ type openFile struct {
        offset int64 // current read offset
 }
 
+var (
+       _ io.Seeker = (*openFile)(nil)
+)
+
 func (f *openFile) Close() error               { return nil }
 func (f *openFile) Stat() (fs.FileInfo, error) { return f.f, nil }