decoder.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package decoder
  2. import (
  3. "io"
  4. "io/fs"
  5. "github.com/langgenius/dify-plugin-daemon/internal/types/entities/plugin_entities"
  6. )
  7. // PluginDecoder is an interface for decoding and interacting with plugin files
  8. type PluginDecoder interface {
  9. // Open initializes the decoder and prepares it for use
  10. Open() error
  11. // Walk traverses the plugin files and calls the provided function for each file
  12. // The function is called with the filename and directory of each file
  13. Walk(fn func(filename string, dir string) error) error
  14. // ReadFile reads the entire contents of a file and returns it as a byte slice
  15. ReadFile(filename string) ([]byte, error)
  16. // ReadDir reads the contents of a directory and returns a slice of strings
  17. // The strings are the filenames, it's a full path and directory will not be included
  18. // It executes recursively
  19. // Example:
  20. // - dirname: "config"
  21. // - return: ["config/settings.yaml", "config/default.yaml"]
  22. ReadDir(dirname string) ([]string, error)
  23. // Close releases any resources used by the decoder
  24. Close() error
  25. // Stat returns file info for the specified filename
  26. Stat(filename string) (fs.FileInfo, error)
  27. // FileReader returns an io.ReadCloser for reading the contents of a file
  28. // Remember to close the reader when done using it
  29. FileReader(filename string) (io.ReadCloser, error)
  30. // Signature returns the signature of the plugin, if available
  31. Signature() (string, error)
  32. // CreateTime returns the creation time of the plugin as a Unix timestamp
  33. CreateTime() (int64, error)
  34. // Manifest returns the manifest of the plugin
  35. Manifest() (plugin_entities.PluginDeclaration, error)
  36. // Assets returns a map of assets, the key is the filename, the value is the content
  37. Assets() (map[string][]byte, error)
  38. // UniqueIdentity returns the unique identity of the plugin
  39. UniqueIdentity() (plugin_entities.PluginUniqueIdentifier, error)
  40. // Checksum returns the checksum of the plugin
  41. Checksum() (string, error)
  42. }