#!/usr/bin/env python3 """Estrae singoli file da uno ZIP remoto via HTTP Range (senza scaricare 1,28 GB). Il tpz dei template Godot e' uno zip: serve solo templates/linux_release.arm64. Legge EOCD + central directory con Range, poi scarica solo il membro richiesto. """ import binascii import struct import sys import urllib.request import zlib URL = ("https://github.com/godotengine/godot-builds/releases/download/" "4.7.1-stable/Godot_v4.7.1-stable_export_templates.tpz") def get_range(url, start, end=None): if end is None: rng = f"bytes={start}-" else: rng = f"bytes={start}-{end}" req = urllib.request.Request(url, headers={"Range": rng}) with urllib.request.urlopen(req, timeout=90) as r: return r.read(), r.status def main(wanted, dest_dir): # 1. dimensione totale req = urllib.request.Request(URL, method="HEAD") with urllib.request.urlopen(req, timeout=60) as r: total = int(r.headers["Content-Length"]) print(f"zip remoto: {total} byte") # 2. EOCD negli ultimi 64 KiB tail_len = min(65536, total) tail, _ = get_range(URL, total - tail_len) pos = tail.rfind(b"PK\x05\x06") if pos < 0: sys.exit("EOCD non trovato (zip64?)") (_, _, _, _, n_entries, cd_size, cd_off, _) = struct.unpack( " 1 else "templates/linux_release.arm64" dest = sys.argv[2] if len(sys.argv) > 2 else "/tmp/godot-dl" main(target, dest)