如何选择一个流作为decrypt_file
操作的输出gnupg
?
文档和代码似乎表明这是不可能的。如果我是正确的(见下文),有哪些可能的解决方法?
~~~
该文档似乎表明这是不可能的:
decrypt_file(filename, always_trust=False, passphrase=None, output=None)¶
with " output (str) -- 将解密的输出写入的文件名。"
~~~
打开代码,我看到:
def decrypt_file(self, file, always_trust=False, passphrase=None,
output=None, extra_args=None):
args = ["--decrypt"]
if output: # write the output to a file with the specified name
self.set_output_without_confirmation(args, output)
if always_trust: # pragma: no cover
args.append("--always-trust")
if extra_args:
args.extend(extra_args)
result = self.result_map['crypt'](self)
self._handle_io(args, file, result, passphrase, binary=True)
logger.debug('decrypt result: %r', result.data)
return result
它指向 set_output_without_confirmation
,确认这个想法是您传递了一个字符串文件名:
def set_output_without_confirmation(self, args, output):
"If writing to a file which exists, avoid a confirmation message."
if os.path.exists(output):
# We need to avoid an overwrite confirmation message
args.extend(['--yes'])
args.extend(['--output', no_quote(output)])