成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

在iPhone開發中實現解壓縮gzip

移動開發 iOS
本文介紹的是在iPhone開發中實現解壓縮gzip,主要介紹的是解壓縮的操作,我們來看內容。

iPhone開發中實現解壓gzip是本文要介紹的內容,最近做的一個東西中,需要從網絡獲取xml文件,但是該文件用了gzip壓縮的。搜索一 下有人說gzip壓縮的用urlrequest可以自己解壓,但是這必須從服務器返回的header中有accept-Encoding說明是gzip 的。也就是用這句就可以實現自解壓

  1. [urlRequest addValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];  

這個在我的項目中沒有作用,因為服務器返回的header中沒有Accept-Encoding的說明。這就需要手動解壓了!解壓需要導入libz.1.2.3.dylib庫,導入#import "zlib.h"

下面是解壓的代碼:

  1. -(NSData *)uncompressZippedData:(NSData *)compressedData    
  2. {    
  3.  
  4.     if ([compressedData length] == 0) return compressedData;    
  5.  
  6.     unsigned full_length = [compressedData length];    
  7.  
  8.     unsigned half_length = [compressedData length] / 2;    
  9.     NSMutableData *decompressed = [NSMutableData dataWithLength: full_length + half_length];    
  10.     BOOL done = NO;    
  11.     int status;    
  12.     z_stream strm;    
  13.     strm.next_in = (Bytef *)[compressedData bytes];    
  14.     strm.avail_in = [compressedData length];    
  15.     strm.total_out = 0;    
  16.     strm.zalloc = Z_NULL;    
  17.     strm.zfree = Z_NULL;    
  18.     if (inflateInit2(&strm, (15+32)) != Z_OK) return nil;    
  19.     while (!done) {    
  20.         // Make sure we have enough room and reset the lengths.    
  21.         if (strm.total_out >= [decompressed length]) {    
  22.             [decompressed increaseLengthBy: half_length];    
  23.         }    
  24.         strm.next_out = [decompressed mutableBytes] + strm.total_out;    
  25.         strm.avail_out = [decompressed length] - strm.total_out;    
  26.         // Inflate another chunk.    
  27.         status = inflate (&strm, Z_SYNC_FLUSH);    
  28.         if (status == Z_STREAM_END) {    
  29.             done = YES;    
  30.         } else if (status != Z_OK) {    
  31.             break;    
  32.         }    
  33.  
  34.     }    
  35.     if (inflateEnd (&strm) != Z_OK) return nil;    
  36.     // Set real length.    
  37.     if (done) {    
  38.         [decompressed setLength: strm.total_out];    
  39.         return [NSData dataWithData: decompressed];    
  40.     } else {    
  41.         return nil;    
  42.     }    
  43. }  

小結:在iPhone開發中實現解壓縮gzip的內容介紹完了,希望本文對你有所幫助!

責任編輯:zhaolei 來源: 互聯網
相關推薦

2023-01-30 09:04:56

Linux命令unzip

2018-09-14 16:18:26

Linux壓縮文件應用程序

2010-06-24 09:29:02

Linux Bzip2

2010-01-04 09:27:31

Linux壓縮解壓縮命令詳解

2012-05-10 09:43:28

2023-12-21 07:30:36

PythonZipfileTarfile

2010-03-05 09:50:37

Ubuntu ligh

2023-03-29 08:59:59

Go壓縮包文檔

2011-07-26 14:18:20

2009-10-21 09:10:52

VB.NET壓縮

2010-06-24 10:42:42

Bzip2壓縮

2016-11-17 22:02:13

Linux壓縮及解壓縮

2021-02-22 07:58:52

Linux壓縮解壓

2009-12-08 16:33:45

PHP unpack函

2013-07-22 13:54:32

iOS開發ASIHTTPRequ

2011-08-15 14:07:53

Objective-C解壓縮ZIP文件

2024-02-22 12:16:55

Python壓縮數據

2009-07-08 16:10:36

Servlet和JSPJSP頁面

2018-01-12 17:03:29

HTTPgzip壓縮

2011-08-15 15:44:46

iPhone開發PDF
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产精品视频网 | 日韩一区精品 | 国产色婷婷精品综合在线播放 | 给我免费的视频在线观看 | 亚洲国产区 | 亚洲综合二区 | 九九免费观看视频 | 国产精品18久久久 | 欧美日韩视频网站 | 久久亚洲国产精品日日av夜夜 | 97色在线观看免费视频 | 99re国产精品 | 成人在线精品 | 亚洲视频手机在线 | 五月槐花香| 视频1区 | 成人av在线网站 | 亚洲一区二区三区久久 | 夜夜精品浪潮av一区二区三区 | 日本一区二区三区在线观看 | 午夜免费视频 | 亚洲精品久久久一区二区三区 | 99爱国产| 日韩欧美一区二区三区免费观看 | 9久久婷婷国产综合精品性色 | 欧美精品久久久久久久久久 | 国产www成人 | 国产一级视频在线播放 | 欧美成人第一页 | 天天干狠狠 | 欧美日批 | 欧美 日韩精品 | 久久这里只有精品首页 | 欧美一区二区三区视频 | 国产精品99久久久久久宅男 | 精品欧美一区二区在线观看欧美熟 | 国产一区二区三区在线免费 | 日韩成人免费视频 | 高清色| 久久久精品一区 | 欧美伊人影院 |