diff options
author | Greg Stein <gstein@lyra.org> | 2000-07-12 09:55:30 +0000 |
---|---|---|
committer | Greg Stein <gstein@lyra.org> | 2000-07-12 09:55:30 +0000 |
commit | 42bb8b3987c8be80e97d49ad9476ff1c61c7413b (patch) | |
tree | 0ca3fa7de067d822cdc75423510cd7373de9197a /Lib/shutil.py | |
parent | 35e459c3eb60634f7edfa77824a468b52a479dc7 (diff) | |
download | cpython-git-42bb8b3987c8be80e97d49ad9476ff1c61c7413b.tar.gz |
apply patch #100868 from Moshe Zadka:
refactor the copying of file data. new: shutil.copyfileobj(fsrc, fdst)
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r-- | Lib/shutil.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py index 88abd1095c..dfde236136 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -9,6 +9,15 @@ import sys 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() |