Skip to content

Instantly share code, notes, and snippets.

@Gargaj
Last active December 15, 2020 13:31
Show Gist options
  • Save Gargaj/5bf66c128c6c6c47f4c78de630e56569 to your computer and use it in GitHub Desktop.
Save Gargaj/5bf66c128c6c6c47f4c78de630e56569 to your computer and use it in GitHub Desktop.
#
# TIC80 packer
#
# Uses the zlib code chunk to crunch down your source
# https://github.com/nesbox/TIC-80/wiki/tic-File-Format
#
# Usage: tic80packer [lua file]
#
import sys
import zlib
with open(sys.argv[1], mode='rb') as file:
uncomp = file.read()
print("Uncompressed length: {} bytes".format(len(uncomp)))
comp = zlib.compress(uncomp, zlib.Z_BEST_COMPRESSION)
print("Compressed length: {} bytes".format(len(comp)))
print("With header: {} bytes".format(len(comp)+4))
with open(sys.argv[1]+".tic", 'wb') as file:
file.write(bytes([16]))
file.write(bytes([len(comp) & 0xFF]))
file.write(bytes([len(comp) >> 8]))
file.write(bytes([0]))
file.write(comp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment