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#

_FdType

Generic enumeration.

_CopyContext

Encapsulates copy setup: file descriptors, offsets, overlap detection.

Functions#

copy(src, dst[, size, src_offset, dst_offset, bufsize])

Copy bytes between file objects using the fastest available method.

copy_crc32c(src, dst[, size, src_offset, dst_offset, ...])

Copy bytes and compute CRC32c in a single pass (when possible).

accumulate_crc32c(fileobj[, size, offset, bufsize, ...])

Compute CRC32c of file contents (read-only scan).

write_zeroes(file, n[, bufsize])

Write n zero bytes. Tries fallocate first, falls back to buffered.

_get_fd_type(fd)

Determine file descriptor type with single fstat call.

_is_seekable(f)

Safely check if file object is seekable (handles broken seekable() methods).

_copy_buffered(ctx[, compute_crc, initial_crc])

Buffered copy with optional CRC. Handles same-file backward overlap.

_copy_buffered_eof(ctx[, compute_crc, initial_crc])

Buffered copy until EOF.

_copy_same_file_overlap(ctx)

Copy within same file with overlap (memmove-style).

_copy_file_range_loop(ctx)

Copy using copy_file_range (kernel-space, zero-copy).

_copy_sendfile(ctx)

Copy using sendfile (kernel-space, dst must be socket).

_copy_splice(ctx)

Copy using splice (kernel-space, requires one pipe end).

_sync_position(f)

Sync fd position to match Python's logical position.