iPhone zip壓縮與解壓

ziparchive是基於開源代碼"MiniZip"的zip壓縮與解壓的Objective-C 的Class,使用起來非常的簡單.你只需要把代碼加進你的工程,然後把zlib庫添加到工程就可以了.
ziparchive可以在googlecode上下載,地址如下
http://code.google.com/p/ziparchive/

壓縮:

ZipArchive可以壓縮多個文件,只需要把文件一一addFileToZip即可.

  1.    ZipArchive* zip = [[ZipArchive alloc] init];
  2.          
  3.     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  4.           NSString *dcoumentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
  5.           NSString* l_zipfile = [dcoumentpath stringByAppendingString:@"/test.zip"] ;
  6.          
  7.           NSString* image1 = [dcoumentpath stringByAppendingString:@"/image1.jpg"] ;   
  8.           NSString* image2 = [dcoumentpath stringByAppendingString:@"/image2.jpg"] ;      
  9.          
  10.           BOOL ret = [zip CreateZipFile2:l_zipfile];
  11.           ret = [zip addFileToZip:image1 newname:@"image1.jpg"];
  12.           ret = [zip addFileToZip:image2 newname:@"image2.jpg"];
  13.           if( ![zip CloseZipFile2] )
  14.           {
  15.               l_zipfile = @"";
  16.           }
  17.           [zip release];
複製代碼

解壓縮:

  1. ZipArchive* zip = [[ZipArchive alloc] init];
  2.           NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  3.           NSString *dcoumentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
  4.          
  5.           NSString* l_zipfile = [dcoumentpath stringByAppendingString:@"/test.zip"] ;
  6.           NSString* unzipto = [dcoumentpath stringByAppendingString:@"/test"] ;
  7.           if( [zip UnzipOpenFile:l_zipfile] )
  8.           {
  9.               BOOL ret = [zip UnzipFileTo:unzipto overWrite:YES];
  10.               if( NO==ret )
  11.               {
  12.               }
  13.               [zip UnzipCloseFile];
  14.           }
  15.          [zip release];

ziparchive是基於開源代碼"MiniZip"的zip壓縮與解壓的Objective-C 的Class,使用起來非常的簡單.你只需要把代碼加進你的工程,然後把zlib庫添加到工程就可以了.
ziparchive可以在googlecode上下載,地址如下
http://code.google.com/p/ziparchive/

壓縮:

ZipArchive可以壓縮多個文件,只需要把文件一一addFileToZip即可.

  1.    ZipArchive* zip = [[ZipArchive alloc] init];
  2.          
  3.     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  4.           NSString *dcoumentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
  5.           NSString* l_zipfile = [dcoumentpath stringByAppendingString:@"/test.zip"] ;
  6.          
  7.           NSString* image1 = [dcoumentpath stringByAppendingString:@"/image1.jpg"] ;   
  8.           NSString* image2 = [dcoumentpath stringByAppendingString:@"/image2.jpg"] ;      
  9.          
  10.           BOOL ret = [zip CreateZipFile2:l_zipfile];
  11.           ret = [zip addFileToZip:image1 newname:@"image1.jpg"];
  12.           ret = [zip addFileToZip:image2 newname:@"image2.jpg"];
  13.           if( ![zip CloseZipFile2] )
  14.           {
  15.               l_zipfile = @"";
  16.           }
  17.           [zip release];
複製代碼

解壓縮:

  1. ZipArchive* zip = [[ZipArchive alloc] init];
  2.           NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  3.           NSString *dcoumentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
  4.          
  5.           NSString* l_zipfile = [dcoumentpath stringByAppendingString:@"/test.zip"] ;
  6.           NSString* unzipto = [dcoumentpath stringByAppendingString:@"/test"] ;
  7.           if( [zip UnzipOpenFile:l_zipfile] )
  8.           {
  9.               BOOL ret = [zip UnzipFileTo:unzipto overWrite:YES];
  10.               if( NO==ret )
  11.               {
  12.               }
  13.               [zip UnzipCloseFile];
  14.           }
  15.           [zip release];

    ziparchive是基於開源代碼"MiniZip"的zip壓縮與解壓的Objective-C 的Class,使用起來非常的簡單.你只需要把代碼加進你的工程,然後把zlib庫添加到工程就可以了.
    ziparchive可以在googlecode上下載,地址如下
    http://code.google.com/p/ziparchive/

    壓縮:

    ZipArchive可以壓縮多個文件,只需要把文件一一addFileToZip即可.

    1.    ZipArchive* zip = [[ZipArchive alloc] init];
    2.          
    3.     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    4.           NSString *dcoumentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
    5.           NSString* l_zipfile = [dcoumentpath stringByAppendingString:@"/test.zip"] ;
    6.          
    7.           NSString* image1 = [dcoumentpath stringByAppendingString:@"/image1.jpg"] ;   
    8.           NSString* image2 = [dcoumentpath stringByAppendingString:@"/image2.jpg"] ;      
    9.          
    10.           BOOL ret = [zip CreateZipFile2:l_zipfile];
    11.           ret = [zip addFileToZip:image1 newname:@"image1.jpg"];
    12.           ret = [zip addFileToZip:image2 newname:@"image2.jpg"];
    13.           if( ![zip CloseZipFile2] )
    14.           {
    15.               l_zipfile = @"";
    16.           }
    17.           [zip release];
    複製代碼

    解壓縮:

    1. ZipArchive* zip = [[ZipArchive alloc] init];
    2.           NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    3.           NSString *dcoumentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
    4.          
    5.           NSString* l_zipfile = [dcoumentpath stringByAppendingString:@"/test.zip"] ;
    6.           NSString* unzipto = [dcoumentpath stringByAppendingString:@"/test"] ;
    7.           if( [zip UnzipOpenFile:l_zipfile] )
    8.           {
    9.               BOOL ret = [zip UnzipFileTo:unzipto overWrite:YES];
    10.               if( NO==ret )
    11.               {
    12.               }
    13.               [zip UnzipCloseFile];
    14.           }
    15.           [zip release];
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章