Create sparse files and punch holes through existing files
Project description
sparsefile
This module implements sparse file
"hole punching" on GNU+Linux, Microsoft Windows, and probably Mac OS X (untested).
This allows you to quickly create sparse file gaps such that the gaps appear to be
filled with null (b"\0"
) bytes but they don't occupy any actual disk space.
This is a pure-Python module which uses ctypes
/pywin32
/fcntl
to do its dirty work.
Dependencies
pywin32
on Windows. None otherwise.
Examples
First import the library and choose an appropriate victim.
>>> from pathlib import Path
>>> import sparsefile
>>> path = Path("my_file.bin")
Then sparsification comes in three different flavours:
-
sparsefile.ensure_sparse(path, offset=1000, length=3000)
Make the byte range 1000-3999 (inclusive) sparse. If the OS or filesystem do not support the operation, raise a
SparsifyError
. -
sparsefile.ensure_zeros_maybe_sparse(path, offset=1000, length=3000)
Fill the byte range 1000-3999 (inclusive) with zeros. The byte range will also be sparse if the OS and filesystem support it. The function returns a boolean that indicates whether the byte range was successfully made sparse.
-
sparsefile.maybe_sparse(path, offset=1000, length=3000)
Try to make the byte range 1000-3999 (inclusive) sparse. Do nothing if the OS or filesystem do not support it. If the file is currently shorter than 4000 bytes, then it will remain so.
Issues
- The test suite is severely lacking.
- Hasn't been tested on OS X (sorry).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sparsefile-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b953d6ffa95526d01e5c4005ed0e75030b7fd6d71cae8689bc0ab01ad10fb1f |
|
MD5 | 00a976f8b0f5e7e3e2027dfd97e31120 |
|
BLAKE2b-256 | 0930fdd86ee6249d269fbd523caed5457828673f8e596df6023af74552584f3e |