Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sparsefile-0.1.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

sparsefile-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file sparsefile-0.1.0.tar.gz.

File metadata

  • Download URL: sparsefile-0.1.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

File hashes

Hashes for sparsefile-0.1.0.tar.gz
Algorithm Hash digest
SHA256 78a0d8799f7f3f856813322daaa5705eb3536f5bc879f6b9c2e66d932178984a
MD5 b88b6376ec58a00ac96bc2d8c285a236
BLAKE2b-256 c31d9c23dfb8c19b94ed57042dfdaada34eaf361c1839bda665e36a0edc18154

See more details on using hashes here.

File details

Details for the file sparsefile-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sparsefile-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

File hashes

Hashes for sparsefile-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b953d6ffa95526d01e5c4005ed0e75030b7fd6d71cae8689bc0ab01ad10fb1f
MD5 00a976f8b0f5e7e3e2027dfd97e31120
BLAKE2b-256 0930fdd86ee6249d269fbd523caed5457828673f8e596df6023af74552584f3e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page