Skip to content
A python packer for packing sounds and files.
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENSE
README.md
packer.py
packer_utils.py

README.md

pypackfile

A python packer for packing sounds and files.

notes

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

todo

  • creating unit tests

requirements

For running successfully this pack you will need pycryptodome pip install pycryptodomex

Usage

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

packer.add_files(*files)

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.
packer.read_file(file)

params:

  • 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.
packer.extract(packname, dir='packs')

params:

  • 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
packer.export_credentials(file)

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')
You can’t perform that action at this time.