473,397 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How to get number of compressed bytes from GzipFile

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
Mar 14 '08 #1
0 936

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
by: Dag | last post by:
Is there a python module that includes functions for working with prime numbers? I mainly need A function that returns the Nth prime number and that returns how many prime numbers are less than N,...
8
by: Dennis Hotson | last post by:
Hi, I'm trying to write a function that adds a file-like-object to a compressed tarfile... eg ".tar.gz" or ".tar.bz2" I've had a look at the tarfile module but the append mode doesn't support...
0
by: Norman Barker | last post by:
Hi, I have spent most of the day on this so any help would be appreciated. I have set up mod_deflate in Apache so that any input marked content-type gzip from the client is automatically...
0
by: Justin Guerin | last post by:
Hello list, gzip documentation states that calling the .close() method on a GzipFile doesn't really close it. If I'm really through with it, what's the best way to close it? I'm using...
9
by: flebber | last post by:
I was working at creating a simple program that would read the content of a playlist file( in this case *.k3b") and write it out . the compressed "*.k3b" file has two file and the one I was trying...
16
by: Nad | last post by:
I have a very large site with valuable information. Is there any way to prevent downloading a large number of articles. Some people want to download the entire site. Any hints or pointers would...
11
by: mach77 | last post by:
When using a GZipStream, is there any way to know how many compressed bytes were written? For example: // "buffer" is data from a text file // "offset" is 0 // "count" is 100 ...
10
by: Mark | last post by:
I used pickle and found the file was saved in text format. I wonder whether anyone is familiar with a good compact off-the-shelf module available that will save in compressed format... or maybe an...
0
by: Gabriel Genellina | last post by:
En Wed, 19 Nov 2008 17:04:22 -0200, Mikolai Fajer <mfajer@gmail.com> escribió: Several of those were added in Python 2.6, looks like GzipFile should behave the same way. -- Gabriel...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.