我有以下代码,但显然这不是真正的流媒体。这是我能找到的最好的,但它首先将整个输入文件读入内存。我想在解密巨大(>100Gb 文件)时将其流式传输到 tarfile 模块,而不使用所有内存
import tarfile, gnupg
gpg = gnupg.GPG(gnupghome='C:/Users/niels/.gnupg')
with open('103330-013.tar.gpg', 'r') as input_file:
decrypted_data = gpg.decrypt(input_file.read(), passphrase='aaa')
# decrypted_data.data contains the data
decrypted_stream = io.BytesIO(decrypted_data.data)
tar = tarfile.open(decrypted_stream, mode='r|')
tar.extractall()
tar.close()
显然,您不能使用 gpnupg 模块来使用真正的流,gnupg 模块总是将 gnupg 的整个输出读取到内存中。
因此,要使用真正的流媒体,您必须直接运行 gpg 程序。
这是示例代码(没有适当的错误处理):
import subprocess
import tarfile
with open('103330-013.tar.gpg', 'r') as input_file:
gpg = subprocess.Popen(("gpg", "--decrypt", "--homedir", 'C:/Users/niels/.gnupg', '--passphrase', 'aaa'), stdin=input_file, stdout=subprocess.PIPE)
tar = tarfile.open(fileobj=gpg.stdout, mode="r|")
tar.extractall()
tar.close()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)