fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design
https://fyne.io/
Other
24.48k stars 1.36k forks source link

storage: Support for getting an os.FileInfo (or similar) from URI #2134

Open Jacalz opened 3 years ago

Jacalz commented 3 years ago

Is your feature request related to a problem? Please describe:

For regular operating system file management, os.FileInfo (renamed to fs.FileInfo and used within the fs package as well as of Go 1.16) is a standardized way of getting information about certain parts of data. image This opens up the possibility of getting data such as size, permissions and modification date (if the URI has that data) and so on. While a URI technically does not need to be a file, it would be good to have it be able to return this type in order to thus be compatible with many other use cases and we can just fill in the data with as much as we have.

My personal use case for this is in wormhole-gui where I need to know how big the file is before it is being sent, and without buffering all the data to memory first, it is not quite possible to know that.

Is it possible to construct a solution with the existing API?

I think so. For regular files, this should be easy enough to just wrap os.Stat(). For other URI handling on mobile platforms, I think we would need to hook into platform specific APIs to get the data and then fill the os.FileMode with as much data as we can get.

Describe the solution you'd like to see:

We should be able to do something like Stat(uri fyne.URI) (os.FileMode, error).

cc @andydotxyz @charlesdaniels

andydotxyz commented 3 years ago

I do not think that using this exact interface works with our interface because not all URIs are files. However there are some things missing like Size() and ModTime() which we could consider adding to our storage implementation?

charlesdaniels commented 3 years ago

I agree with @andydotxyz. Golang's FileInfo system is very UNIX-centric, which won't apply on Windows, Mobile, and may not map well to other types of back-ends.

I think we should start by reviewing the prior art. How do other languages and toolkits that work in a cross-platform way handle this set of problems?