def read(self, consumer, offset=0, size=None):
if size is None:
size = self.get_size() - offset
-
+ size = min(size, self.get_size() - offset)
if offset == 0 and size == self.get_size():
# don't use the cache, just do a normal streaming download
def _read_tail_done(mc):
self.failUnlessEqual("".join(mc.chunks), DATA[2:])
d.addCallback(_read_tail_done)
+ d.addCallback(lambda ign:
+ n.read(MemoryConsumer(), size=len(DATA)+1000))
+ def _read_too_much(mc):
+ self.failUnlessEqual("".join(mc.chunks), DATA)
+ d.addCallback(_read_too_much)
return d
d.addCallback(_test_read)