Skip to main content

Dirty quick binary file management library

Project description

DirtyIO

Description

At least python 3.5 is needed to use this module

DirtyIO was designed to ease the processing of binary data by providing an interface to break down the reading and writing process into comprehensible pieces.

Documentation

DirtyReader

Interface laid over a file pointer for reading actions
  • constructor(Path)

    Takes path string or a Pathlib.Path (not a file pointer!) as an argument and returns an instance of DirtyReader. Path will be checked for sanity. In case the path is not a file, an empty DirtyReader is returned.

  • is_reader_valid

    Checks whether the Reader is empty or not.

  • read_*(amount)

    Reads a provided amount of of chunks of the underlying file and returns it as a byte, if amount=1, or a byte array if amount>1. The chunk size ranges from singular bytes to qwords (4 words aka 8 bytes). A list of the names for the availabe chunk sizes can be found below.

  • read_*_ints(amount,be=True,sig=False)

    Reads a provided amount of of chunks of the underlying file and returns it as an int, if amount=1, or an int array if amount>1. The be flag (whether the bytes shall be interpreted as big endian) and the sig flag (whether the bytes shall be interpreted as a signed number) can be specified, but are optional. The chunk size ranges from singular bytes to qwords (4 words aka 8 bytes). A list of the names for the availabe chunk sizes can be found below.

  • read_nt_string()

    Reads and returns a null terminated string. In case the End of file has been reached before the string gets terminated, an error is thrown and the file is reverted to the previous state.

  • pad_out()

    Sets the pointer to the nearest word (4 byte) border. The 1 to 3 bytes are seen as padding and are omitted.

  • skip_*()

    Skip one chunk of the underlying file omitting it in the process. The chunk size ranges from singular bytes to qwords (4 words aka 8 bytes). A list of the names for the availabe chunk sizes can be found below.

  • rebase(Path)

    close underlying file and switch to another. Returns whether the switch was successful. If not, the state is not changed, aka the old file is still open.

  • passthrough functions

    Since the underlying file pointer shall not be accessed for consistency reasons, there are some functions which are just passed through the native file pointer object.

    • tell()

      Returns the distance between current position and beginning of file in bytes.

    • seek(amount, mode)

      pushes the file pointer to a another point in the file. This function was enabled to allow custom reverting via tell-seek pattern. It was designed to be the last resort. Please treat it as such.

    • dirty_bytes(amount)

      returns the "dirty" byte string of specified length. This function was enabled to allow processing of data that should not be interpreted, e.g. non null terminating textual data. It was designed to be the last resort. Please treat it as such.

    • close

      closes the file and emptying the DirtyReader. Just like with regular file pointers, it is highly advised to use this function after everything is done.

DirtyWriter

Interface laid over a file pointer for writing actions
  • constructor(Path)

    Takes path string or a Pathlib.Path (not a file pointer!) as an argument and returns an instance of DirtyWriter. Path will be checked for sanity. In case the path is not a file, an empty DirtyWriter is returned.

  • is_writer_valid()

    Checks whether the Writer is empty or not.

  • write_bytes(bytes)

    Writes a byte(string) or byte array to the file

  • write_ints(ints,be=true,sign=false)

    Writes an int or int array to the file. The be flag (whether the bytes shall be interpreted as big endian) and the sig flag (whether the bytes shall be interpreted as a signed number) can be specified, but are optional.

  • write_bytes_as_nt_string(bs)

    writes the bytestring or bytearray to the file and adds a null terminator byte at the end.

  • rebase(Path)

    close underlying file and switch to another. Returns whether the switch was successful. If not, the state is not changed, aka the old file is still open.

  • passthrough functions

    Since the underlying file pointer shall not be accessed for consistency reasons, there are some functions which are just passed through the native file pointer object.

    • close()

      closes the file and emptying the DirtyReader. Just like with regular file pointers, it is highly advised to use this function after everything is done.

chunk size names

The following is the list of names that can replace the star from the functions above:
  • byte 1 Byte
  • word 2 Byte (Word)
  • triplet 3 Byte
  • dword 4 Byte (Double Word)
  • quintet 5 Byte
  • sextet 6 Byte
  • septet 7 Byte
  • qword 8 Byte (Quadruple Word)

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

DirtyIO-A13XIS-1.0.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

DirtyIO_A13XIS-1.0.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file DirtyIO-A13XIS-1.0.0.tar.gz.

File metadata

  • Download URL: DirtyIO-A13XIS-1.0.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

File hashes

Hashes for DirtyIO-A13XIS-1.0.0.tar.gz
Algorithm Hash digest
SHA256 585d692716924aa60e69c90994f9a4a82c1ea58538f5d15bc51da0b5893c5f51
MD5 f9df81485830aa1097bb25a38b3ff6fc
BLAKE2b-256 d8e38cfe2babbe709e9081167088193b39e4e02a241e19d3e53615dc146b4b9c

See more details on using hashes here.

File details

Details for the file DirtyIO_A13XIS-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: DirtyIO_A13XIS-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

File hashes

Hashes for DirtyIO_A13XIS-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 54eca814fddbaa5e6b32e213001ab3bc8d2b2c9938940d862432e124a9adc7c7
MD5 e6bdeaecfa3901241e3998a0d2154d9d
BLAKE2b-256 2987a578bd1221d5a5d845197f766d6207fe09b1659dddcb66b552916d40172f

See more details on using hashes here.

Supported by

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