func unzip()

in astro/tvm/utils.go [56:100]


func unzip(zipfilePath string, destDir string) error {
	r, err := zip.OpenReader(zipfilePath)
	if err != nil {
		return err
	}
	defer r.Close()

	for _, f := range r.File {
		// Get file data
		fh, err := f.Open()
		if err != nil {
			return err
		}
		defer fh.Close()

		path := filepath.Join(destDir, f.Name)
		if !strings.HasPrefix(path, filepath.Clean(destDir)+string(os.PathSeparator)) {
			return fmt.Errorf("illegal file path in zip: %s", path)
		}

		if f.FileInfo().IsDir() {
			// Directory
			os.MkdirAll(path, os.ModePerm)
		} else {
			// File
			if err = os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
				return err
			}

			out, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
			if err != nil {
				return err
			}

			_, err = io.Copy(out, fh)

			out.Close()

			if err != nil {
				return err
			}
		}
	}
	return nil
}