C# 中的 GZIP 文件总长度
我有一个大小为几 GB 的压缩文件,我想获取解压缩内容的大小,但不想在 C# 中实际解压缩该文件,我可以使用什么库?当我右键单击 .gz 文件并转到“属性”时,在“存档”选项卡下有一个属性名称“TotalLength”,它显示了该值。但我想使用 C# 以编程方式获取它..有什么想法吗?
I have a zipped file having size of several GBs, I want to get the size of Unzipped contents but don't want to actually unzip the file in C#, What might be the Library I can use? When I right click on the .gz file and go to Properties then under the Archive
Tab there is a property name TotalLength
which is showing this value. But I want to get it Programmatically using C#.. Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
gz 文件的最后 4 个字节包含长度。
所以它应该是这样的:
The last 4 bytes of the gz file contains the length.
So it should be something like:
.gz 文件的最后一个字节是未压缩的输入大小模 2^32。如果您的未压缩文件不大于 4GB,则只需读取文件的最后 4 个字节。如果您有更大的文件,我不确定是否可以在不解压缩流的情况下获得。
The last for bytes of a .gz file are the uncompressed input size modulo 2^32. If your uncompressed file isn't larger than 4GB, just read the last 4 bytes of the file. If you have a larger file, I'm not sure that it's possible to get without uncompressing the stream.
编辑:参见 Leppie 和 Gabe 的答案;我保留它(而不是删除它)的唯一原因是,如果您怀疑长度>,则可能有必要。 4GB
对于 gzip,该数据似乎无法直接获得 - 我查看了
GZipStream
和 SharpZipLib 等效项 - 两者都不起作用。我能建议的最好的办法是在本地运行它:如果它是一个 zip,那么 SharpZipLib:
EDIT: See the answers by Leppie and Gabe; the only reason I'm keeping this (rather than deleting it) is that it may be necessary if you suspect the length is > 4GB
For gzip, that data doesn't seem to be directly available - I've looked at
GZipStream
and the SharpZipLib equivalent - neither works. The best I can suggest is to run it locally:If it was a zip, then SharpZipLib: