repository.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package mobile
  2. import (
  3. "fyne.io/fyne/v2"
  4. "fyne.io/fyne/v2/storage/repository"
  5. )
  6. // declare conformance with repository types
  7. var _ repository.Repository = (*mobileFileRepo)(nil)
  8. var _ repository.HierarchicalRepository = (*mobileFileRepo)(nil)
  9. var _ repository.ListableRepository = (*mobileFileRepo)(nil)
  10. var _ repository.WritableRepository = (*mobileFileRepo)(nil)
  11. type mobileFileRepo struct {
  12. }
  13. func (m *mobileFileRepo) CanList(u fyne.URI) (bool, error) {
  14. return canListURI(u), nil
  15. }
  16. func (m *mobileFileRepo) CanRead(u fyne.URI) (bool, error) {
  17. return true, nil // TODO check a file can be read
  18. }
  19. func (m *mobileFileRepo) CanWrite(u fyne.URI) (bool, error) {
  20. return true, nil // TODO check a file can be written
  21. }
  22. func (m *mobileFileRepo) Child(u fyne.URI, name string) (fyne.URI, error) {
  23. if u == nil || u.Scheme() != "file" {
  24. return nil, repository.ErrOperationNotSupported
  25. }
  26. return repository.GenericChild(u, name)
  27. }
  28. func (m *mobileFileRepo) CreateListable(u fyne.URI) error {
  29. return createListableURI(u)
  30. }
  31. func (m *mobileFileRepo) Delete(u fyne.URI) error {
  32. // TODO: implement this
  33. return repository.ErrOperationNotSupported
  34. }
  35. func (m *mobileFileRepo) Destroy(string) {
  36. }
  37. func (m *mobileFileRepo) Exists(u fyne.URI) (bool, error) {
  38. return existsURI(u)
  39. }
  40. func (m *mobileFileRepo) List(u fyne.URI) ([]fyne.URI, error) {
  41. return listURI(u)
  42. }
  43. func (m *mobileFileRepo) Parent(u fyne.URI) (fyne.URI, error) {
  44. if u == nil || u.Scheme() != "file" {
  45. return nil, repository.ErrOperationNotSupported
  46. }
  47. return repository.GenericParent(u)
  48. }
  49. func (m *mobileFileRepo) Reader(u fyne.URI) (fyne.URIReadCloser, error) {
  50. return fileReaderForURI(u)
  51. }
  52. func (m *mobileFileRepo) Writer(u fyne.URI) (fyne.URIWriteCloser, error) {
  53. return fileWriterForURI(u)
  54. }