transit.writeToFile: add hasher= argument
This commit is contained in:
parent
01ec5fb2a6
commit
d8f6126916
|
@ -419,8 +419,8 @@ class Connection(protocol.Protocol, policies.TimeoutMixin):
|
||||||
# optional callable which will be called on each write (with the number
|
# optional callable which will be called on each write (with the number
|
||||||
# of bytes written). Returns a Deferred that fires (with the number of
|
# of bytes written). Returns a Deferred that fires (with the number of
|
||||||
# bytes written) when the count is reached or the RecordPipe is closed.
|
# bytes written) when the count is reached or the RecordPipe is closed.
|
||||||
def writeToFile(self, f, expected, progress=None):
|
def writeToFile(self, f, expected, progress=None, hasher=None):
|
||||||
fc = FileConsumer(f, progress)
|
fc = FileConsumer(f, progress, hasher)
|
||||||
return self.connectConsumer(fc, expected)
|
return self.connectConsumer(fc, expected)
|
||||||
|
|
||||||
class OutboundConnectionFactory(protocol.ClientFactory):
|
class OutboundConnectionFactory(protocol.ClientFactory):
|
||||||
|
@ -863,13 +863,14 @@ class TransitReceiver(Common):
|
||||||
|
|
||||||
# based on twisted.protocols.ftp.FileConsumer, but don't close the filehandle
|
# based on twisted.protocols.ftp.FileConsumer, but don't close the filehandle
|
||||||
# when done, and add a progress function that gets called with the length of
|
# when done, and add a progress function that gets called with the length of
|
||||||
# each write.
|
# each write, and a hasher function that gets called with the data.
|
||||||
|
|
||||||
@implementer(interfaces.IConsumer)
|
@implementer(interfaces.IConsumer)
|
||||||
class FileConsumer:
|
class FileConsumer:
|
||||||
def __init__(self, f, progress=None):
|
def __init__(self, f, progress=None, hasher=None):
|
||||||
self._f = f
|
self._f = f
|
||||||
self._progress = progress
|
self._progress = progress
|
||||||
|
self._hasher = hasher
|
||||||
self._producer = None
|
self._producer = None
|
||||||
|
|
||||||
def registerProducer(self, producer, streaming):
|
def registerProducer(self, producer, streaming):
|
||||||
|
@ -881,6 +882,8 @@ class FileConsumer:
|
||||||
self._f.write(bytes)
|
self._f.write(bytes)
|
||||||
if self._progress:
|
if self._progress:
|
||||||
self._progress(len(bytes))
|
self._progress(len(bytes))
|
||||||
|
if self._hasher:
|
||||||
|
self._hasher(bytes)
|
||||||
|
|
||||||
def unregisterProducer(self):
|
def unregisterProducer(self):
|
||||||
assert self._producer
|
assert self._producer
|
||||||
|
|
Loading…
Reference in New Issue
Block a user