Skip to content
Prev Previous commit
Next Next commit
Document some of optimizations os.copy_file_range can use implicitly
  • Loading branch information
illia-v committed May 24, 2022
commit 1e381265c3513fa1ab469f09fbadb2090c3c6699
5 changes: 4 additions & 1 deletion Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,10 @@ as internal buffering of data.

This copy is done without the additional cost of transferring data
from the kernel to user space and then back into the kernel. Additionally,
some filesystems could implement extra optimizations. The copy is done as if
some filesystems could implement extra optimizations, such as the use of
reflinks (i.e., two or more inodes that share pointers to the same
copy-on-write disk blocks; supported file systems include btrfs and XFS)
and server-side copy (in the case of NFS). The copy is done as if
both files are opened as binary.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function arguments are file descriptors. What does "binary" mean for file descriptors?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence is not new. I guess it means that bytes written to a destination file will be equal to ones read from the source file.

In contrary, if a file range is read in the text mode in Python and it is written in the text mode to a different file, bytes may differ. For example, line endings may be changed. See https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind to rephase the sentence to explain that? Explain that the copy does not change the line endings, for example?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 069651d.

BTW, shutil.copyfile looks to behave the same, but shutil.copyfileobj seems to respect the text mode.


The return value is the amount of bytes copied. This could be less than the
Expand Down