日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

gzip格式解压缩

發布時間:2024/1/3 综合教程 33 生活家
生活随笔 收集整理的這篇文章主要介紹了 gzip格式解压缩 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

gzip格式解壓縮

有時候網絡請求中會出現gzip格式的數據,而我們無法通過常規辦法進行解析:

這時候可以使用下面的這個工具來解決這個問題:

https://github.com/mattt/Godzippa

注意,使用的時候需要引入一個lib:

本人寫好的示例代碼:

https://github.com/YouXianMing/iOS-Utilities

//
//  ViewController.m
//  GZipDataCompression
//
//  Created by YouXianMing on 16/3/12.
//  Copyright © 2016年 YouXianMing. All rights reserved.
//

#import "ViewController.h"
#import "Godzippa.h"
#import "NSData+JSONData.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];

    // https://github.com/mattt/Godzippa
    
    /*
     Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: application/x-gzip" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7fd8f25293e0>{ status code: 200, headers {
     Date = "Sat, 12 Mar 2016 03:48:00 GMT";
     Server = "Apache-Coyote/1.1";
     "Transfer-Encoding" = Identity;
     } }, com.alamofire.serialization.response.error.data=<1f8b0800 00000000 0000ab56 4ace4f49 55b2520a 08720d34 30303054 d2514a49 2c4954b2 aaaed551 ca2d4e07 4a3ded6f 7a367543 746671ee f33dd39e f66f8f7d b2a3f745 f3de273b 763d5fb9 0ba8bea4 b2006482 9b522d00 1076388e 4e000000>, NSLocalizedDescription=Request failed: unacceptable content-type: application/x-gzip}
     */
    
    NSURL  *fileURL  = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"GZipData" ofType:nil]];
    NSData *GZipData = [NSData dataWithContentsOfURL:fileURL];
    NSLog(@"%@ %@", GZipData, [GZipData toListProperty]);
    
    NSData *decompressingData = [GZipData dataByGZipDecompressingDataWithError:nil];
    NSLog(@"%@ %@", decompressingData, [decompressingData toListProperty]);
}

@end

總結

以上是生活随笔為你收集整理的gzip格式解压缩的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。