用Golang解压缩LZMA2 7z文件

时间:2019-06-15 18:25:49

标签: go compression lzma

我尝试使用“ github.com/ulikunitz/xz/lzma”包解压缩LZMA2 7z文件。但我收到错误panic: lzma: unsupported chunk header byte

我不了解这种行为,因为标头中的魔术字节表示7-zip archive data, version 0.4see

文件

enter image description here

文件作为base64:     N3q8ryccAAQs1zX / DgAAAAAAAABaBaAAAAAAAAALA

代码

file, err := os.Open(`file.7z`)
if err != nil {
    panic(err)
}

s, err := file.Stat()
if err != nil {
    panic(err)
}

fmt.Println("Length:", s.Size())

rB := bufio.NewReader(file)
r,err := lzma.NewReader2(rB) // NewReader2 because of LZMA2 
if err != nil {
    panic(err)
}

fullpath := path.Join(dir, "file.txt")
f, err := os.Create(fullpath)
if err != nil {
    panic(err)
}

_, err = io.Copy(f,r)
if err != nil {
    panic(err) // panic: lzma: unsupported chunk header byte
}

0 个答案:

没有答案
相关问题