Looks like you want to use a "readinto" method to reduce data copying. One problem is that it is not specified exactly what kind of object "copyfileobj" supports reading from. The documentation only says "file-like". According to the glossary, this means io.RawIOBase, BufferedIOBase, or TextIOBase. However TextIOBase doesn't have a "readinto" method. And it wouldn't be hard to find that someone has written their own class that doesn't have "readinto" either. The other problem is you still need to support a negative "length" value, which is easier to do by calling "read".
Martin, your points got me thinking... to make a proper copy of a file, it should be done using bytes! Text IO could easily lead to corrupting your file. for example (current function): with open(old_path, 'r', encoding='latin-1') as fsrc: with open(new_path, 'w') as fdst: copyfileobj(fsrc, fdst) This would lead you to have wrongly encoded file with different filesize.
Ok, updated the patch to account for: - improved memory usage for bytes io using readinto - still supporting negative length - potential encoding mismatch bug fix while using text io did i miss anything?