关于在gzip文件上使用seek [英] About the use of seek on gzip files

查看:83
本文介绍了关于在gzip文件上使用seek的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的gzip文件,我只想使用seek读取其中的一部分. 关于在gzip文件上使用seek,此页面表示:

I have a big gzip file and I would like to read only parts of it using seek. About the use of seek on gzip files, this page says:

seek()位置相对于未压缩的数据,因此 呼叫者甚至不需要知道数据文件是否已压缩.

The seek() position is relative to the uncompressed data, so the caller does not even need to know that the data file is compressed.

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

Does this imply that seek has to read and decompress the data from the beginning of the file to the target position?

推荐答案

是. 这是代码:

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)

此处讨论替代方案.问题是gzip格式固有的.

这篇关于关于在gzip文件上使用seek的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆