By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,095 Members | 1,658 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,095 IT Pros & Developers. It's quick & easy.

How to get number of compressed bytes from GzipFile

P: n/a
Hi all,

I'm using the gzip module to return a gzip response from a small
python httpserver. I'd like to know the number of bytes written to
the underlying socket, but it doesn't seem to support the tell()
function. This works fine for a file:

[15:39:51] mattb ~ $ cat
#!/usr/bin/env python

import os
import gzip

f = open("tmp.gz", "wb")
gz = gzip.GzipFile('', 'wb', 6, f)

for i in xrange(100):
gz.write('abcdefg' * 100)


print gz.tell()
print f.tell()


print os.stat('tmp.gz').st_size
[15:40:17] mattb ~ $ ./

So I wrote 70000 raw bytes which gets compressed to 151 bytes -- I
guess the 10-byte difference is a gzip header or something?

Is there any way to get this same functionality when using a socket?


Mar 14 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.