MCPcopy
hub / github.com/pocketbase/pocketbase / zipAddFS

Function zipAddFS

tools/archive/create.go:45–91  ·  view source on GitHub ↗

note remove after similar method is added in the std lib (https://github.com/golang/go/issues/54898)

(w *zip.Writer, fsys fs.FS, skipPaths ...string)

Source from the content-addressed store, hash-verified

43
44// note remove after similar method is added in the std lib (https://github.com/golang/go/issues/54898)
45func zipAddFS(w *zip.Writer, fsys fs.FS, skipPaths ...string) error {
46 return fs.WalkDir(fsys, ".", func(name string, d fs.DirEntry, err error) error {
47 if err != nil {
48 return err
49 }
50
51 if d.IsDir() {
52 return nil
53 }
54
55 // skip
56 for _, ignore := range skipPaths {
57 if ignore == name ||
58 strings.HasPrefix(filepath.Clean(name)+string(os.PathSeparator), filepath.Clean(ignore)+string(os.PathSeparator)) {
59 return nil
60 }
61 }
62
63 info, err := d.Info()
64 if err != nil {
65 return err
66 }
67
68 h, err := zip.FileInfoHeader(info)
69 if err != nil {
70 return err
71 }
72
73 h.Name = name
74 h.Method = zip.Deflate
75
76 fw, err := w.CreateHeader(h)
77 if err != nil {
78 return err
79 }
80
81 f, err := fsys.Open(name)
82 if err != nil {
83 return err
84 }
85 defer f.Close()
86
87 _, err = io.Copy(fw, f)
88
89 return err
90 })
91}

Callers 1

CreateFunction · 0.85

Calls 3

OpenMethod · 0.65
CloseMethod · 0.65
CopyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…