Created
May 22, 2020 01:43
-
-
Save PolCPP/a17d937c094d9aeccb3c438085741faf 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
#!/usr/bin/env python | |
import sys | |
import json | |
import os | |
from zipfile import ZipFile | |
from xml.dom import minidom | |
dir_name = sys.argv[1] | |
fileHeader = 59 + len(dir_name) | |
zip_file = dir_name + ".zip" | |
dzi_file = minidom.parse(sys.argv[2]) | |
image_tag = dzi_file.getElementsByTagName('Image')[0] | |
size_tag = dzi_file.getElementsByTagName('Size')[0] | |
file_table = { | |
"Image": { | |
"TileFormat": "edz", | |
"Format": image_tag.attributes['Format'].value, | |
"Overlap": image_tag.attributes['Overlap'].value, | |
"TileSize": image_tag.attributes['TileSize'].value, | |
"Size": { | |
"Height": size_tag.attributes['Height'].value, | |
"Width": size_tag.attributes['Width'].value | |
}, | |
"ZipFile": zip_file, | |
"Ranges": {} | |
} | |
} | |
os.system("zip -Z store -r %s %s" % (zip_file, dir_name)) | |
f = open(zip_file, "r") | |
file_contents = f.read() | |
f.close() | |
with ZipFile(zip_file, 'r') as zip: | |
files = zip.infolist() | |
for file in files: | |
if not file.filename.endswith('/'): | |
#Slow safe way | |
#data = zip.read(file) | |
#offset = file_contents.find(data) | |
#size = len(data) | |
#Fast/Magic i don't get how i made it work way | |
offset = file.header_offset + fileHeader + len(file.filename.replace(dir_name + "/", "")); | |
size = file.file_size; | |
file_table["Image"]["Ranges"][file.filename] = { | |
"offset": offset, | |
"size": size | |
} | |
f = open(dir_name + ".json", "w") | |
f.write(json.dumps(file_table)) | |
f.close() | |
# 6285 | |
# 6350 | |
#python -c 'f=open("duomo.zip","rb");f.seek(6315);print(f.read(196));f.close()' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment