[英]Vala: How to retrieve the names of all files in a zip archive without unzipping it?
vala中是否有任何功能,如erlang中的zip:list_dir
? 我找到了libgsf,但是我不想解壓縮zip文件。
您可以使用libarchive
。
void check_ok (Archive.Result r) throws IOError {
if (r == Archive.Result.OK)
return;
if (r == Archive.Result.WARN)
return;
throw new IOError.FAILED ("libarchive returned an error");
}
int main () {
try {
var a = new Archive.Read ();
check_ok (a.support_filter_all ());
check_ok (a.support_format_all ());
check_ok (a.open_filename ("archive.zip", 10240));
unowned Archive.Entry entry;
while (a.next_header (out entry) == Archive.Result.OK) {
stdout.printf ("%s\n", entry.pathname ());
a.read_data_skip ();
}
}
catch (IOError e) {
stderr.printf (e.message + "\n");
return 1;
}
return 0;
}
使用valac ListZip.vala --pkg libarchive --pkg gio-2.0
編譯。
僅IOError
錯誤域需要GIO。 實際上,您想用一些描述性更強的消息來擴展check_ok
方法,該操作已失敗。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.