Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7967537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:56:27+00:00 2026-06-04T06:56:27+00:00

I’m stuck using Jython 2.2.1 with zlib module version 1.1.3 for a project. I

  • 0

I’m stuck using Jython 2.2.1 with zlib module version 1.1.3 for a project. I need to download a lot of gzipped data, process it, and write it to a database. I’d like to avoid having multiple copies of the data in memory, so I’m decompressing it as a stream.

Using Python 2.7.2, I have been able to decompress a gzip stream as:

from zlib import decompressobj, MAX_WBITS

f = open('stream.gz', 'rb') # in real life, this stream comes from urllib2  
gunzipper = decompressobj(16+MAX_WBITS)  
data = ''  
for chunk in iter(lambda: f.read(BLOCK_SIZE), ''):
    data += gunzipper.decompress(chunk)
#done

Under Jython 2.2.1, however, the same code gets an error when creating the decompressobj:

.\jythonLib.jar\lib/zlib$py.class", line 89, in __init__
ValueError: Invalid initialization option

Apparently the header offset trick doesn’t work with this old version of zlib.

I’m new to the Java side of Jython, and was wondering if there is a way to decompress a gzip stream using Java classes within Jython? Or perhaps there is a way to coax zlib 1.1.3 into accepting the gzip header?

Any other potential solutions are welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:56:28+00:00Added an answer on June 4, 2026 at 6:56 am

    I was able to work around using this old zlib module by using the integrated Java libraries within Jython.

    I also had to handle my URL using Java classes, in order to pass a FileInputStream object to the gzip decoder.

    For future reference:

    from java.io import BufferedReader,InputStreamReader
    from java.util.zip import GZIPInputStream
    from java.net import URL
    
    url = URL('http://data.com')
    urlconn = url.openConnection()
    urlconn.setRequestProperty('Accept-encoding', 'gzip, compress')
    urlconn.connect()
    
    reader = BufferedReader(InputStreamReader(GZIPInputStream(urlconn.getInputStream())))
    data = ''
    for chunk in iter(lamdba: reader.readLine(), None):
        data += chunk
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters
I need to clean up various Word 'smart' characters in user input, including but
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.