removing the header from a gzip'd string

Gabriel Genellina gagsl-py at yahoo.com.ar
Thu Dec 21 21:52:42 EST 2006


At Thursday 21/12/2006 18:32, Fredrik Lundh wrote:

> > Hi, I have some code that takes a string and obtains a compressed
> > version using zlib.compress
> >
> > Does anybody know how I can remove the header portion of the compressed
> > bytes, such that I only have the compressed data remaining?
>
>what makes you think there's a "header portion" in the data you get
>from zlib.compress ?  it's just a continuous stream of bits, all of
>which are needed by the decoder.

No. The first 2 bytes (or more if using a preset dictionary) are 
header information. The last 4 bytes are for checksum. In-between 
lies the encoded bit stream.
Using the default options ("deflate", default compression level, no 
custom dictionary) will make those first two bytes 0x78 0x9c.
If you want to encrypt a compressed text, you must remove redundant 
information first. Knowing part of the clear message is a security 
hole. Using an structured container (like a zip/rar/... file) gets 
worse because the fixed (or "guessable") part is longer, but anyway, 
2 bytes may be bad enough.
See RFC1950 <ftp://ftp.isi.edu/in-notes/rfc1950.txt>


-- 
Gabriel Genellina
Softlab SRL 


	

	
		
__________________________________________________ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 




More information about the Python-list mailing list