import gzip, os, sys
os.chdir("d:/Proyectos/Arduino/Arduino-Car/Esp32Cam/data")
with open("index.html","rb") as f:
    data = f.read()
with gzip.open("index.html.gz","wb",compresslevel=9) as f:
    f.write(data)
compressed = open("index.html.gz","rb").read()
print(f"Original: {len(data)} bytes  Gzipped: {len(compressed)} bytes")
lines  = ["// Auto-generado desde data/index.html"]
lines += [f"#define index_html_gz_len {len(compressed)}"]
lines += ["static const uint8_t index_html_gz[] = {"]
for i in range(0, len(compressed), 16):
    chunk = compressed[i:i+16]
    lines.append("  " + ", ".join(f"0x{b:02X}" for b in chunk) + ",")
lines[-1] = lines[-1].rstrip(",")
lines += ["};"]
with open("../camera_index.h","w") as f:
    f.write("\n".join(lines) + "\n")
print("camera_index.h generado OK")
