From 021bb89a9eff6bf2545f6930e63128cbf24537fe Mon Sep 17 00:00:00 2001 From: YoSTEALTH <35307184+YoSTEALTH@users.noreply.github.com> Date: Wed, 10 Jan 2018 15:00:41 -0600 Subject: [PATCH] Update shutil.py --- Lib/shutil.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Lib/shutil.py b/Lib/shutil.py index 3c02776a4065515..c0c3616edaaea5c 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -75,11 +75,18 @@ class RegistryError(Exception): def copyfileobj(fsrc, fdst, length=16*1024): """copy data from file-like object fsrc to file-like object fdst""" + buf = memoryview(bytearray(length)) + # localize + readinto = fsrc.readinto + write = fdst.write + # run loop while 1: - buf = fsrc.read(length) - if not buf: + recv_len = readinto(buf) + if recv_len < length: + # write remaining content if any. + write(buf[:recv_len]) break - fdst.write(buf) + write(buf) def _samefile(src, dst): # Macintosh, Unix.