From b48cc5733b05137f106fd16d3bff9eaa756e9fb6 Mon Sep 17 00:00:00 2001 From: Cameron Dale Date: Sun, 6 Apr 2008 22:51:24 -0700 Subject: [PATCH] Minor update to the multiple peer downloading (still not working). --- apt_p2p/PeerManager.py | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/apt_p2p/PeerManager.py b/apt_p2p/PeerManager.py index df00399..90a35c5 100644 --- a/apt_p2p/PeerManager.py +++ b/apt_p2p/PeerManager.py @@ -149,10 +149,11 @@ class StreamToFile(defer.Deferred): @param hash: the hash object to use for the file """ self.stream = inputStream - self.outFile = outFile.open('w') + self.outFile = outFile self.hash = hash self.hash.new() self.length = self.stream.length + self.doneDefer = None def run(self): """Start the streaming.""" @@ -168,44 +169,16 @@ class StreamToFile(defer.Deferred): self.doneDefer.callback(self.hash) def _gotData(self, data): - self.peers[site]['pieces'] += data - - def read(self): - """Read some data from the stream.""" if self.outFile.closed: - return None - - # Read data from the stream, deal with the possible deferred - data = self.stream.read() - if isinstance(data, defer.Deferred): - data.addCallbacks(self._write, self._done) - return data - - self._write(data) - return data - - def _write(self, data): - """Write the stream data to the file and return it for others to use. + return - Also optionally decompresses it. - """ if data is None: self._done() - return data # Write and hash the streamed data self.outFile.write(data) self.hash.update(data) - return data - - def close(self): - """Clean everything up and return None to future reads.""" - self.length = 0 - self._done() - self.stream.close() - - class FileDownload: """Manage a download from a list of peers or a mirror. -- 2.39.5