亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

iPhone解壓碼

iPhone解壓碼

iOS
侃侃爾雅 2019-11-26 10:30:09
確實堅持嘗試編寫代碼來解壓縮iPhone上的文件或目錄。以下是一些用于嘗試解壓縮簡單文本文件的示例代碼。它將文件解壓縮,但已損壞。(void)loadView {    NSString *DOCUMENTS_FOLDER = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];    NSString *path = [DOCUMENTS_FOLDER stringByAppendingPathComponent:@"sample.zip"];    NSString *unzipeddest = [DOCUMENTS_FOLDER stringByAppendingPathComponent:@"test.txt"];      gzFile file = gzopen([path UTF8String], "rb");    FILE *dest = fopen([unzipeddest UTF8String], "w");    unsigned char buffer[CHUNK];    int uncompressedLength = gzread(file, buffer, CHUNK);    if(fwrite(buffer, 1, uncompressedLength, dest) != uncompressedLength ||     ferror(dest)) {        NSLog(@"error writing data");    }    else{    }    fclose(dest);    gzclose(file);  }
查看完整描述

3 回答

?
慕蓋茨4494581

TA貢獻1850條經驗 獲得超11個贊

我想要一個簡單的解決方案,但在這里找不到我喜歡的解決方案,因此我修改了一個庫以實現自己想要的功能。您可能會發現SSZipArchive有用。(它也可以順便創建zip文件。)


用法:


NSString *path = @"path_to_your_zip_file";

NSString *destination = @"path_to_the_folder_where_you_want_it_unzipped";

[SSZipArchive unzipFileAtPath:path toDestination:destination];


查看完整回答
反對 回復 2019-11-26
?
子衿沉夜

TA貢獻1828條經驗 獲得超3個贊

對于gzip,這段代碼對我來說效果很好:


數據庫是這樣準備的:gzip foo.db


關鍵是遍歷gzread()。上面的示例僅讀取前CHUNK字節。


#import <zlib.h>

#define CHUNK 16384



  NSLog(@"testing unzip of database");

  start = [NSDate date];

  NSString *zippedDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"foo.db.gz"];

  NSString *unzippedDBPath = [documentsDirectory stringByAppendingPathComponent:@"foo2.db"];

  gzFile file = gzopen([zippedDBPath UTF8String], "rb");

  FILE *dest = fopen([unzippedDBPath UTF8String], "w");

  unsigned char buffer[CHUNK];

  int uncompressedLength;

  while (uncompressedLength = gzread(file, buffer, CHUNK) ) {

    // got data out of our file

    if(fwrite(buffer, 1, uncompressedLength, dest) != uncompressedLength || ferror(dest)) {

      NSLog(@"error writing data");

    }

  }

  fclose(dest);

  gzclose(file);

  NSLog(@"Finished unzipping database");

順便說一句,我可以在77秒內將33MB解壓縮到130MB,或者每秒壓縮約1.7MB。


查看完整回答
反對 回復 2019-11-26
  • 3 回答
  • 0 關注
  • 562 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號