开发者

Decode the bytes

开发者 https://www.devze.com 2023-02-10 09:00 出处:网络
Following piece of code is from zipfile.py. self.fp.write(zinfo.FileHeader()) def FileHeader(self): 开发者_开发问答header = struct.pack(structFileHeader, stringFileHeader,

Following piece of code is from zipfile.py.

   self.fp.write(zinfo.FileHeader())

   def FileHeader(self):

开发者_开发问答       header = struct.pack(structFileHeader, stringFileHeader,
                 self.extract_version, self.reserved, flag_bits,
                 self.compress_type, CRC, dosdate, CRC,
                 compress_size, file_size,
                 len(filename), len(extra))
       return header + filename + extra

In some other file:

  // Some other codes.....


  zip_file = zip_dir(self.upload_dir)

  zip_file.getvalue()

My Question:

The result of 'zip_file.getvalue()' is as follows:

...b'PK\x03\x04\x14\x00\x00\x00\x00\x00\x00\x00O>\x9f\xec\x04\xd0\x06\x00\x00\x00\x06\x00\x00\x00\n\x00\x00\x00index.htmlyellowPK\x01\x02\x14\x03\x14\x00\x00\x00\x00\x00\x84\x93O>\x9f\xec\x04\xd0\x06\x00\x00\x00\x06\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x00\x00\x00\x00index.htmlPK\x05\x06\x00\x00\x00\x00\x01\x00\x01\x008\x00\x00\x00.\x00\x00\x00\x00\x00'

If I try to decode i.e.

zip_file.getvalue().decode()

it says:

'utf8' codec can't decode byte 0x9f in position 14: unexpected code byte

Is it possible to decode the above?


There's nothing to decode. The bytes make up a zip file, and you can extract the contents of the archive with creative use of zipfile.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号