Skip to main content

A multi-format archive unpacking utility supporting deep recursion.

Project description

libunpacker

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.0.tar.gz (3.1 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.0-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: libunpacker-0.1.0.tar.gz
  • Upload date:
  • Size: 3.1 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.0.tar.gz
Algorithm Hash digest
SHA256 bde607a595d775d822ecac2a1fea10a0a2750cb325f34b5774b90bd46a1e2434
MD5 135e7be45829244c507dfb04dddc44da
BLAKE2b-256 a6e65cb3d68645d3b445b68c1eaeb48875aadeffd637101ce3bd7c517880bd59

See more details on using hashes here.

Provenance

The following attestation bundles were made for libunpacker-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: libunpacker-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.2 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 24e9ce1bc7b731be797a907bbd0416b6fc96078fdb42994a758559816fdc7ab3
MD5 6438bfee97f0bfe4e9e5a084456b193d
BLAKE2b-256 835220755b333c707d4de90b9c25d09fbc9d4aea269eee5a2ab0b69f7df7c4ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for libunpacker-0.1.0-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