Closed as not planned
Closed as not planned
Description
Hi there, I'm enjoying the go1.16 RC, I'm trying to migrate some code from using ioutil.ReadFile to fs.ReadFile while staying backwards-compatible. I'm running into two things:
- It's not possible to make code that does something like
ioutil.ReadFile("./path/to/file.txt")
work withos.DirFS(".")
, because it rejects the leading./
- There is no way to have absolute paths for the same reason, because 'Open should reject attempts to open names that do not satisfy ValidPath(name)' according to the fs.FS documentation
I can get around those things by doing something like this:
// osFS is an fs.FS implementation that just passes on to os.Open
type osFS struct{}
func (c osFS) Open(name string) (fs.File, error) {
return os.Open(name)
}
Which is technically an invalid implementation, although it's not entirely clear why those restrictions are in place. It would be nice if something like the above osFS
was built-in, so there's a clear migration path from ioutil.ReadFile
to fs.ReadFile
.
What version of Go are you using (go version
)?
$ go version go1.16rc1 darwin/arm64