bzip2.py
ofrak.core.bzip2
Bzip2Data (GenericBinary)
dataclass
A bzip2 binary blob.
Bzip2Packer (Packer)
Compresses data using the bzip2 algorithm. Use after modifying decompressed bzip2 data to recreate .bz2 files or bzip2-compressed sections within larger binaries. Common for compressed tarballs and firmware images.
pack(self, resource, config=None)
async
Pack a resource into bzip2 data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource |
Resource |
required | |
config |
None |
Source code in ofrak/core/bzip2.py
async def pack(self, resource: Resource, config=None):
"""
Pack a resource into bzip2 data.
:param resource:
:param config:
"""
bzip2_child = await resource.get_only_child()
bzip2_compressed = bz2.compress(await bzip2_child.get_data())
original_size = await resource.get_data_length()
resource.queue_patch(Range(0, original_size), bzip2_compressed)
Bzip2Unpacker (Unpacker)
Decompresses bzip2-compressed data, which uses Burrows-Wheeler transform and Huffman coding for compression. Use for .bz2 files or bzip2-compressed sections within larger binaries. Common in Linux systems for compressed tarballs (.tar.bz2) and firmware images. Results in a single child.
unpack(self, resource, config=None)
async
Unpack bzip2 data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource |
Resource |
required | |
config |
None |
Source code in ofrak/core/bzip2.py
async def unpack(self, resource: Resource, config=None):
"""
Unpack bzip2 data.
:param resource:
:param config:
"""
resource_data = await resource.get_data()
decompressed_data = bz2.decompress(resource_data)
await resource.create_child(
tags=(GenericBinary,),
data=decompressed_data,
)