use FileBodyProducer to read

This commit is contained in:
Kay Kurokawa 2017-10-25 16:04:35 -04:00
parent a5293de44b
commit 10ac86a99e

View file

@ -1,6 +1,8 @@
import binascii import binascii
import logging import logging
from twisted.internet import defer, threads from io import BytesIO
from twisted.internet import defer
from twisted.web.client import FileBodyProducer
from cryptography.hazmat.primitives.ciphers import Cipher, modes from cryptography.hazmat.primitives.ciphers import Cipher, modes
from cryptography.hazmat.primitives.ciphers.algorithms import AES from cryptography.hazmat.primitives.ciphers.algorithms import AES
from cryptography.hazmat.primitives.padding import PKCS7 from cryptography.hazmat.primitives.padding import PKCS7
@ -73,14 +75,17 @@ class StreamBlobDecryptor(object):
read_handle = self.blob.open_for_reading() read_handle = self.blob.open_for_reading()
@defer.inlineCallbacks
def decrypt_bytes(): def decrypt_bytes():
data = read_handle.read() producer = FileBodyProducer(read_handle)
self.buff += data buff = BytesIO()
self.len_read += len(data) yield producer.startProducing(buff)
self.buff = buff.getvalue()
self.len_read += len(self.buff)
write_bytes() write_bytes()
finish_decrypt() finish_decrypt()
d = threads.deferToThread(decrypt_bytes) d = decrypt_bytes()
return d return d