A python packer for packing sounds and files.
This is really in an early, early beta, there fore things may be unstable. If you find any bug and you fixed it, feel free to send a pull request. I apologize in advance if the code is too messed up. Also, note that the encryption functions used here can be changed if needed. This is your choice
- creating unit tests
For running successfully this pack you will need pycryptodome pip install pycryptodomex
This library has a few functions
class packer(name='', dir='', encrypt=False, key='', IV='')
This constructor has default arguments, therefore the constructor can be called without passing any argument, and then call packer.create() with the arguments defined above. params:
- name (str) defines the name of the pack file to create. You can pass an absolute path, or a relative path to this argument. For example the name could be sounds.dat
- dir (str) defines the directory from where you'd like to collect the game data or files that you need in this pack.
- encrypt (bool) sets the pack to encrypted. If the encrypt parameter is true, the key and IV must be provided. If it is false, those can be left as blank
- key (str) or (bytes) if the pack is encrypted this value is necessary. this is the pack encryption key. It must be 16 or 32 bytes long.
- IV (str) or (bytes) ionitializzation vector (I don't know exactly what it is used for when encrypting, but it's required). Must be 16 bytes long. If the length provided is less than the minimum required the packer will generate the bytes that are missing. If the IV is not provided, the packer will generate a new one.
packer.create(self, name, dir, encrypted=False, key='', IV='')
Look parameters above
Adds a list of files to the packer. params:
- files (list) list of filenames that you want to add to the packer These filenames must be the name of existing files present in the target directory.
- file (str) the file in the pack that needs to be read. This will return the string with the file content of the selected file if the latter is present in the pack.
- packname (str) name of the pack to extract
- dir (str) the directory in which the pack will be extracted This method extracts the entire content of the packname targeted in the specified directory. The default directory in which the pack will be extracted is packs
this method exports the key and the IV of the packer in a file. In this way they can be used later on params:
- file (str) the file in which the data will be stored.
putting all to gether
# importing the packer import packer # defining the instancce which will hold the packer class p = packer.packer() # since I did not directly defined the constructor arguments, I will call create() p.create('test.dat', 'testdir', False) # we can now extract p.extract('test.dat')