diff --git a/__init__.py b/__init__.py index 1bba1e2..c89cec3 100644 --- a/__init__.py +++ b/__init__.py @@ -4,4 +4,4 @@ from .xanim import Anim from .sanim import SiegeAnim -version = (0, 2, 0) # Version specifier for PyCoD +version = (0, 2, 1) # Version specifier for PyCoD diff --git a/_lz4.py b/_lz4.py index 2fd22eb..254e515 100644 --- a/_lz4.py +++ b/_lz4.py @@ -12,8 +12,15 @@ except ImportError: xrange = range - def byte2int(_bytes): - return ord(_bytes[0]) + # If we're running Python 3 or newer, we must + # define byte2int differently than with Python 2 + import sys + if sys.version_info[0] >= 3: + import operator + byte2int = operator.itemgetter(0) + else: + def byte2int(_bytes): + return ord(_bytes[0]) class CorruptError(Exception): pass @@ -122,7 +129,10 @@ def compress(data): else: # Use python-lz4 if present __support_mode__ = 'python-lz4' - compress = lz4.block.compress + + def compress(data): + return lz4.block.compress(data, store_size=False) + uncompress = lz4.block.decompress support_info = 'LZ4: Using %s' % __support_mode__ diff --git a/xbin.py b/xbin.py index 4724e6b..38ea600 100644 --- a/xbin.py +++ b/xbin.py @@ -323,8 +323,9 @@ def WriteMetaVec4Block(file, _hash, vec): @staticmethod def WriteCommentBlock(file, comment): - comment = bytearray(comment.encode('utf-8')) - data = struct.pack('Hxx%ds' % (len(comment) + 1), 0xC355, comment) + comment = __str_packable__(comment) + padded_size = padded(len(comment) + 1) + data = struct.pack('Hxx%ds' % padded_size, 0xC355, comment) file.write(data) @staticmethod @@ -458,7 +459,7 @@ def WritePartInfo(file, index, name): @staticmethod def WritePartIndex(file, index): - data = struct.pack('Hh', 0x745A, index) + data = struct.pack('Hh', 0x745A, int(index)) file.write(data) @staticmethod @@ -468,12 +469,12 @@ def WriteFramerate(file, framerate): @staticmethod def WriteFrameCount(file, frame_count): - data = struct.pack('Hxxi', 0xB917, frame_count) + data = struct.pack('Hxxi', 0xB917, int(frame_count)) file.write(data) @staticmethod def WriteFrameIndex(file, frame): - data = struct.pack('Hxxi', 0xC723, frame) + data = struct.pack('Hxxi', 0xC723, int(frame)) file.write(data) @staticmethod