iOS数据压缩与解压-创新互联

iOS  数据压缩与解压

创新互联公司10多年成都企业网站建设服务;为您提供网站建设,网站制作,网页设计及高端网站定制服务,成都企业网站建设及推广,对成都垃圾桶等多个领域拥有多年的网站设计经验的网站建设公司。

Hi,推荐文件给你 "数据压缩与解压.zip"

http://vdisk.weibo.com/s/Gbabp

本文中需要的第三库在本文的代码例子中可以下载。minizip和ZipArchive这两个第三库

ViewController.h代码如下:

#import 
#import "ZipArchive.h"
@interface ViewController : UIViewController
-(IBAction)compress:(id)sender;
-(IBAction)unAr:(id)sender;
@end

ViewController.m代码如下:

自己拖2个Button与如下两个方法相关联

//这方法中数据压缩的方法:

-(IBAction)compress:(id)sender
{
    //导入ZipArchive包之后要加入libz.1.2.5.dylib的库
    ZipArchive* zip = [[ZipArchive alloc] init];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
    NSString* zipfilePath = [documentpath stringByAppendingString:@"/dj.zip"] ;
    //
    NSLog(@"%@",zipfilePath);
                     
                     
    NSString* p_w_picpath2 = [[NSBundle mainBundle] pathForResource:@"xiaonan" ofType:@"jpg"];
    NSString* p_w_picpath3 = [[NSBundle mainBundle] pathForResource:@"xiaonan" ofType:@"jpg"];
                     
                     
    //创建压缩包
    BOOL ret = [zip CreateZipFile2:zipfilePath];
    //向压缩包内加入数据
    ret = [zip addFileToZip:p_w_picpath2 newname:@"xiaonan.jpg"];
    ret = [zip addFileToZip:p_w_picpath3 newname:@"p_w_picpath3.jpg"];
    //关闭压缩包
    [zip CloseZipFile2];
                     
                     
    [zip release];
}

//数据解压的方法

-(IBAction)unAr:(id)sender
{
        
    ZipArchive* zip = [[ZipArchive alloc] init];
         
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
         
    NSString* l_zipfile = [documentpath stringByAppendingString:@"/dj.zip"] ;
    NSString* unzipto = [documentpath stringByAppendingString:@"/dj"] ;
         
         
    //找到需要解压文件的路径
    if( [zip UnzipOpenFile:l_zipfile] )
    {
        BOOL ret = [zip UnzipFileTo:unzipto overWrite:YES];
        if( NO==ret )
        {
        }
        //完成解压
        [zip UnzipCloseFile];
    } 
    [zip release];
}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


本文标题:iOS数据压缩与解压-创新互联
本文URL:http://lszwz.com/article/eipej.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款