FileChunkIO
raw JSON → 1.8 verified Mon Apr 27 auth: no python maintenance
FileChunkIO provides a file-like object representing a chunk of an OS-level file, supporting reading, writing, and random access within a byte range. Version 1.8 is the latest (2014), with no recent updates; stable but unmaintained.
pip install filechunkio Common errors
error FileChunkIO requires integer offset and bytes ↓
cause Passing non-integer types (e.g., strings) for offset or bytes raises TypeError.
fix
Convert offset and bytes to int explicitly: int(offset).
error ValueError: I/O operation on closed file ↓
cause Attempting to read/write after closing the FileChunkIO object.
fix
Ensure all operations are done within a context manager or before calling close().
Warnings
gotcha FileChunkIO does not support 'w' mode for writing arbitrarily; only 'r', 'r+', 'a', 'a+', 'w', 'w+'. Opening with 'w' truncates the entire file, not just the chunk range. ↓
fix Use 'r+' mode and write only within the intended byte range; avoid 'w' mode unless you intend to truncate the whole file.
deprecated This library is effectively unmaintained since 2014. No Python 3 support beyond basic compatibility; may have issues with newer Python versions (e.g., file descriptor handling). ↓
fix Consider alternatives like 'io.BytesIO' or 'mmap' if possible.
gotcha The 'bytes' parameter specifies the number of bytes in the chunk, not the end offset. The actual accessible region is [offset, offset+bytes). If 'bytes' is None, the chunk extends to end of file. ↓
fix Ensure you compute the correct byte count; do not mistake 'bytes' for end offset.
Imports
- FileChunkIO
from filechunkio import FileChunkIO
Quickstart
from filechunkio import FileChunkIO
with open('test.bin', 'wb') as f:
f.write(b'a' * 1024)
with FileChunkIO('test.bin', 'r', offset=0, bytes=512) as chunk:
data = chunk.read()
print(len(data)) # 512