In fact, in iOS development, compression and decompression, I was implemented using a third-party framework Ssziparchive
GitHub Address: Https://github.com/ZipArchive/ZipArchive
There are detailed methods of use
Because Ziparchive does not support arc, if your project opens arc, then you need to set the Ziparchive . In the Ziparchive. MM compilation option, add-fno-objc-arc.
Finally, the Libz.dylib dynamic link library needs to be linked to the project .
Use demonstration (compression):
Get the picture path of all png in Mainbundle nsarray *pngs = [[NSBundle mainbundle] pathsforresourcesoftype:@ "PNG" Indirectory:nil ]; Zip file path nsstring *caches = [Nssearchpathfordirectoriesindomains (nscachesdirectory, Nsuserdomainmask, YES) Lastobject]; NSString *zipfilepath = [Caches stringbyappendingpathcomponent:@ "Pngs.zip"]; Create a ZIP file
Extract:
NSString *caches = [Nssearchpathfordirectoriesindomains (nscachesdirectory, Nsuserdomainmask, YES) lastObject]; NSString *filepath = [caches stringbyappendingpathcomponent:@ "file name. zip"]; Dispatch_async (Dispatch_get_global_queue (dispatch_queue_priority_default, 0), ^{ //decompression (file size, it will be more time-consuming, so put in the sub-thread decompression) [ssziparchive Unzipfileatpath:filepath todestination:caches]; });
Compression and decompression in iOS development