You've already forked PythonLib
mirror of
https://github.com/lifebottle/PythonLib.git
synced 2026-02-13 15:25:50 -08:00
Move is_compressed into comptolib
I think it makes more sense
This commit is contained in:
@@ -404,18 +404,6 @@ class ToolsTales:
|
||||
|
||||
# Didn't match anything
|
||||
return None
|
||||
|
||||
def is_compressed(self,data):
|
||||
if len(data) < 0x09:
|
||||
return False
|
||||
|
||||
expected_size = struct.unpack("<L", data[1:5])[0]
|
||||
tail_data = abs(len(data) - (expected_size + 9))
|
||||
if expected_size == len(data) - 9:
|
||||
return True
|
||||
elif tail_data <= 0x10 and data[expected_size + 9 :] == b"#" * tail_data:
|
||||
return True # SCPK files have these trailing "#" bytes :(
|
||||
return False
|
||||
|
||||
|
||||
def extract_Cab(self, cab_file_name, new_file_name, working_dir):
|
||||
|
||||
18
comptolib.py
18
comptolib.py
@@ -101,4 +101,20 @@ def compress_file(input: str, output: str, raw: bool=False, version: int=3):
|
||||
|
||||
def decompress_file(input: str, output: str, raw: bool=False, version: int=3):
|
||||
error = compto_fdecode(input.encode("utf-8"), output.encode("utf-8"), raw, version)
|
||||
RaiseError(error)
|
||||
RaiseError(error)
|
||||
|
||||
|
||||
def is_compressed(data: bytes) -> bool:
|
||||
if len(data) < 0x09:
|
||||
return False
|
||||
|
||||
expected_size = struct.unpack("<L", data[1:5])[0]
|
||||
tail_data = abs(len(data) - (expected_size + 9))
|
||||
|
||||
if expected_size == len(data) - 9:
|
||||
return True
|
||||
|
||||
if tail_data <= 0x10 and data[expected_size + 9 :] == b"#" * tail_data:
|
||||
return True # SCPK files have these trailing "#" bytes :(
|
||||
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user