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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbd8d6df5d4bd2aa152ff9716ce1556f0776457a8dba386a44729381186e4a68
|
|
| MD5 |
364dbca9eae93f7fa54f5bd6448a4aaf
|
|
| BLAKE2b-256 |
245885e03dfab79a81a694eea5bf3fa821f4cae7f08e176331a23888de129ea6
|
Provenance
The following attestation bundles were made for libunpacker-0.1.2.tar.gz:
Publisher:
python-publish.yml on Msmastr74/libunpacker
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
libunpacker-0.1.2.tar.gz -
Subject digest:
fbd8d6df5d4bd2aa152ff9716ce1556f0776457a8dba386a44729381186e4a68 - Sigstore transparency entry: 2110196165
- Sigstore integration time:
-
Permalink:
Msmastr74/libunpacker@c6537a26778740575f429bb9e5bc86544dedcb93 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/Msmastr74
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c6537a26778740575f429bb9e5bc86544dedcb93 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24f1ca4b4ee82168c0abb686ec83918e570ee767b4a5ba4d306373a9f243990e
|
|
| MD5 |
fc52632b979c46fde68c6ce67d592f19
|
|
| BLAKE2b-256 |
f94450979383b9fa0ce8504bd2d997da5f787f1ca7d3e3a8954813a696d1354a
|
Provenance
The following attestation bundles were made for libunpacker-0.1.2-py3-none-any.whl:
Publisher:
python-publish.yml on Msmastr74/libunpacker
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
libunpacker-0.1.2-py3-none-any.whl -
Subject digest:
24f1ca4b4ee82168c0abb686ec83918e570ee767b4a5ba4d306373a9f243990e - Sigstore transparency entry: 2110196224
- Sigstore integration time:
-
Permalink:
Msmastr74/libunpacker@c6537a26778740575f429bb9e5bc86544dedcb93 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/Msmastr74
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c6537a26778740575f429bb9e5bc86544dedcb93 -
Trigger Event:
release
-
Statement type: