Last active
September 12, 2025 11:09
-
-
Save elderica/0b6fae4088b2dc078f33a2ab9cefacdd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See: https://github.com/openwrt/openwrt/issues/9619#issuecomment-1722333145 | |
from tkinter import * | |
from tkinter import filedialog | |
from tkinter import messagebox | |
import gzip | |
import os | |
import os.path | |
def find_gzip_size(gz_filepath): | |
st = os.stat(gz_filepath) | |
size = st.st_size | |
min = 0 | |
max = size | |
with open(gz_filepath, mode='rb') as f: | |
gz_data = f.read() | |
while True: | |
try: | |
gzip.decompress(gz_data[0:size]) | |
return size | |
except EOFError: | |
min = size | |
except gzip.BadGzipFile: | |
max = size | |
size = (max-min) // 2 + min | |
def find_trailing_data(gz_filepath): | |
with open(gz_filepath, mode='rb') as f: | |
gz_data = f.read() | |
gz_size = find_gzip_size(gz_filepath) | |
messagebox.showinfo('detected size', f'{gz_size} bytes') | |
gz_dirname = os.path.dirname(gz_filepath) | |
new_gz_name = 'purified.' + os.path.basename(gz_filepath) | |
new_gz_filepath = os.path.join(gz_dirname, new_gz_name) | |
with open(new_gz_filepath, 'wb') as f: | |
f.write(gz_data[0:gz_size]) | |
trailing_filepath = gz_filepath + '.trailing.raw' | |
with open(trailing_filepath, 'wb') as f: | |
f.write(gz_data[gz_size:]) | |
messagebox.showinfo('complete', message=f"""purified: {new_gz_filepath} | |
trailing: {trailing_filepath}""") | |
def ui(): | |
root = Tk() | |
root.withdraw() | |
gz_filepath = filedialog.askopenfilename() | |
if gz_filepath == '': | |
return | |
find_trailing_data(gz_filepath) | |
ui() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment