apply patch #100868 from Moshe Zadka:

refactor the copying of file data. new: shutil.copyfileobj(fsrc, fdst)
This commit is contained in:
Greg Stein 2000-07-12 09:55:30 +00:00
parent 35e459c3eb
commit 42bb8b3987
1 changed files with 10 additions and 5 deletions

View File

@ -9,6 +9,15 @@ import sys
import stat 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): def copyfile(src, dst):
"""Copy data from src to dst""" """Copy data from src to dst"""
fsrc = None fsrc = None
@ -16,11 +25,7 @@ def copyfile(src, dst):
try: try:
fsrc = open(src, 'rb') fsrc = open(src, 'rb')
fdst = open(dst, 'wb') fdst = open(dst, 'wb')
while 1: copyfileobj(fsrc, fdst)
buf = fsrc.read(16*1024)
if not buf:
break
fdst.write(buf)
finally: finally:
if fdst: if fdst:
fdst.close() fdst.close()