Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lzstring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ def _compress(uncompressed, bitsPerChar, getCharFromInt):
context_data_position = 0

for ii in range(len(uncompressed)):
context_c = uncompressed[ii]
if isinstance(uncompressed, (bytes)):
context_c = chr(uncompressed[ii])
else:
context_c = uncompressed[ii]
if context_c not in context_dictionary:
context_dictionary[context_c] = context_dictSize
context_dictSize += 1
Expand Down Expand Up @@ -373,6 +376,11 @@ class LZString(object):
def compress(uncompressed):
return _compress(uncompressed, 16, chr)

@staticmethod
def compressToUint8Array(uncompressed):
return bytes([ord(x) for x in _compress(uncompressed, 8, chr)])


@staticmethod
def compressToUTF16(uncompressed):
if uncompressed is None:
Expand Down Expand Up @@ -404,6 +412,14 @@ def decompress(compressed):
return None
return _decompress(len(compressed), 32768, lambda index: ord(compressed[index]))

@staticmethod
def decompressFromUint8Array(compressed):
if compressed is None:
return ""
if compressed == "":
return None
return _decompress(len(compressed), 128, lambda index: compressed[index])

@staticmethod
def decompressFromUTF16(compressed):
if compressed is None:
Expand Down