barecat.io.copyfile#
Fast file copy utilities with kernel-space zero-copy when available.
Methods tried in order of preference: 1. splice (Linux, kernel-space, zero-copy, requires one pipe end) 2. copy_file_range (Linux 4.5+, kernel-space, zero-copy, file-to-file) 3. sendfile (kernel-space, file-to-file or file-to-socket) 4. Buffered user-space copy
For CRC32c variants, must use buffered copy since data needs to pass through user space.
Classes#
Generic enumeration. |
|
Encapsulates copy setup: file descriptors, offsets, overlap detection. |
Functions#
|
Copy bytes between file objects using the fastest available method. |
|
Copy bytes and compute CRC32c in a single pass (when possible). |
|
Compute CRC32c of file contents (read-only scan). |
|
Write n zero bytes. Tries fallocate first, falls back to buffered. |
|
Determine file descriptor type with single fstat call. |
|
Safely check if file object is seekable (handles broken seekable() methods). |
|
Buffered copy with optional CRC. Handles same-file backward overlap. |
|
Buffered copy until EOF. |
Copy within same file with overlap (memmove-style). |
|
Copy using copy_file_range (kernel-space, zero-copy). |
|
|
Copy using sendfile (kernel-space, dst must be socket). |
|
Copy using splice (kernel-space, requires one pipe end). |
Sync fd position to match Python's logical position. |