# Zlib Deflate to java.util.zip inflate problem

**URL:** <https://www.ruby-forum.com/t/zlib-deflate-to-java-util-zip-inflate-problem/164718>\
**Category:** Ruby\
**Created:** [April 4, 2009, 6:46pm UTC](https://www.ruby-forum.com/t/zlib-deflate-to-java-util-zip-inflate-problem/164718 "2009-04-04T18:46:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@dom](https://www.ruby-forum.com/u/dom)\
**Post date:** [April 4, 2009, 6:46pm UTC](https://www.ruby-forum.com/t/zlib-deflate-to-java-util-zip-inflate-problem/164718/1 "2009-04-04T18:46:19Z")

</div>

Hello, I’m a total ruby newbie and am developing a simple app that  
tests an existing web app. Part of the request I need to post  
contains data that needs to be compressed as the web app will  
uncompress it. Currently, the java app just uses simple  
java.util.zip.Inflater to do this, and I’ve been able to do this from  
cocoa to java no problem. Using Ruby to craft the data and post  
request has presented a problem: when the web app gets the request,  
I’m getting exceptions from java.utl.zip Unkown Compression format I  
can’t change the back end, only the ruby client side. Does anybody  
know how to properly use the ruby zlib library to deflate data such  
that java’s built in classes can inflate it? Sorry if this is a basic  
question; I’ve googled this to death and hit nothing but dead ends.  
Here’s the call that compresses:

compressedBroadcast = Zlib::Deflate.new(nil, -  
Zlib::MAX\_WBITS).deflate(binaryBroadcastData, Zlib::FINISH)

Other than this, I’m very much enjoying the other Ruby bits. Thanks  
for any pointers.

Dom

---

<div class="post-metadata">

**Author:** ![dom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@dom](https://www.ruby-forum.com/u/dom)\
**Post date:** [April 4, 2009, 10:10pm UTC](https://www.ruby-forum.com/t/zlib-deflate-to-java-util-zip-inflate-problem/164718/2 "2009-04-04T22:10:50Z")

</div>

Anything, anybody? Little help here…😉

---

<div class="post-metadata">

**Author:** ![dom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@dom](https://www.ruby-forum.com/u/dom)\
**Post date:** [April 4, 2009, 10:40pm UTC](https://www.ruby-forum.com/t/zlib-deflate-to-java-util-zip-inflate-problem/164718/3 "2009-04-04T22:40:42Z")

</div>

Dom wrote:

> that java’s built in classes can inflate it? Sorry if this is a basic  
> question; I’ve googled this to death and hit nothing but dead ends.

Did you find rubyzip? It doesn’t seem to work under Ruby 1.9, but it  
does have an interface supposedly modeled on java.util.zip:

```
 http://rubyzip.sourceforge.net/

```

It’s hard to believe this didn’t come up when you Googled.

---

<div class="post-metadata">

**Author:** ![dom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@dom](https://www.ruby-forum.com/u/dom)\
**Post date:** [April 5, 2009, 11:49am UTC](https://www.ruby-forum.com/t/zlib-deflate-to-java-util-zip-inflate-problem/164718/4 "2009-04-05T11:49:18Z")

</div>

Dom wrote:

> Sorry, should have been more clear, I’m not creating files. I did  
> find it, but it seems entirely focused on zip files; I’m just using  
> the deflate/inflate to squeeze some data before sending it over the  
> wire. Being that they’re both based on zlib, you’d think that deflated  
> from one would be inflatable by the other and I was hoping that  
> perhaps I’m just missing a setting or not using a correct parameter to  
> one of the ruby calls. But, I’ve pretty much tried every permutation  
> and cannot get the server to inflate the data. I’d think somebody’s  
> doing this somewhere with success.

Could it be that your java side is expecting the new zlib format?

As could be seen in your first post, you are using -MAX\_WBITS, which  
enables old (headerless? don’t know what it’s called) zlib format, that  
has no gzip header and no checksum. Maybe you should be using +MAX\_WBITS  
(the default), which adds necessary header and checksum.

---

<div class="post-metadata">

**Author:** ![dom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@dom](https://www.ruby-forum.com/u/dom)\
**Post date:** [April 6, 2009, 7:51am UTC](https://www.ruby-forum.com/t/zlib-deflate-to-java-util-zip-inflate-problem/164718/5 "2009-04-06T07:51:30Z")

</div>

On Apr 5, 2009, at 02:48, Alexey B. wrote:

> Could it be that your java side is expecting the new zlib format?
> 
> As could be seen in your first post, you are using -MAX\_WBITS, which  
> enables old (headerless? don’t know what it’s called) zlib format,  
> that  
> has no gzip header and no checksum. Maybe you should be using  
> +MAX\_WBITS  
> (the default), which adds necessary header and checksum.

Agreed, you probably only want -MAX\_WBITS when implementing a gzip  
stream.

---

<div class="post-metadata">

**Author:** ![dom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@dom](https://www.ruby-forum.com/u/dom)\
**Post date:** [April 6, 2009, 7:52am UTC](https://www.ruby-forum.com/t/zlib-deflate-to-java-util-zip-inflate-problem/164718/6 "2009-04-06T07:52:05Z")

</div>

On Apr 4, 2009, at 09:45, Dom wrote:

> compressedBroadcast = Zlib::Deflate.new(nil, -  
> Zlib::MAX\_WBITS).deflate(binaryBroadcastData, Zlib::FINISH)

I think you’re asking for a gzip stream here with your -MAX\_WBITS

---

<div class="post-metadata">

**Author:** ![dom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@dom](https://www.ruby-forum.com/u/dom)\
**Post date:** [April 5, 2009, 2:32am UTC](https://www.ruby-forum.com/t/zlib-deflate-to-java-util-zip-inflate-problem/164718/7 "2009-04-05T02:32:56Z")

</div>

Thanks for the reply,

Sorry, should have been more clear, I’m not creating files. I did  
find it, but it seems entirely focused on zip files; I’m just using  
the deflate/inflate to squeeze some data before sending it over the  
wire. Being that they’re both based on zlib, you’d think that deflated  
from one would be inflatable by the other and I was hoping that  
perhaps I’m just missing a setting or not using a correct parameter to  
one of the ruby calls. But, I’ve pretty much tried every permutation  
and cannot get the server to inflate the data. I’d think somebody’s  
doing this somewhere with success.
