【问题标题】:About the use of seek on gzip files关于在 gzip 文件上使用 seek
【发布时间】:2014-11-17 02:26:37
【问题描述】:

我有一个很大的gzip 文件,我想使用seek 只读其中的一部分。 关于在gzip 文件上使用seek,这个page 说:

seek() 位置是相对于未压缩数据的,所以 调用者甚至不需要知道数据文件是否被压缩。

这是否意味着seek 必须从文件开头读取并解压缩数据到目标位置?

【问题讨论】:

    标签: python python-2.7 gzip seek


    【解决方案1】:

    是的。 This is the code:

    elif self.mode == READ:
        if offset < self.offset:
            # for negative seek, rewind and do positive seek
            self.rewind()
        count = offset - self.offset
        for i in range(count // 1024):
            self.read(1024)
        self.read(count % 1024)
    

    Alternatives are discussed here. 这个问题是gzip 格式所固有的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多