-
Notifications
You must be signed in to change notification settings - Fork 117
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
WIP: fs.FS support #175
WIP: fs.FS support #175
Conversation
So each filesystem would implement
I am not sure what you mean by this. Can you show a practical example? |
Yes, that's right! And please find the practical example in the related issue comment. |
I still don't get the wrapper issue? |
Okay I'll elaborate more when I get to my laptop. I'm on the road now... |
So, my thoughts on the implementation, as I see it. I may be wrong in some points as I'm still new to go. As you can see from my wip patchset, there are very few receiver methods missing for the
Having such minor changes here I'm not tempted to write a wrapper, to be honest. Now to incompatibilities: Also, it is tempting to have ReadDirFS implemented, but So, here are my thoughts, pros and cons... Again, I might be totally wrong or missing something obvious, so please let me know! P.S.: I suspect, that having |
Now I understand where you are going. I think you are in the right direction. My only issue is something that is not the fault of your implementation, but actually of go in general. I cannot implement an interface by returning something that implements an interface, only the interface itself. Specifically, if As an example, see here. Despite the fact that So if I want to return I am not sure I like that restriction. That may push us towards the idea of a wrapper. So you could have: filesystem.Open() filesystem.File And maybe a wrapper, so you get (pseudo-code): fsys := diskfs.Open()
fsys.FS() // convert to fs.FS The reason I am concerned about having type File interface {
Stat() (FileInfo, error)
Read([]byte), (int, error)
Close() error
} Whereas we have |
Given that generics have landed now, it might be possible to use the existing types internally, and then use a generic to convert them to fs.FS compatible types at compile time? ie: https://play.golang.com/p/AHrNgLNYggU This is a bit convoluted, but it does get around the issue that interfaces which define functions that return interfaces are not satisfied if an implementation returns a concrete type (that implements the correct interface). |
I had a play with the generics idea, and it didn't play out as nicely as I'd hoped. But using a wrapper type seems to work ok - would this approach be simpler? #184 |
Yeah, I like what you did in #184 , let's move the detailed conversation over to there. |
@AndreRenaud glad you came up with less invasive solution, thank you! @deitch do you plan cutting a release any time soon? It's been almost a year since 1.3.0 and I'd be more than happy to see this feature included into the nearest release! |
Yeah, we can, I see no reason not to. Done |
Thank you for the prompt response, @deitch ! |
@deitch please find my first effors of implementing fs.FS here. Only iso9660 is supported as yet.
For me, there it is a dilemma: either to break the api and implement whole fs.FS support or implement wrapper functions. Wrappers look clumsily and, either way, require modifications of existing functions...
As for newly created
diskfs.OpenFile
, I've made it during my efforts of fiddling with "multi-layered fs.FS", i.e. say, I have aDirFS
, where I call fs.Open yeiding anfs.File
, which I pass todiskfs.OpenFile
to get to the next layer. Again, it's not very handy, asdiskfs.initDisk
requiresos.File
- another "why" in my journey..closes #169