返回顶部

收藏

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. 2015-11-27 20:36:13Iterating Over Lines with readlines by 张宋付
  2. 2016-01-04 17:35:46Closing Files by 西国の海妖
  3. 2016-08-19 15:46:08Working with Directories by 西国の海妖
  4. 2016-09-03 11:47:53Define function to Open a file by 阮小七
  5. 2016-09-19 19:25:12File Output by jack.chen
  6. 2016-10-19 10:47:50Handling I/O Errors by 大猪
  7. 2016-12-06 09:03:52Demonstrates writing to a text file by 张宋付
  8. 2016-03-26 20:56:22Reading Everything: read the whole file in one go by 风云轩
  9. 2016-08-19 15:55:27Working with File Objects by Solon.Ring
  10. 2016-09-03 14:35:51Writing to Files by 西国の海妖
  11. 2016-10-19 11:28:30Reads a single line from the file by 蟋蟀MM
相关聚客文章
  1. Huqiu Liao / Srain 发表 2015-05-12 16:00:00 通过 shell 执行 python 报错: No such file or directory
  2. JohnDeng 发表 2014-11-29 18:44:04 Python常用概念与技巧
  3. 博主 发表 2015-04-23 15:15:08 PIL 简明教程 - 基本用法
  4. 熊能 发表 2015-01-14 07:06:38 使用PyInstaller打包Python程序
  5. 田俊 发表 2015-04-28 15:16:24 (5)一起用python之基础篇——numpy
  6. SeisMan 发表 2013-08-27 04:27:00 MoPaD:地震矩绘制和分析工具
  7. wolftankk 发表 2014-04-17 10:38:31 了解正则中的特殊匹配技巧
  8. admin 发表 2015-04-30 01:29:33 get java status for zabbix
  9. Zealot 发表 2012-08-18 16:23:18 管理个人服务器
  10. admin 发表 2015-05-04 02:35:16 python subprocess
  11. mdjhny 发表 2013-01-13 16:00:00 用Sublime Text 2和Pelican在Github上发布博客
  12. admin 发表 2015-05-06 07:28:56 python logging module

发表评论