Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python script that converts .unitypackage file to .zip archive
#!/usr/bin/env python3
import sys
import tarfile
import zipfile
from pathlib import Path
src = sys.argv[1]
dst = Path(src).name + ".zip"
with[1], "r:gz") as tar:
with zipfile.ZipFile(dst, "w", zipfile.ZIP_DEFLATED, compresslevel=9) as z:
while True:
i =
if not i:
if i.isdir():
asset = meta = pathname = None
elif i.isfile() and != ".icon.png":
name = Path(
if name == "asset":
asset = tar.extractfile(i).read()
elif name == "asset.meta":
meta = tar.extractfile(i).read()
elif name == "pathname":
pathname = tar.extractfile(i).read()
if asset is not None and pathname is not None and meta is not None:
pathname = pathname.rstrip().decode("utf-8").split("\n")[0]
z.writestr(pathname, asset)
z.writestr(pathname + ".meta", meta)
asset = meta = pathname = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.