UPDATE: native with new hdiff type
This commit is contained in:
@@ -29,6 +29,41 @@ func IsFileIn7z(archivePath, fileInside string) (bool, error) {
|
||||
return false, fmt.Errorf("%s not found in %s", fileInside, archivePath)
|
||||
}
|
||||
|
||||
func ListFilesInZip(archivePath string) ([]string, error) {
|
||||
cmd := exec.Command(constant.Tool7zaExe.String(), "l", archivePath)
|
||||
var out bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
cmd.Stderr = &out
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return nil, fmt.Errorf("7za list failed: %v\nOutput: %s", err, out.String())
|
||||
}
|
||||
|
||||
lines := strings.Split(out.String(), "\n")
|
||||
var files []string
|
||||
foundTable := false
|
||||
|
||||
for _, line := range lines {
|
||||
if strings.HasPrefix(line, "----------") {
|
||||
if foundTable {
|
||||
break
|
||||
}
|
||||
foundTable = true
|
||||
continue
|
||||
}
|
||||
|
||||
if foundTable {
|
||||
fields := strings.Fields(line)
|
||||
if len(fields) >= 6 {
|
||||
fileName := strings.Join(fields[5:], " ")
|
||||
files = append(files, fileName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func ExtractAFileFromZip(archivePath, fileInside, outDir string) error {
|
||||
cmd := exec.Command(constant.Tool7zaExe.String(), "e", archivePath, fileInside, "-o"+outDir, "-y")
|
||||
cmd.Stdout = os.Stdout
|
||||
|
||||
Reference in New Issue
Block a user