Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions Lib/tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def read(self, size=None):
if not buf:
break
t.append(buf)
buf = "".join(t)
buf = b"".join(t)
else:
buf = self._read(size)
self.pos += len(buf)
Expand All @@ -547,6 +547,7 @@ def _read(self, size):
return self.__read(size)

c = len(self.dbuf)
t = [self.dbuf]
while c < size:
buf = self.__read(self.bufsize)
if not buf:
Expand All @@ -555,26 +556,27 @@ def _read(self, size):
buf = self.cmp.decompress(buf)
except self.exception:
raise ReadError("invalid compressed data")
self.dbuf += buf
t.append(buf)
c += len(buf)
buf = self.dbuf[:size]
self.dbuf = self.dbuf[size:]
return buf
t = b"".join(t)
self.dbuf = t[size:]
return t[:size]

def __read(self, size):
"""Return size bytes from stream. If internal buffer is empty,
read another block from the stream.
"""
c = len(self.buf)
t = [self.buf]
while c < size:
buf = self.fileobj.read(self.bufsize)
if not buf:
break
self.buf += buf
t.append(buf)
c += len(buf)
buf = self.buf[:size]
self.buf = self.buf[size:]
return buf
t = b"".join(t)
self.buf = t[size:]
return t[:size]
# class _Stream

class _StreamProxy(object):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed a performance regression for reading streams with tarfile. The
buffered read should use a list, instead of appending to a bytes object.