如何拖动压缩文件而不读取其全部内容? [英] How can I tail a zipped file without reading its entire contents?

查看:173
本文介绍了如何拖动压缩文件而不读取其全部内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想模仿gzcat的功能tail -n。



这将有助于有大量文件(几GB的左右)的时候。我可以拖尾这样的文件的最后几行,从头读它吗?我怀疑这是不可能的,因为我猜猜gzip,编码将取决于所有以前的文本。



但我仍然想听到

解决方案

不,你可以使用一个可以提供这样的功能的压缩算法。 't。 压缩算法适用于流和适配器它的内部编码到流包含的内容以实现其高压缩比。



在某个点之前不知道流的内容是什么,不可能知道如何



任何允许对其任意部分进行解压缩的算法都需要对数据进行多次压缩才能压缩。 / p>

I want to emulate the functionality of gzcat | tail -n.

This would be helpful for times when there are huge files (of a few GB's or so). Can I tail the last few lines of such a file w/o reading it from the beginning? I doubt that this won't be possible since I'd guess for gzip, the encoding would depend on all the previous text.

But still I'd like to hear if anyone has tried doing something similar - maybe investigating over a compression algorithm that could provide such a feature.

解决方案

No, you can't. The zipping algorithm works on streams and adapts its internal codings to what the stream contains to achieve its high compression ratio.

Without knowing what the contents of the stream are before a certain point, it's impossible to know how to go about de-compressing from that point on.

Any algorithm which allows you to de-compress arbitrary parts of it will require multiple passes over the data to compress it.

这篇关于如何拖动压缩文件而不读取其全部内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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