clq
浏览(404) +
2023-03-10 08:52:36 发表
编辑
关键字:
[未测试] golang 下解压 rar
https://github.com/mholt/archiver
https://blog.csdn.net/lengyue1084/article/details/125104802
另外 golang 的标准库就是支持 zip 格式的。参考
https://blog.csdn.net/K346K346/article/details/122441250
--------------------------------------------------------
package main
import (
"fmt"
"github.com/mholt/archiver/v3"
)
func main() {
filename := "./file/新建 DOC 文档.rar"
rar := archiver.Rar{}
passwordMap := []string{"11111","abcdef","123456"}
for k, v := range passwordMap {
rar.Password = v
err := rar.Unarchive(filename, "./file/demo02")
if err != nil {
fmt.Println(err)
continue
}
fmt.Printf("password:%v,计算了%v次",v,k)
}
}
//reading file in rar archive: rardecode: incorrect password
//reading file in rar archive: rardecode: incorrect password
//password:123456,计算了2次map[one:1]
--------------------------------------------------------
https://blog.csdn.net/K346K346/article/details/122441250
package main
import (
"archive/zip"
"fmt"
"io"
"os"
"path/filepath"
"strings"
)
func main() {
dst := "output"
archive, err := zip.OpenReader("archive.zip")
if err != nil {
panic(err)
}
defer archive.Close()
for _, f := range archive.File {
filePath := filepath.Join(dst, f.Name)
fmt.Println("unzipping file ", filePath)
if !strings.HasPrefix(filePath, filepath.Clean(dst)+string(os.PathSeparator)) {
fmt.Println("invalid file path")
return
}
if f.FileInfo().IsDir() {
fmt.Println("creating directory...")
os.MkdirAll(filePath, os.ModePerm)
continue
}
if err := os.MkdirAll(filepath.Dir(filePath), os.ModePerm); err != nil {
panic(err)
}
dstFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
if err != nil {
panic(err)
}
fileInArchive, err := f.Open()
if err != nil {
panic(err)
}
if _, err := io.Copy(dstFile, fileInArchive); err != nil {
panic(err)
}
dstFile.Close()
fileInArchive.Close()
}
}
NEWBT官方QQ群1: 276678893
可求档连环画,漫画;询问文本处理大师等软件使用技巧;求档softhub软件下载及使用技巧.
但不可"开车",严禁国家敏感话题,不可求档涉及版权的文档软件.
验证问题说明申请入群原因即可.