github.com/drone/drone-cache-lib@v0.0.0-20200806063744-981868645a25/archive/util/util.go (about) 1 package util 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/drone/drone-cache-lib/archive" 8 "github.com/drone/drone-cache-lib/archive/tar" 9 "github.com/drone/drone-cache-lib/archive/tgz" 10 ) 11 12 // FromFilename determines the archive format to use based on the name. 13 func FromFilename(name string) (archive.Archive, error) { 14 if strings.HasSuffix(name, ".tar") { 15 return tar.New(), nil 16 } 17 18 if strings.HasSuffix(name, ".tgz") || strings.HasSuffix(name, ".tar.gz") { 19 return tgz.New(), nil 20 } 21 22 return nil, fmt.Errorf("Unknown file format for archive %s", name) 23 }