-
Notifications
You must be signed in to change notification settings - Fork 18k
io/fs: provide backwards-compatible migration path from ioutil.ReadFile to fs.ReadFile #44286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You can just create a simple compatibility decorator like this:
You can get a lot more fancy like allowing absolute paths or add logging to ease migration. |
Related: #44279 |
cc @rsc |
Perhaps |
I don't think this is something that can generally be done. You should also consider using the new Root apis for constraining access. https://pkg.go.dev/os#Root |
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:
ioutil.ReadFile("./path/to/file.txt")
work withos.DirFS(".")
, because it rejects the leading./
I can get around those things by doing something like this:
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 fromioutil.ReadFile
tofs.ReadFile
.What version of Go are you using (
go version
)?The text was updated successfully, but these errors were encountered: