Documentation ¶
Index ¶
- func AbsPath(path string) string
- func BaseDir() fs.FS
- func ChBaseDir(path string) (err error)
- func DirExists(filePath string) (bool, error)
- func FileExists(filePath string) (bool, error)
- func IsDir(path string) (bool, error)
- func RelativeToCurrentPath(path string) (string, error)
- func SaveFile(src io.ReadCloser, dst string) error
- func SaveToDisk(fileTree fs.FS, root string) (err error)
- func Sha1(root fs.FS, path string) (string, error)
- func ShortenFileBase(baseDir, fullPath string) string
- func Tar(src fs.FS, dst string) error
- func Untar(src, dst string) (err error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FileExists ¶
func RelativeToCurrentPath ¶
func SaveToDisk ¶
SaveToDisk saves the file tree to disk with path root. file tree is a tree of files from disk, memory or any other places which implement fs.FS.
func ShortenFileBase ¶
ShortenFileBase removes baseDir from fullPath (but keep the last element of baseDir). e.g. ShortenFileBase("a/b", "a/b/c.go") => "b/c.go"
Example ¶
package main import ( "fmt" . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" "github.com/asppj/appserver-template/pkg/utils/fs" ) type testParams struct { base, path, expectedPath string } var _ = Describe("Testing file", func() { DescribeTable("Testing ShortenFileBase", func(p testParams) { path := fs.ShortenFileBase(p.base, p.path) Expect(path).To(Equal(p.expectedPath)) }, Entry("short path", testParams{ base: "a", path: "a/b/c.go", expectedPath: "a/b/c.go", }), Entry("short path with '/'", testParams{ base: "a/", path: "a/b/c.go", expectedPath: "a/b/c.go", }), Entry("long path", testParams{ base: "a/b", path: "a/b/c.go", expectedPath: "b/c.go", }), Entry("long path with '/'", testParams{ base: "a/b/", path: "a/b/c.go", expectedPath: "b/c.go", }), Entry("longer path", testParams{ base: "a/d/b", path: "a/d/b/c.go", expectedPath: "b/c.go", }), Entry("empty path", testParams{ base: "", path: "b/c.go", expectedPath: "b/c.go", }), Entry("current path", testParams{ base: ".", path: "b/c.go", expectedPath: "b/c.go", }), Entry("root path", testParams{ base: "/", path: "/b/c.go", expectedPath: "b/c.go", }), ) }) func main() { fmt.Println(fs.ShortenFileBase("a", "a/b/c.go")) fmt.Println(fs.ShortenFileBase("a/", "a/b/c.go")) fmt.Println(fs.ShortenFileBase("a/b", "a/b/c.go")) fmt.Println(fs.ShortenFileBase("a/b/", "a/b/c.go")) fmt.Println(fs.ShortenFileBase("a/d/b", "a/d/b/c.go")) fmt.Println(fs.ShortenFileBase("", "b/c.go")) fmt.Println(fs.ShortenFileBase(".", "b/c.go")) fmt.Println(fs.ShortenFileBase("/", "/b/c.go")) }
Output: a/b/c.go a/b/c.go b/c.go b/c.go b/c.go b/c.go b/c.go b/c.go
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.