Why is seeking from the end of a file allowed for BZip2 files and not Gzip files?

痴心易碎 提交于 2019-12-05 16:34:34

In simple terms, gzip is a stream compressor, which means that each compressed element depends on the previous one. Seeking would be pointless, because whole file would have to be decompressed anyway. Probably the authors of gzip.py assumed it is better to raise an error instead of silently decompressing the file, so that the user can realize that seeking is inefficient.

On the other hand bzip2 is a block compressor, each block is independent.

If you really want random access to a gzipped file, then write a wrapper which decompresses the contents and returns a buffer which offers seeking. Unfortunately that would defeat the optimisation which is mentioned in the link from your question.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!