如何在 C# 中解压缩嵌套的 GZip (TGZ) 文件
我收到一份 TGZ 文件,其中包含一个纯文本文件以及可能的一个或多个嵌套 TGZ 文件。我已经弄清楚如何解压缩主 TGZ 文件并读取其中包含的纯文本文件,但我无法弄清楚如何识别和解压缩嵌套的 TGZ 文件。以前有人遇到过这个问题吗?
另外,我无法控制收到的文件,因此无法更改包含嵌套 TGZ 文件的 TGZ 文件的格式。另一个需要注意的是(尽管我认为这并不重要),这些文件是在 Unix 或 Linux 环境中被压缩和焦化的。
预先感谢您的任何帮助。
I am receiving a TGZ file that will contain one plain text file along with possibly one or more nested TGZ files. I have figured out how to decompress the main TGZ file and read the plain text file contained in it, but I have not been able to figure out how to recognize and decompress the nested TGZ files. Has anyone come across this problem before?
Also, I do not have control over the file I am receiving, so I cannot change the format of a TGZ file containing nested TGZ files. One other caveat (even though I don't think it matters) is that these files are being compressed and tarred in a Unix or Linux environment.
Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试 SharpZipLib (http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx )免费图书馆。
它允许您使用 TGZ 并具有在尝试膨胀文件之前测试文件的方法;因此,您可以依赖正确的文件扩展名,或者单独测试它们,看看是否可以将它们作为压缩文件读取 - 然后在主文件解压缩后将它们膨胀。
Try the SharpZipLib (http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx) free library.
It lets you work with TGZ and has methods to test files before trying to inflate them; so you can either rely on the file extensions being correct, or test them individually to see if you can read them as compressed files - then inflate them once the main file has been decompressed.
要从 .NET 读取和写入 .tar 和 .tgz (或 .tar.gz )文件,您可以使用以下单文件 tar 类:
http://cheesoexamples.codeplex.com/SourceControl/changeset/view/97756#1868643
用法非常简单。要创建存档:
创建压缩 (gzip) tar 存档:
读取 tar 存档:
提取 tar 存档中的所有条目:
To read and write .tar and .tgz (or .tar.gz ) files from .NET, you can use this one-file tar class:
http://cheesoexamples.codeplex.com/SourceControl/changeset/view/97756#1868643
Very simple usage. To create an archive:
Create a compressed (gzip'd) tar archive:
Read a tar archive:
Extract all entries in a tar archive:
查看 CodePlex 上的 DotNetZip。
看来您可以遍历压缩文件并将各个文件从存档中拉出。然后您可以测试解压缩的文件并查看它们本身是否是 GZip 文件。
这是来自他们的 < a href="http://dotnetzip.codeplex.com/wikipage?title=CS-Examples&referringTitle=Examples" rel="nofollow noreferrer">示例页面
Keith
Take a look at DotNetZip on CodePlex.
It appears that you can iterate through the compressed file and pull the individual files out of the archive. You can then test the files you uncompressed and see if any of them are themselves GZip files.
Here is a snippit from their Examples Page
Keith