diff --git a/Lib/shutil.py b/Lib/shutil.py index 88abd1095c0..dfde2361369 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -9,6 +9,15 @@ import stat +def copyfileobj(fsrc, fdst, length=16*1024): + """copy data from file-like object fsrc to file-like object fdst""" + while 1: + buf = fsrc.read(length) + if not buf: + break + fdst.write(buf) + + def copyfile(src, dst): """Copy data from src to dst""" fsrc = None @@ -16,11 +25,7 @@ def copyfile(src, dst): try: fsrc = open(src, 'rb') fdst = open(dst, 'wb') - while 1: - buf = fsrc.read(16*1024) - if not buf: - break - fdst.write(buf) + copyfileobj(fsrc, fdst) finally: if fdst: fdst.close()