Friday, 15 March 2013

python zlib produces a -3 error when inflating data through a Decompress() object -


I basically remove pars, deccps and a file from a zlib encoded file downloaded through an urlib2 file A decoder is made - the idea of ​​the object is to use as little memory and disk space as possible, so I use a reader / author pattern with "decoder" in between to unmoder the data coming from urllib2 I am in CPIO subpros Data for the disk in the feed and end of the file write:

  closed as a reader (builder.open ()): with open (component, "W + B") as author : Decoder = decoder () while true: data = reader.read (10240) if lane (data) == 0: break writer. Write (decoder.Data (data)) final = decoder.flas () if not last no one: the author. Writing (Final) Writer The flush () decoder is very simple:  
  class decoder (object): def __init __ (self): auto.__ zcat = zlib.decompressobj () #cpio initialisation def decode (auto, data_in ): Refund self .__ Consumption (auto.__ zcat.decompress (data_in)) def __consume (auto, zcat_data_in): # CPIO operation returns data_out def: flush (self): return self.__ consumption (auto.__ zcat.flush ( ))  

Before passing anything to the CPIO pipe, I am seeing an error, so I think that except for this it can be used for clarity. Was funny.

The interesting thing is that to verify that the data can actually be uncompressed by zlib, I wrote the raw data data_in decode ()

  has been passed for DEF decode (self, data_in): sys.stdout.write (data_in) returns the self .__ consumption (auto.__ zcat decompress (data_in))  

then ran away:

  $ bin / myprog.py 2 & gt; / Dev / null | Zcat - | File - / dev / stdin: cpio archive  

As you can see, zcat was quite happy about the data given on stdin and the resulting file is a CPIO archive. But the zlib deconption method is reporting:

  error: error 3 while decompose: wrong header check  

\ x1f \ x9d are the first two bytes of the old Unix compressed format. Zlib can not help you in deleting it. Gzip can decompress it to be compatible with the old compression utility.

You can drag that format to uncompressed and use it directly.


No comments:

Post a Comment