我能';我似乎没有得到golang';s openpgp库压缩我的输出
我在使用Golang的openpgp库进行压缩时遇到问题。我试图加密和压缩超过2G的文件,所以我使用文件缓冲区,即使这是一个可怕的做法。我的代码片段如下所示:我能';我似乎没有得到golang';s openpgp库压缩我的输出,go,zlib,openpgp,Go,Zlib,Openpgp,我在使用Golang的openpgp库进行压缩时遇到问题。我试图加密和压缩超过2G的文件,所以我使用文件缓冲区,即使这是一个可怕的做法。我的代码片段如下所示: newPath := path + ".gpg" // encrypt string fBuf, err := os.OpenFile(newPath, os.O_WRONLY|os.O_CREATE, 0644) defer fBuf.Close() if err != nil {
newPath := path + ".gpg"
// encrypt string
fBuf, err := os.OpenFile(newPath, os.O_WRONLY|os.O_CREATE, 0644)
defer fBuf.Close()
if err != nil {
return "", err
}
wc, err := openpgp.Encrypt(fBuf, entityList, nil, nil, pgpConfig)
defer wc.Close()
if err != nil {
return "", err
}
r, err := os.OpenFile(path, os.O_RDONLY, 0644)
defer r.Close()
if err != nil {
return "", err
}
if _, err := io.Copy(wc, r); err != nil {
return "", err
}
var pgpConfig = &packet.Config{
DefaultCompressionAlgo: packet.CompressionZLIB,
CompressionConfig: &packet.CompressionConfig{
Level: 6,
},
}
pgpConfig的定义如下:
newPath := path + ".gpg"
// encrypt string
fBuf, err := os.OpenFile(newPath, os.O_WRONLY|os.O_CREATE, 0644)
defer fBuf.Close()
if err != nil {
return "", err
}
wc, err := openpgp.Encrypt(fBuf, entityList, nil, nil, pgpConfig)
defer wc.Close()
if err != nil {
return "", err
}
r, err := os.OpenFile(path, os.O_RDONLY, 0644)
defer r.Close()
if err != nil {
return "", err
}
if _, err := io.Copy(wc, r); err != nil {
return "", err
}
var pgpConfig = &packet.Config{
DefaultCompressionAlgo: packet.CompressionZLIB,
CompressionConfig: &packet.CompressionConfig{
Level: 6,
},
}
目前,加密和解密工作完全符合预期,但绝对没有压缩。我尝试导入zlib库并直接使用它,但没有成功。。。同样,加密和解密可以工作,但不需要压缩。任何帮助都将不胜感激
谢谢