MCPcopy Create free account
hub / github.com/LanceLRQ/deer-executor / UnZip

Function UnZip

common/persistence/problems/utils.go:33–62  ·  view source on GitHub ↗

UnZip do unzip

(zipArchive *zip.ReadCloser, destDir string)

Source from the content-addressed store, hash-verified

31
32// UnZip do unzip
33func UnZip(zipArchive *zip.ReadCloser, destDir string) error {
34 return WalkZip(zipArchive, func(f *zip.File) error {
35 fpath := filepath.Join(destDir, f.Name)
36 if f.FileInfo().IsDir() {
37 _ = os.MkdirAll(fpath, os.ModePerm)
38 } else {
39 if err := os.MkdirAll(filepath.Dir(fpath), os.ModePerm); err != nil {
40 return err
41 }
42
43 inFile, err := f.Open()
44 if err != nil {
45 return err
46 }
47 defer inFile.Close()
48
49 outFile, err := os.OpenFile(fpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
50 if err != nil {
51 return err
52 }
53 defer outFile.Close()
54
55 _, err = io.Copy(outFile, inFile)
56 if err != nil {
57 return err
58 }
59 }
60 return nil
61 })
62}
63
64// WalkZip walk in zip
65func WalkZip(zipArchive *zip.ReadCloser, walkFunc func(file *zip.File) error) error {

Callers 2

ReadProblemInfoFunction · 0.85
ReadProblemInfoZipFunction · 0.85

Calls 1

WalkZipFunction · 0.85

Tested by

no test coverage detected