Skip to content

Commit

Permalink
v0.2.1
Browse files Browse the repository at this point in the history
Python-LZ4 compatibility fixes
Python 3 compatibility fixes
Various XBin fixes
  • Loading branch information
SE2Dev committed Jan 14, 2018
2 parents 78d1095 + 6dbcb43 commit 182e681
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 13 additions & 3 deletions _lz4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__
11 changes: 6 additions & 5 deletions xbin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 182e681

Please sign in to comment.