[Pythonmac-SIG] copy() in macostools.py

Jakob Spies jakob.spies@spmtechnologies.com
Fri, 30 Nov 2001 10:08:00 +0100


The implementation of file copying in macostools.copy() looks like this

	d = ifp.read(BUFSIZ)
	while d:
		ofp.write(d)
		d = ifp.read(BUFSIZ)
		
It should, however, look similar to this:
	
	d = ifp.read(BUFFER_SIZE)
	while d:
		ofp.write(d)
		if (len(d) >= BUFFER_SIZE):
			# last read did not encounter EOF
			d = ifp.read(BUFFER_SIZE)
		else:
			# save useless but expensive read attempt
			break;

I think you get the point. 
I have tried this in a Python program mainly concerned with copying files
that are smaller than 512 KB (=BUFSIZ), and the speed improved significantly
(because of half as much file input accesses).