File indexing completed on 2025-01-19 03:59:54
0001 import io 0002 import json 0003 import gzip 0004 from ..objects import Animation 0005 0006 0007 def parse_tgs_json(file): 0008 """! 0009 Reads both tgs and lottie files, returns the json structure 0010 """ 0011 return open_maybe_gzipped(file, json.load) 0012 0013 0014 def open_maybe_gzipped(file, on_open): 0015 if isinstance(file, str): 0016 with open(file, "r") as fileobj: 0017 return open_maybe_gzipped(fileobj, on_open) 0018 0019 if isinstance(file, io.TextIOBase): 0020 binfile = file.buffer 0021 else: 0022 binfile = file 0023 0024 mn = binfile.read(2) 0025 binfile.seek(0) 0026 if mn == b'\x1f\x8b': # gzip magic number 0027 final_file = gzip.open(binfile, "rb") 0028 elif isinstance(file, io.TextIOBase): 0029 final_file = file 0030 else: 0031 final_file = io.TextIOWrapper(file) 0032 0033 return on_open(final_file) 0034 0035 0036 def parse_tgs(filename): 0037 """! 0038 Reads both tgs and lottie files 0039 """ 0040 lottie = parse_tgs_json(filename) 0041 return Animation.load(lottie)