Skip to main content

Utilities to divide a buffer into smaller buffers

Project description

io-chunks

Man, I wish there was a way to split this opened file into smaller subfiles to read any part of it independently!

-- No one ever

I made a library for it anyway.

What's this?

This library contains utilities (well, one utility) to get a Python buffer from another buffer, allowing you to read from each of them separately.

Let me show you an example.

from io_chunks import RawIOChunk

with open("test_file", "w") as file_handle:
    file_handle.write("Hello beautiful world!")

with open("test_file", "rb") as file_handle:
    # Create a "chunk" with the first 5 bytes
    chunk_hello = RawIOChunk(file_handle, 5)
    # Create a "chunk" starting at position 16 with the last 6 bytes
    chunk_world = RawIOChunk(file_handle, size=6, start=16)
    # This prints b'Hello'
    print(chunk_hello.read())
    # This prints b'world!'
    print(chunk_world.read())
    # Now, this prints b'Hello beautiful world!' to demostrate that the original
    # `file_handle` pointer wasn't altered at all!
    print(file_handle.read())

Amazing, right?

Why?

While writing a parser I found this class to be somewhat useful, around 7 years ago.

While today I don't really see it today, I decided to clean it up and released it in case it's useful for someone.

Install

Use pip:

$ pip install io-chunks

Documentation

You can read it at readthedocs.

Run the tests

Create a venv with your favorite tool and activate it. Then, install the development dependencies and execute pytest:

$ pip install -r requirements-dev.txt
$ pytest

Alternatively, to execute the tests using tox:

$ pip install tox
$ tox

License

MIT

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

io-chunks-2.0.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

io_chunks-2.0.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file io-chunks-2.0.0.tar.gz.

File metadata

  • Download URL: io-chunks-2.0.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for io-chunks-2.0.0.tar.gz
Algorithm Hash digest
SHA256 69c9bba17d044145937f1eda9d8fd18dfdcf897bb2118450f8a33a1ff516467c
MD5 004209b23235252c3eb0bebe2a40b8f7
BLAKE2b-256 5e5f2491af0e4fc26358483ce76ade106413d96b3fa3ad2b57d07213667cc253

See more details on using hashes here.

File details

Details for the file io_chunks-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: io_chunks-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for io_chunks-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fe54da77abba45a88cbe8344fea86c69af0f525bee4552667d8e0c37f38fce86
MD5 0a05b3f8007b2955dac6533a29858e2a
BLAKE2b-256 423c92409d0bf850f9a54bcb9916ba3b6ed7a7158dc43df0b56d1714372d8d1d

See more details on using hashes here.

Supported by

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