Created
December 19, 2017 00:57
-
-
Save nirs/c44882ab64f48926b54eecf02eea6efa to your computer and use it in GitHub Desktop.
Copying data from disk to disk using direct io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mmap | |
import io | |
from contextlib import closing | |
BUF_SIZE = 8 * 1024**2 | |
buf = mmap.mmap(-1, BUF_SIZE) | |
with closing(buf), io.FileIO(src_path, "r") as src, io.FileIO(dst_path, "r+") as dst: | |
while True: | |
read = src.readinto(buf) | |
if read == 0: | |
break # done | |
written = 0 | |
while written < read: | |
wbuf = buffer(buf, written, read - written) | |
written += dst.write(wbuf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment