write_variablenumber ( 2 ) # 2- 255 self. write_bitstring ( " 10 " ) 249 250 # if the last operations were literal or single byte 251 # and the offset is unchanged since the last block copy 252 # we can just store a 'null' offset and the length 253 if self.
_tag = 2 184 185 reads a bit until the next bit in the pair is not set """ 186 result = 1 187 result = ( result = 2 248 self. _tag | = ( 1 > i ) & 1 ) 119 return 120 121 def write_variablenumber ( self, value ) : 122 assert value > = 2 123 124 length = getbinlen ( value ) - 2 # the highest bit is 1 125 self. _tagoffset ) 84 85 def write_bit ( self, value ) : 86 """ writes a bit, make space for the tag if necessary """ 87 if self. _tagsize ) 83 return modifystring ( self. _isfirsttag = True 77 78 79 def getdata ( self ) : 80 """ builds an output string of what ' s currently compressed: 81 currently output bit + current tag content """ 82 tagstr = int2lebin ( self. rfind ( word, 0, limit + 1 ) 22 if pos = - 1 : 23 return offset, length 24 25 offset = limit - pos 26 length = len ( word ) 27 dic + = sub 28 29 while l > ( 8 * i ) ) & 0xFF ) 48 return result 49 50 def modifystring ( s, sub, offset ) : 51 """ overwrites ' sub ' at ' offset ' of ' s ' """ 52 return s + sub + s 53 54 def getbinlen ( value ) : 55 """ return the bit length of an integer """ 56 result = 0 57 if value = 0 : 58 return 1 59 while value != 0 : 60 value > = 1 61 result + = 1 62 return result 63 64 # from kbp\_bits.py # 65 class _bits_compress ( ) : 66 """ bit machine for variable-sized auto-reloading tag compression """ 67 def _init_ ( self, tagsize ) : 68 """ tagsize is the number of bytes that takes the tag """ 69 self. Raw file 1 # this is a standalone single-file merge of aplib compression and decompression 2 # taken from my own library Kabopan 3 # (no other clean-up or improvement) 4 5 # Ange Albertini, BSD Licence, 2007-2011 6 7 # from kbp\comp\_lz77.py # 8 def find_longest_match ( s, sub ) : 9 """ returns the number of byte to look backward and the length of byte to copy) """ 10 if sub = " " : 11 return 0, 0 12 limit = len ( s ) 13 dic = s 14 l = 0 15 offset = 0 16 length = 0 17 first = 0 18 word = " " 19 20 word + = sub 21 pos = dic. I found a few other libraries, including the puff.1 complexity | 7dec9e823bded8edc04d5745c39f99bf MD5 | The author says that commercial licenses are available on request, but unfortunately he's currently unreachable (for non-technical reasons, like the news on his site say).
#APLIB DECOMPRESSOR LICENSE#
We found LZO, which would be almost perfect for us, but it has a so-called "free" license (GPL) by default, which makes it totally unusable for our customer.
#APLIB DECOMPRESSOR CODE#
The uncompression code should be in C, since it's unlikely that someone has an ASM optimized version for our controller.
NET code preferred though for compression, to make things easier.
#APLIB DECOMPRESSOR PC#
The compression can be slow and ugly, since we're doing it on the PC side. This means we need a sufficiently fast uncompression algorithm that does not use a lot of memory. And of course, it doesn't have an operating system or other luxury.
It has enough flash memory to store the result, and can uncompress the data block as it is received, but it may not have enough RAM to store the entire compressed or uncompressed (or even both!) data blocks. The device itself, however, runs on a micro controller that is not really fast and does not have a lot of memory. The communication channel is really, really slow, so we'd like to compress the data beforehand, pass to the device and let it uncompress the data to its internal flash. This is a bit simplified, so assume that the data must be passed and uncompressed a lot, not just once a year. We're currently creating a device for a customer that will get a block of data (like, say, 5-10KB) from a PC application.