Commits

Mikhail Korobov committed d2167db Merge

Merge pull request #1 from stefanklug/master

encoder bug

  • Participants
  • Parent commits b67c3b8, 571765a

Comments (0)

Files changed (2)

File src/packbits.py

 
     data = bytearray(data)
 
-    state = 'RLE' if data[1] == data[0] else 'RAW'
-
     result = bytearray()
     buf = bytearray()
     pos = 0
     repeat_count = 0
     MAX_LENGTH = 127
+    #we can safely start with RAW as empty RAW sequences are handled by finish_raw()
+    state = 'RAW'
 
     def finish_raw():
+        if len(buf) == 0:
+            return
         result.append(len(buf)-1)
         result.extend(buf)
         buf[:] = bytearray()

File test_packbits.py

 def test_encode2():
     encoded = packbits.encode(b'112112')
     assert packbits.decode(encoded) == b'112112'
+    
+def test_encode_switching_rle():
+    encoded = packbits.encode(b'1122')
+    assert packbits.decode(encoded) == b'1122'
 
 def test_encode_long_rle():
     data = b'1' * 126