[英]How to stream and decrypt large files in S3 with GPG using Ruby
我正在S3中处理非常大的文件,这些文件需要解密并保存回S3中。 我们的磁盘空间和内存有限,因此流式传输是我们的最佳选择。
我正在使用ruby-gpgme宝石。
这是我到目前为止的内容:
require 'gpgme'
require 'aws-sdk'
s3_credentials = Aws::Credentials.new(AWS_ACCESS_KEY_ID, AWS_SECRET_KEY_ID)
s3_client = Aws::S3::Client.new(credentials: s3_credentials)
source_file = 'in_file.gpg'
object_key = "upload/#{source_file}"
destination = File.open('out.txt', 'w+b')
crypto = GPGME::Crypto.new
source = File.open(source_file)
s3_client.get_object(bucket: bucket, key: object_key) do |chunk|
crypto.decrypt(chunk, password: password, output: destination)
end
# As a follow-up, I will setup the script to stream directly back out to S3
# S3.get_object > GPG.decrypt > S3.upload_part
这样可以成功解密并写入第一个块,但是在处理下一个块之前解密失败。
我假设这是因为第一个块未正确终止,并且.decrypt不会连续从流本身读取数据。
关于如何将块作为流传递以进行解密的任何想法?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.