resource.go 575 B

12345678910111213141516171819202122232425
  1. package storage
  2. import (
  3. "io"
  4. "fyne.io/fyne/v2"
  5. )
  6. // LoadResourceFromURI creates a new StaticResource in memory using the contents of the specified URI.
  7. // The URI will be opened using the current driver, so valid schemas will vary from platform to platform.
  8. // The file:// schema will always work.
  9. func LoadResourceFromURI(u fyne.URI) (fyne.Resource, error) {
  10. read, err := Reader(u)
  11. if err != nil {
  12. return nil, err
  13. }
  14. defer read.Close()
  15. bytes, err := io.ReadAll(read)
  16. if err != nil {
  17. return nil, err
  18. }
  19. return fyne.NewStaticResource(u.Name(), bytes), nil
  20. }