From 54449a71321300566370bf3a5a67508e02f5a3c6 Mon Sep 17 00:00:00 2001 From: vg Date: Tue, 5 Mar 2024 00:03:41 +0100 Subject: git-sync on dita --- gamechestcli/gamechest/runners/extract.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gamechestcli/gamechest/runners/extract.py b/gamechestcli/gamechest/runners/extract.py index cb8009a..8101e02 100644 --- a/gamechestcli/gamechest/runners/extract.py +++ b/gamechestcli/gamechest/runners/extract.py @@ -1,5 +1,6 @@ import os import re +import struct import subprocess import humanfriendly @@ -13,6 +14,8 @@ class Extract(RunnerBase): _progress_re = re.compile(r'^\s*(\S+)\s+\[([^]]+)/s\]\s+ETA\s+(\S+)\s*$') def __init__(self, src, dst): + import sys + print('src', src, 'dst', dst, file=sys.stderr) common_parameters = dict( encoding='utf8', env={**os.environ, @@ -34,10 +37,13 @@ class Extract(RunnerBase): lzip_command = '/usr/bin/lzip' plzip_command = '/usr/bin/plzip' uncompress_command_to_use = [lzip_command, '--decompress'] - if str(src).endswith('.tlz'): + first_word_magic = 0 + with open(src, 'rb') as stream: + first_word_magic = struct.unpack('>L', stream.read(4)) + if first_word_magic == 0x4c5a4950: # lzip magic if os.path.exists(plzip_command): uncompress_command_to_use = [plzip_command, '--decompress'] - elif str(src).endswith('.tzst'): + elif first_word_magic == 0x28B52FFD: uncompress_command_to_use = ['zstd', '-T0', '-d', '--stdout'] self.zip_proc = subprocess.Popen( uncompress_command_to_use, -- cgit v1.2.3