mirror of
https://github.com/lcdr/utils.git
synced 2024-08-30 17:32:16 +00:00
Changed decompress_sd0 to operate on bytes instead of files.
This commit is contained in:
parent
e2e7ff5183
commit
3e10476cd6
@ -2,18 +2,16 @@ import argparse
|
|||||||
import os.path
|
import os.path
|
||||||
import zlib
|
import zlib
|
||||||
|
|
||||||
def decompress(in_path, out_path):
|
def decompress(data):
|
||||||
with open(in_path, "rb") as in_file:
|
|
||||||
data = in_file.read()
|
|
||||||
|
|
||||||
assert data[:5] == b"sd0\x01\xff"
|
assert data[:5] == b"sd0\x01\xff"
|
||||||
pos = 5
|
pos = 5
|
||||||
with open(out_path, "wb") as out_file:
|
out = b""
|
||||||
while pos < len(data):
|
while pos < len(data):
|
||||||
length = int.from_bytes(data[pos:pos+4], "little")
|
length = int.from_bytes(data[pos:pos+4], "little")
|
||||||
pos += 4
|
pos += 4
|
||||||
out_file.write(zlib.decompress(data[pos:pos+length]))
|
out += zlib.decompress(data[pos:pos+length])
|
||||||
pos += length
|
pos += length
|
||||||
|
return out
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
@ -24,6 +22,10 @@ if __name__ == "__main__":
|
|||||||
filename, ext = os.path.splitext(os.path.basename(args.in_path))
|
filename, ext = os.path.splitext(os.path.basename(args.in_path))
|
||||||
args.out_path = filename+"_decompressed"+ext
|
args.out_path = filename+"_decompressed"+ext
|
||||||
|
|
||||||
decompress(args.in_path, args.out_path)
|
with open(args.in_path, "rb") as file:
|
||||||
|
data = in_file.read()
|
||||||
|
|
||||||
|
with open(args.out_path, "wb") as file:
|
||||||
|
file.write(decompress(data))
|
||||||
|
|
||||||
print("Decompressed file:", args.out_path)
|
print("Decompressed file:", args.out_path)
|
||||||
|
Loading…
Reference in New Issue
Block a user