ios - How to unzip a big zip file containing one file and get the progress in bytes with swift? -
i try unzip big zip file containing 1 item (more 100mb) , show progress during unzipping.
i found solutions progress can determined based on amount of files unzipped in case have 1 big file inside. guess must determined amount of bytes unzipped?
actually using ssziparchive following code works fine:
var myzipfile:nsstring="/users/user/library/developer/coresimulator/devices/mydevice/ziptest/testzip.zip"; var destpath:nsstring="/users/user/library/developer/coresimulator/devices/mydevice/ziptest/"; let unzipped = ssziparchive.unzipfileatpath(myzipfile as! string, todestination: destpath as! string);
i found no solutions this.
does have hint, sample or link sample ?
update: following code looks work intended, handler called once (at end of unzipping) when 1 file unzipped:
func unzipfile(szipfile: string, todest: string){ ssziparchive.unzipfileatpath(szipfile, todestination: todest, progresshandler: { (entry, zipinfo, readbyte, totalbyte) -> void in println("readbyte : \(readbyte)") // <- called once, @ end of unzipping. 500mb zipfile holds 1 file. println("totalbyte : \(totalbyte)") //asynchrone task dispatch_async(dispatch_get_main_queue()) { println("readbyte : \(readbyte)") println("totalbyte : \(totalbyte)") //change progress value } }, completionhandler: { (path, success, error) -> void in if success { //successful!! } else { println(error) } }) }
update 2:
as "martin r" analysed in ssarchive, not possible. there other way unzip file , show progress based kbytes?
update 3:
i changed ssziparchive.m after solution explained "roop" follows. else can use too:
file *fp = fopen((const char*)[fullpath utf8string], "wb"); while (fp) { int readbytes = unzreadcurrentfile(zip, buffer, 4096); if (readbytes > 0) { fwrite(buffer, readbytes, 1, fp ); totalbytesread=totalbytesread+4096; // added me if (progresshandler) { progresshandler(strpath, fileinfo, currentfilenumber, totalbytesread); } // end added me } else { break; } }
to achieve want, have modify ssziparchive's internal code.
ssziparchive uses minizip provide zipping functionality. can see minizip unzipping api here: unzip.h.
in ssziparchive.m, can uncompressed size of file being unzipped fileinfo
variable.
you can see unzipped contents being read here:
file *fp = fopen((const char*)[fullpath utf8string], "wb"); while (fp) { int readbytes = unzreadcurrentfile(zip, buffer, 4096); if (readbytes > 0) { fwrite(buffer, readbytes, 1, fp ); } else { break; } }
you need readbytes
, uncompressed file size compute progress single file. can add new delegate ssziparchive send these data calling code.
Comments
Post a Comment