pipe/stream gnupg output to tarfile in

前端 未结 1 1074
-上瘾入骨i
-上瘾入骨i 2021-01-28 02:55

I have the following code but obviously this is not real streaming. It is the best I could find but it reads the whole input file into memory first. I want to stream it to tarfi

相关标签:
1条回答
  • 2021-01-28 03:23

    Apparently, you cannot use real streaming using gpnupg module, gnupg module always reads whole output of gnupg into memory. So to use real streaming, you'll have to run gpg program directly. Here is a sample code (without proper error handling):

    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()
    
    0 讨论(0)
提交回复
热议问题