MCPcopy
hub / github.com/spicetify/cli / Unzip

Function Unzip

src/utils/utils.go:39–81  ·  view source on GitHub ↗

Unzip unzips zip

(src, dest string)

Source from the content-addressed store, hash-verified

37
38// Unzip unzips zip
39func Unzip(src, dest string) error {
40 r, err := zip.OpenReader(src)
41 if err != nil {
42 return err
43 }
44 defer r.Close()
45
46 for _, f := range r.File {
47 rc, err := f.Open()
48 if err != nil {
49 return err
50 }
51 defer rc.Close()
52
53 fpath := filepath.Join(dest, f.Name)
54 if f.FileInfo().IsDir() {
55 os.MkdirAll(fpath, 0700)
56 } else {
57 var fdir string
58 if lastIndex := strings.LastIndex(fpath, string(os.PathSeparator)); lastIndex > -1 {
59 fdir = fpath[:lastIndex]
60 }
61
62 err = os.MkdirAll(fdir, 0700)
63 if err != nil {
64 log.Fatal(err)
65 return err
66 }
67 f, err := os.OpenFile(
68 fpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0700)
69 if err != nil {
70 return err
71 }
72 defer f.Close()
73
74 _, err = io.Copy(f, rc)
75 if err != nil {
76 return err
77 }
78 }
79 }
80 return nil
81}
82
83// Copy .
84func Copy(src, dest string, recursive bool, filters []string) error {

Callers 2

ExtractFunction · 0.92
UpdateFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected