Issue #27194: superfluous truncate calls in tarfile.py slow down extraction
Patch by Jason Fried.
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index 86e1cf9..721f9d7 100755
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -2150,10 +2150,10 @@
for offset, size in tarinfo.sparse:
target.seek(offset)
copyfileobj(source, target, size, ReadError)
+ target.seek(tarinfo.size)
+ target.truncate()
else:
copyfileobj(source, target, tarinfo.size, ReadError)
- target.seek(tarinfo.size)
- target.truncate()
def makeunknown(self, tarinfo, targetpath):
"""Make a file from a TarInfo object with an unknown type