Skip to content

Commit

Permalink
mtk-bpf-patcher: Switch to gzip instead of zlib
Browse files Browse the repository at this point in the history
* The `zlib` module isn't able to properly compress the given image and since
  the `gzip` module also provides a function to decompress, use that.
  • Loading branch information
R0rt1z2 committed Apr 21, 2023
1 parent ef549bc commit 74c36c5
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions mtk_bpf_patcher/utils/parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import zlib
import gzip

try:
from data.Types import FileTypes
Expand Down Expand Up @@ -68,17 +68,15 @@ def decide_type(self):
'''Decompresses the given data using gzip.'''
def gzip_decompress(self, data):
try:
# ZLIB expects the data to be prepended with a 16-bit header.
return zlib.decompress(data, wbits=16 + zlib.MAX_WBITS)
return gzip.decompress(data)
except zlib.error as e:
self.logger.log(2, e)

'''Compresses the given data using gzip.'''
def gzip_compress(self, data):
try:
# For whatever reason, ZLIB doesn't prepend the data with a 16-bit header.
# As a quick workaround, use system's gzip to compress the data correctly.
return zlib.compress(data, level=9) # Default to MAX compression ratio.
return gzip.compress(data, compresslevel=9) # Default to MAX compression ratio.
except Exception as e:
self.logger.log(2, e)

Expand Down

0 comments on commit 74c36c5

Please sign in to comment.