English 中文(简体)
Jython 2.2.1 我如何压缩气流?
原标题:Jython 2.2.1 how can I decompress a gzip stream?

I muck, using Jython 2.2.1 with zlib 项目单元1.1.3 我需要下载大量热量数据,处理数据,并将其输入数据库。 我愿避免重复数据,这样,我就把数据压缩为一流。

使用 Python子 2.7.2,我可以说是:

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

但是,根据Jython 2.2.1,同样的代码在创建<代码>decompressobj时有错误:

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

很明显,。 页: 1

在Jython的Java一侧,我是新鲜的,并想知道在Jython内是否有办法用贾瓦语压缩气流? 或者,在接受高压头体时,可能有一种办法:zlib 1.1.3?

欢迎任何其他可能的解决办法。

最佳回答

我能够利用Jython的Java综合图书馆,围绕这一旧的zlib模块开展工作。

我还不得不使用 Java门处理我的URL,以便通过,反对gzip decoder。

今后参考:

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
问题回答




相关问题
How to determine compressed size from zlib for gzipped data?

I m using zlib to perform gzip compression. zlib writes the data directly to an open TCP socket after compressing it. /* socket_fd is a file descriptor for an open TCP socket */ gzFile gzf = gzdopen(...

Transparent SQLite Data Compression

I am looking for an existing solution for transparent SQLite 3 zlib compression using a custom VFS implementation and a custom IO methods implementation. Is anyone aware of an existing project that ...

"Untar" file on iPhone

I m writing an iPhone app which downloads a tar-gzipped file from a Webserver, then needs to unarchive this file so that it can be copied into the app s Documents folder. I m using tar/gzip because I ...

Compress data before storage on Google App Engine

I im trying to store 30 second user mp3 recordings as Blobs in my app engine data store. However, in order to enable this feature (App Engine has a 1MB limit per upload) and to keep the costs down I ...

Unzipping part of a .gz file using python

So here s the problem. I have sample.gz file which is roughly 60KB in size. I want to decompress the first 2000 bytes of this file. I am running into CRC check failed error, I guess because the gzip ...

热门标签