Unix系统编程——以编程方式解压缩文件
我需要做的是解压缩一个文件(.gz 或 .z),读取第一行并根据读取的第一行执行一些操作。但C标准库似乎没有提供这样做的方法。
这是一种独立于平台的方法吗?
What I need to do is unzip a file, (.gz or .z), read the first line and do some stuff according to the first line read. But the C standard library doesn't seem to offer a way to do this.
Is the a platform-independent way to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用“zlib”,执行压缩和解压缩的库:
http://www.zlib.net/
包含在所有 Unix 发行版的基础中,您可以轻松地将您的程序链接到 Windows 版本并发送 DLL。
Use "zlib", the library that performs compression and decompression:
http://www.zlib.net/
It's included in the base of all Unix distributions, and you can easily link your program against it for the windows version and ship the DLL.
info-zip 库相当可移植。
The info-zip libraries are quite portable.
如果你想独立于平台,你的程序中必须有解压缩代码。您可能想要链接到第三方库,例如 Unix 系统上的标准 ZLib ,或者在 Windows 上使用 DLL。
其余的非常简单:使用 ZLib 将文件解压缩到临时位置,正常读取文件,然后在完成后删除文件。
if you want to platform-independent, you'd have to have the unzipping code in your program. Likely, you'd want to link against a third-party library, such as ZLib which is standard on Unix systems, or use the DLL when on Windows.
The rest is pretty simple: use ZLib to unzip the file to a temporary location, read the file as normal, then remove the file when you're done.