bzip2.py
ofrak_components.bzip2
Bzip2Data (GenericBinary)
dataclass
A bzip2 binary blob.
Bzip2Packer (Packer)
Pack a resource, compressing it into bzip2 data.
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_components/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)
Unpack bzip2 data.
bzip2 binary blobs decompress into one child.
unpack(self, resource, config=None)
async
Unpack bzip2 data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource |
Resource |
required | |
config |
None |
Source code in ofrak_components/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,
)