返回顶部

收藏

Loop through header information in a ZIP file

更多
import struct

data = open('myfile.zip', 'rb').read()
start = 0
for i in range(3):                      # show the first 3 file headers
    start += 14
    fields = struct.unpack('LLLHH', data[start:start+16])
    crc32, comp_size, uncomp_size, filenamesize, extra_size = fields

    start += 16
    filename = data[start:start+filenamesize]
    start += filenamesize
    extra = data[start:start+extra_size]
    print filename, hex(crc32), comp_size, uncomp_size

    start += extra_size + comp_size     # skip to the next header

标签:Python,File

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2016-02-11 11:05:41Loop through a file by jack.chen
  2. 2016-03-27 14:52:35Close a file after using by Solon.Ring
  3. 2016-05-30 16:40:50Reading a binary File by 西国の海妖
  4. 2016-08-19 16:12:51File Random Access by 张宋付
  5. 2016-09-20 18:13:43Use seek() to move file pointer by 大猪
  6. 2016-10-04 12:15:46Write string to a file by 司马
  7. 2016-11-20 11:31:44Close a file by xwz
  8. 2016-08-19 16:23:52Adding Line Numbers to a Python Script by 西国の海妖
  9. 2016-09-22 11:48:20Define class to deal with files by 阿明娃儿
  10. 2016-10-14 16:12:39Change Dir by 大猪
  11. 2018-03-30 21:56:50java自动识别用户上传的文本文件编码 by Hugh

发表评论