adam-gui/vendor/fyne.io/fyne/v2/storage/resource.go
2024-04-29 19:13:50 +02:00

26 lines
575 B
Go

package storage
import (
"io"
"fyne.io/fyne/v2"
)
// LoadResourceFromURI creates a new StaticResource in memory using the contents of the specified URI.
// The URI will be opened using the current driver, so valid schemas will vary from platform to platform.
// The file:// schema will always work.
func LoadResourceFromURI(u fyne.URI) (fyne.Resource, error) {
read, err := Reader(u)
if err != nil {
return nil, err
}
defer read.Close()
bytes, err := io.ReadAll(read)
if err != nil {
return nil, err
}
return fyne.NewStaticResource(u.Name(), bytes), nil
}