Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About the use of seek on gzip files

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:

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

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

like image 217
usual me Avatar asked Sep 23 '14 01:09

usual me


1 Answers

Yes. 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. The problem is inherent to the gzip format.

like image 61
Veedrac Avatar answered Sep 28 '22 21:09

Veedrac