def safe_copyfileobj(fsrc, fdst, length=(16 * 1024), size=0):
 if (not size):
  return
 while (size > 0):
  buf = fsrc.read(min(length, size))
  if (not buf):
   break
  fdst.write(buf)
  size -= len(buf)

def safe_copyfileobj ( fsrc , fdst , length = ( 16 * 1024 ) , size = 0 ) : if ( not size ) : return while ( size > 0 ) : buf = fsrc . read ( min ( length , size ) ) if ( not buf ) : break fdst . write ( buf ) size -= len ( buf )
a version of shutil .