def next(resp=None, exc=None, tb=None): if resp and resp.data: ctxt['res'].append(resp.data) ctxt['offset'] += len(resp.data) if ctxt['count'] == 0: if offset is None: self.offset = ctxt['offset'] return callback(''.join(ctxt['res']), exc, tb) n = min(ctxt['count'], self.iounit) ctxt['count'] -= n self._dorpc(fcall.Tread(offset=ctxt['offset'], count=n), next, fail or callback)
def read(self, count=None, offset=None, buf=''): if count is None: count = self.iounit res = [] with self.lock: offs = self.offset if offset is not None: offs = offset while count > 0: n = min(count, self.iounit) count -= n resp = self._dorpc(fcall.Tread(offset=offs, count=n)) data = resp.data offs += len(data) res.append(data) if len(data) < n: break if offset is None: self.offset = offs return ''.join(res)