github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/file/resolver.go (about) 1 package file 2 3 import ( 4 "context" 5 "io" 6 ) 7 8 // Resolver is an interface that encompasses how to get specific file references and file contents for a generic data source. 9 type Resolver interface { 10 ContentResolver 11 PathResolver 12 LocationResolver 13 MetadataResolver 14 } 15 16 // ContentResolver knows how to get file content for a given Location 17 type ContentResolver interface { 18 FileContentsByLocation(Location) (io.ReadCloser, error) 19 } 20 21 type MetadataResolver interface { 22 FileMetadataByLocation(Location) (Metadata, error) 23 } 24 25 // PathResolver knows how to get a Location for given string paths and globs 26 type PathResolver interface { 27 // HasPath indicates if the given path exists in the underlying source. 28 // The implementation for this may vary, however, generally the following considerations should be made: 29 // - full symlink resolution should be performed on all requests 30 // - returns locations for any file or directory 31 HasPath(string) bool 32 33 // FilesByPath fetches a set of file references which have the given path (for an image, there may be multiple matches). 34 // The implementation for this may vary, however, generally the following considerations should be made: 35 // - full symlink resolution should be performed on all requests 36 // - only returns locations to files (NOT directories) 37 FilesByPath(paths ...string) ([]Location, error) 38 39 // FilesByGlob fetches a set of file references for the given glob matches 40 // The implementation for this may vary, however, generally the following considerations should be made: 41 // - full symlink resolution should be performed on all requests 42 // - if multiple paths to the same file are found, the best single match should be returned 43 // - only returns locations to files (NOT directories) 44 FilesByGlob(patterns ...string) ([]Location, error) 45 46 // FilesByMIMEType fetches a set of file references which the contents have been classified as one of the given MIME Types. 47 FilesByMIMEType(types ...string) ([]Location, error) 48 49 // RelativeFileByPath fetches a single file at the given path relative to the layer squash of the given reference. 50 // This is helpful when attempting to find a file that is in the same layer or lower as another file. 51 RelativeFileByPath(_ Location, path string) *Location 52 } 53 54 type LocationResolver interface { 55 // AllLocations returns a channel of all file references from the underlying source. 56 // The implementation for this may vary, however, generally the following considerations should be made: 57 // - NO symlink resolution should be performed on results 58 // - returns locations for any file or directory 59 AllLocations(ctx context.Context) <-chan Location 60 } 61 62 type WritableResolver interface { 63 Resolver 64 65 Write(location Location, reader io.Reader) error 66 }