# Zlib/bz2 store and retrieve didnt worked

**URL:** https://discuss.aerospike.com/t/zlib-bz2-store-and-retrieve-didnt-worked/2959
**Category:** General Discussion
**Created:** [May 18, 2016, 11:37am UTC](https://discuss.aerospike.com/t/zlib-bz2-store-and-retrieve-didnt-worked/2959 "2016-05-18T11:37:54Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![dhanasekaran1980](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@dhanasekaran1980](https://discuss.aerospike.com/u/dhanasekaran1980)
#### Post date: [May 18, 2016, 11:37am UTC](https://discuss.aerospike.com/t/zlib-bz2-store-and-retrieve-didnt-worked/2959/1 "2016-05-18T11:37:54Z")

</div>

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

---

<div class="post-metadata">

### Author: ![rbotzer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rbotzer/32/2114_2.png) [@rbotzer](https://discuss.aerospike.com/u/rbotzer)
#### Post date: [May 18, 2016, 4:11pm UTC](https://discuss.aerospike.com/t/zlib-bz2-store-and-retrieve-didnt-worked/2959/2 "2016-05-18T16:11:18Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dhanasekaran1980](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@dhanasekaran1980](https://discuss.aerospike.com/u/dhanasekaran1980)
#### Post date: [May 19, 2016, 10:31am UTC](https://discuss.aerospike.com/t/zlib-bz2-store-and-retrieve-didnt-worked/2959/3 "2016-05-19T10:31:14Z")

</div>

> ```
> 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
> 
> ```

---

<div class="post-metadata">

### Author: ![rbotzer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rbotzer/32/2114_2.png) [@rbotzer](https://discuss.aerospike.com/u/rbotzer)
#### Post date: [May 20, 2016, 11:58pm UTC](https://discuss.aerospike.com/t/zlib-bz2-store-and-retrieve-didnt-worked/2959/4 "2016-05-20T23:58:20Z")

</div>

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: [Aerospike: zlib/bz2 store and retrieve didnt worked - Stack Overflow](https://stackoverflow.com/questions/37298413/aerospike-zlib-bz2-store-and-retrieve-didnt-worked)
