Zlib/bz2 store and retrieve didnt worked


#1

I am compressing a string using zlib, then storing in Aerospike bin. On retrieval and decompressing, I am getting “zlib.error: Error -5 while decompressing data: incomplete or truncated stream”

When I compared original compressed data and retrieved compressed data, some thing is missing at the end in retrieved data.

I am using Aerospike 3.7.3 & python client 2.0.1

Please help

Thanks


#2

Please post some Python code that shows what you’re trying to do.


#3
import aerospike
import bz2
config = {
    'hosts': [
        ( '127.0.0.1', 3000 )
    ],
    'policies': {
        'timeout': 1000 # milliseconds
    }
}
client = aerospike.client(config)
client.connect()
content = "An Aerospike Query"
content_bz2 = bz2.compress(content)
key = ('benchmark', 'myset', 55)
#client.put(key, {'bin0':content_bz2})
(key, meta, bins) =  client.get(key)
print bz2.decompress(bins['bin0'])
Getting Following Error:
Traceback (most recent call last):
  File "asread.py", line 22, in <module>
    print bz2.decompress(bins['bin0'])
ValueError: couldn't find end of stream

#4

If you want to stay as binary data you need to wrap it as a bytearray. The bz.compress gives back a string, and the client will try to put it into an as_str instead of as_bytes.

I added a code sample here: https://stackoverflow.com/questions/37298413/aerospike-zlib-bz2-store-and-retrieve-didnt-worked