#################################
# IMutableFileNode
- # allow the use of IDownloadTarget
- def download(self, target):
- # fake it. TODO: make this cleaner.
- d = self.download_best_version()
- def _done(data):
- target.open(len(data))
- target.write(data)
- target.close()
- return target.finish()
- d.addCallback(_done)
- return d
-
-
- # new API
-
def download_best_version(self):
return self._do_serialized(self._download_best_version)
def _download_best_version(self):
return d
def download_best_version(self):
+ if self.storage_index not in self.all_contents:
+ return defer.fail(NotEnoughSharesError(None, 0, 3))
return defer.succeed(self.all_contents[self.storage_index])
def overwrite(self, new_contents):
if len(new_contents) > self.MUTABLE_SIZELIMIT:
self.all_contents[self.storage_index] = modifier(old_contents, None, True)
return None
- def download(self, target):
- if self.storage_index not in self.all_contents:
- f = failure.Failure(NotEnoughSharesError(None, 0, 3))
- target.fail(f)
- return defer.fail(f)
- data = self.all_contents[self.storage_index]
- target.open(len(data))
- target.write(data)
- target.close()
- return defer.maybeDeferred(target.finish)
- def download_to_data(self):
- if self.storage_index not in self.all_contents:
- return defer.fail(NotEnoughSharesError(None, 0, 3))
- data = self.all_contents[self.storage_index]
- return defer.succeed(data)
-
def make_mutable_file_cap():
return uri.WriteableSSKFileURI(writekey=os.urandom(16),
fingerprint=os.urandom(32))