def stream_copy(source, destination, chunk_size=(512 * 1024)):
 br = 0
 while True:
  chunk = source.read(chunk_size)
  destination.write(chunk)
  br += len(chunk)
  if (len(chunk) < chunk_size):
   break
 return br

def stream_copy ( source , destination , chunk_size = ( 512 * 1024 ) ) : br = 0 while True : chunk = source . read ( chunk_size ) destination . write ( chunk ) br += len ( chunk ) if ( len ( chunk ) < chunk_size ) : break return br
copy all data from the source stream into the destination stream in chunks of size chunk_size :return: amount of bytes written .