From: Eduardo Robles Elvira Date: Sat, 10 Aug 2013 08:46:04 +0000 (+0200) Subject: fixing readlin in tarfile, it was not working right after passing the bufsize X-Git-Tag: v2.2~113 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=f0fd5e3a7e9b3121f01bf45d70479f7a49fb11e3;p=python-delta-tar fixing readlin in tarfile, it was not working right after passing the bufsize --- diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index 237e841..1e7c3b9 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -687,15 +687,25 @@ class _Stream: def readline(self): """Reads just one line, new line character included """ - buf = [] - pos = 0 + # if \n in dbuf, no read neads to be done + if '\n' in self.dbuf: + pos = self.dbuf.index('\n') + 1 + ret = self.dbuf[:pos] + self.dbuf = self.dbuf[pos:] + return ret + + buf = [self.dbuf] + self.dbuf = "" while True: chunk = self._read(self.bufsize) + # nothing more to read, so return the buffer if not chunk: return ''.join(buf) buf.append(chunk) + + # if \n found, return the new line if '\n' in chunk: dbuf = ''.join(buf) pos = dbuf.index('\n') + 1