How to get number of compressed bytes from GzipFile

M

Matt

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 mygzip.py
#!/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)

gz.flush()

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

gz.close()
f.close()

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

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?

thx

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,110
Latest member
OdetteGabb
Top