Skip to main content

A multi-format archive unpacking utility supporting deep recursion.

Project description

libunpacker

PyPI - Version License PyPI downloads GitHub Workflow Status

A multi-format archive unpacking utility supporting deep recursion.

How to use it

The simplest way to use it that can be used in almost any use case, is simply libunpacker.unpack(input_file_name, output_file_name), this will take input_file_name and write it's uncompressed contents to output_file_name. However with multi-file archives, output_file_name must be a directory (ending with a /, this is mandatory)

Operators

A fun little thing I added to this is operators, these allow you to have special functionality without doing some crazy weird tricks and workarounds so here they are:

input (arg 1)

  • //data:<raw file data>: rather than reading a file for the data, it takes it directly from your input!

output (arg 2)

  • //return: instead of writing the uncompressed file data, it returns it
  • //overwrite:<file path>: by default, it uses "xb" instead of "wb" for file writing, this makes it use "wb" (cannot be used on directories)
  • //autocreate:<directory path>: by default, it doesn't write to directories that don't exist, this makes it create directories that don't exist and continue on like normal

The unpackers class

This is what actually does the unpacking, the unpack function just handles the reading recursion and writing, although all of these functions require raw byte data as input and always return a dictionary containing the extracted data (fun little quirk I gotta include here, unpackers.xz() can handle LZMA1 compression, but unpack() can't)

yeah that's pretty much everything you need to know to use this thing, here's my testing script that demonstrates how it's actually used and all the supported formats for all you visual learners out there:

up.unpack("libunpacker_test_zip.zip", "ziptest/")
up.unpack("libunpacker_test_gzip.txt.gz", "gztest.txt")
up.unpack("libunpacker_test_bz2.txt.bz2", "bz2test.txt")
up.unpack("libunpacker_test_xz.txt.xz", "xztest.txt")
up.unpack("libunpacker_test_7z.7z", "7ztest/")
up.unpack("libunpacker_test_tar.tar", "tartest/")
up.unpack("libunpacker_test_rar.rar", "rartest/")
up.unpack("libunpacker_test_targz.tar.gz", "tgztest/")
up.unpack("libunpacker_test_big_one.tar.zip.7z.rar.gz.bz2.xz", "bigtest/")
up.unpack("libunpacker_test_big_one_disguised", "bigtest2/")
with open("libunpacker_test_lzma.txt.lzma", "rb") as f:
    lzma_file_data = up.unpackers.xz(f.read())
with open("lzmatest.txt", "wb") as f:
    f.write(lzma_file_data["file"])
# monofile testing
up.unpack("libunpacker_test_zip_mono.txt.zip", "zipmonotest.txt")
up.unpack("libunpacker_test_7z_mono.txt.7z", "7zmonotest.txt")
up.unpack("libunpacker_test_tar_mono.txt.tar", "tarmonotest.txt")
up.unpack("libunpacker_test_rar_mono.txt.rar", "rarmonotest.txt")
return_data = up.unpack("libunpacker_test_xz.txt.xz", "//return")
print(return_data)
with open("libunpacker_test_xz.txt.xz", "rb") as f:
    up.unpack(b"//data:" + f.read(), "datainputtest.txt")
up.unpack("libunpacker_test_xz.txt.xz", "//overwrite:datainputtest.txt")
up.unpack("libunpacker_test_zip.zip", "//autocreate:newdir/")

oh and if you're debugging, libunpacker.verbose == True makes it print out some runtime debugging info, it was useful for me

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

libunpacker-0.1.2.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

libunpacker-0.1.2-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file libunpacker-0.1.2.tar.gz.

File metadata

  • Download URL: libunpacker-0.1.2.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for libunpacker-0.1.2.tar.gz
Algorithm Hash digest
SHA256 fbd8d6df5d4bd2aa152ff9716ce1556f0776457a8dba386a44729381186e4a68
MD5 364dbca9eae93f7fa54f5bd6448a4aaf
BLAKE2b-256 245885e03dfab79a81a694eea5bf3fa821f4cae7f08e176331a23888de129ea6

See more details on using hashes here.

Provenance

The following attestation bundles were made for libunpacker-0.1.2.tar.gz:

Publisher: python-publish.yml on Msmastr74/libunpacker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libunpacker-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: libunpacker-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for libunpacker-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 24f1ca4b4ee82168c0abb686ec83918e570ee767b4a5ba4d306373a9f243990e
MD5 fc52632b979c46fde68c6ce67d592f19
BLAKE2b-256 f94450979383b9fa0ce8504bd2d997da5f787f1ca7d3e3a8954813a696d1354a

See more details on using hashes here.

Provenance

The following attestation bundles were made for libunpacker-0.1.2-py3-none-any.whl:

Publisher: python-publish.yml on Msmastr74/libunpacker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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