A library for manipulating BIG format archives
Project description
pyBIG
Python library to programatically manipulate .big files, the archive format used in many of the game titles created by Westwood studios.
This library is largely possible due to the work done by the OpenSage team (Link). Essentially this library is a python wrapper around the knowledge they gathered with some helper functions.
Installation
You can get it from Pypi: https://pypi.org/project/pyBIG/
pip install pyBIG
Usage
The library is based on the pyBIG.Archive object. This objects takes raw bytes representing a BIG archive. The decision to take raw bytes allow the user to decide where those bytes come from, whether a file stored in memory or on disk. There is also a class method, Archive.from_directory that allows you to load a directory on the disk painlessly.
You can modify the archive in memory with the following methods:
- Archive.edit_file(str, bytes)
- Archive.add_file(str, bytes)
- Archive.remove_file(str)
Each method takes a name which is the windows-format path to the file in the archive so something like 'data\ini\weapon.ini'. The methods that takes bytes represent the new contents of the file as bytes.
It is important to note that these methods do not actually modify the archive but it is as if. This does not update the entries or the raw bytes. If you want to update the archive you need to call Archive.repack(). This is an expensive operation which is only called automatically when the archive is saved or extracted. The rest is up to the user.
You can look at the tests for more examples.
from pyBIG import Archive
with open("test.big", "rb") as f:
archive = Archive(f.read())
# get the contents of a file as bytes
contents = archive.read_file("data\\ini\\weapon.ini")
#add a new file
archive.add_file("data\\ini\john.ini", b"this is the story of a man named john")
archive.repack()
#remove a file
archive.remove_file("data\\ini\\john.ini")
archive.repack()
#save the big file back to disk, this will also take care of repacking
# the file with the latest modified entries
archive.save("test.big")
# extract all the files in the archive
archive.extract("output/")
# load an archive from a directory
archive = Archive.from_directory("output/")
Advanced
In version 0.2.0, this library also makes the LargeArchive
object available. This special object does not store the entire file into memory, allowing for manipulation of large files. It works essentially the same except that reading is done from the file present on disk and functions are tied to that location. Repacking does the same as save on this object but it is recommended to instead use the save function.
It is important to note that adding and editing files in a LargeArchive stores them in memory. As such it is recommended to to save at regular interval to commit these changes to disk. The LargeArchive object exposes archive_memory_size
as a simple way of seeing how many bytes are currently stored directly on the object.
from pyBIG import LargeArchive
archive = LargeArchive("test.big")
TODO
- Investigate and implement proper compression (refpack)
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
File details
Details for the file pyBIG-0.5.0.tar.gz
.
File metadata
- Download URL: pyBIG-0.5.0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bed10c7fb3ef218fa7d7d0eab0ec90516fe1afe968c3ab629ec00eaeb380e433 |
|
MD5 | 8ebb7adc33494c6f9b2239fa1fe64490 |
|
BLAKE2b-256 | 575d0c28c66286bee921d375866a616732a45665786178452413a6664f10b50c |
File details
Details for the file pyBIG-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: pyBIG-0.5.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cbfa4181a7c0bbe44472f0fd7fca926ab4dc2a84242f4f700b2cf52500ba088 |
|
MD5 | 487a9f082c33a97130f7ed6d0bb60545 |
|
BLAKE2b-256 | 826dd63f898334dacec9db07cde63400df01d6e2949265219552e72d940f934b |