From 67bb07bb55577970761b51effa9e17b05b86a2a2 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Tue, 17 Jul 2012 19:00:33 +0200 Subject: ipsw: add function ipsw_get_file_size() to get uncompressed file size --- src/ipsw.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/ipsw.c') diff --git a/src/ipsw.c b/src/ipsw.c index 789af60..84547b3 100644 --- a/src/ipsw.c +++ b/src/ipsw.c @@ -56,6 +56,32 @@ ipsw_archive* ipsw_open(const char* ipsw) { return archive; } +int ipsw_get_file_size(const char* ipsw, const char* infile, off_t* size) { + ipsw_archive* archive = ipsw_open(ipsw); + if (archive == NULL || archive->zip == NULL) { + error("ERROR: Invalid archive\n"); + return -1; + } + + int zindex = zip_name_locate(archive->zip, infile, 0); + if (zindex < 0) { + error("ERROR: zip_name_locate: %s\n", infile); + return -1; + } + + struct zip_stat zstat; + zip_stat_init(&zstat); + if (zip_stat_index(archive->zip, zindex, 0, &zstat) != 0) { + error("ERROR: zip_stat_index: %s\n", infile); + return -1; + } + + *size = zstat.size; + + ipsw_close(archive); + return 0; +} + int ipsw_extract_to_file(const char* ipsw, const char* infile, const char* outfile) { ipsw_archive* archive = ipsw_open(ipsw); if (archive == NULL || archive->zip == NULL) { -- cgit v1.1-32-gdbae