2012-07-12 77 views
0

我想知道是否使用ASIHTTPRequest我們可以解壓縮一個.zip下載的文件或者它只能將 解壓縮爲.gzip壓縮文件。通過asihttprequest解壓下載的文件

請讓我知道,因爲如果ASIHTTPRequest無法解壓.zip壓縮文件,那麼我將不得不使用ZipArchive等第三方api解壓縮下載的文件。

感謝

回答

0

爲什麼不使用gzip壓縮這將通過ASI(和幾乎所有其他HTTP訪問的框架)來透明地解碼你的HTTP通訊。

ASIHTTP支持減壓,例如 -

- (IBAction)grabURL:(id)sender 
{ 
    NSURL *url    = [NSURL URLWithString:@"http://allseeing-i.com"]; 
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; 

    // YES is the default, you can turn off gzip compression by setting this to NO 
    [request setAllowCompressedResponse:YES]; 

    [request startSynchronous]; 
    BOOL *dataWasCompressed = [request isResponseCompressed]; // Was the response gzip compressed? 
    NSData *compressedResponse = [request rawResponseData]; // Compressed data 
    NSData *uncompressedData = [request responseData]; // Uncompressed data 
    NSString *response   = [request responseString]; // Uncompressed data as a string 
} 

UPDATE:櫃面ASI不支持解壓ZIP文件然後我用ZipArchive在過去的成功。

這是相當ligyweight和使用簡單,支持密碼保護,ZIP中的多個文件,以及壓縮&解壓縮。所以你需要先通過asi獲取壓縮文件,然後使用ziparchive進行解壓縮。

的基本用法是:

NSString *filepath = [[NSBundle mainBundle] pathForResource:@"ZipFileName" ofType:@"zip"]; 
ZipArchive *zipArchive = [[ZipArchive alloc] init]; 
[zipArchive UnzipOpenFile:filepath Password:@"xxxxxx"]; 
[zipArchive UnzipFileTo:{pathToDirectory} overWrite:YES]; 
[zipArchive UnzipCloseFile]; 
[zipArchive release]; 
+0

還是你的意思是說我們只能解壓gzip壓縮的數據通過ASI不ZIP壓縮數據。 – Aisha 2012-07-12 07:02:20

+0

試一試。看看它是否有效。如果zip不能在asi中工作。然後看到我上面的更新。 – 2012-07-12 07:06:48