NSData+BBAGZip.h 2.66 KB
//
//  NSData+BBAGZip.h
//  ZipArchive
//
//  Created by Zhu,Yusong on 2018/10/16.
//  Copyright © 2018年 Baidu. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "BDPFoundationDefines.h"

NS_ASSUME_NONNULL_BEGIN

typedef NSInteger BDPCompressionLevel;
FOUNDATION_EXTERN BDPCompressionLevel const BDPCompressionLevelNoCompressin;
FOUNDATION_EXTERN BDPCompressionLevel const BDPCompressionLevelBestSpeed;
FOUNDATION_EXTERN BDPCompressionLevel const BDPCompressionLevelBestCompression;
FOUNDATION_EXTERN BDPCompressionLevel const BDPCompressionLevelDefaultCompression;

@interface NSData (BBAGZip)

/**
 * @brief 默认的 GZip 压缩, level 为 BDPCompressionLevelDefaultCompression, 速度快
 *
 * @return GZip 压缩后的 NSData
 */
- (nullable NSData *)bba_compressGZip BDP_FOUNDATION_DEPRECATED("please use bdp_compressGZip");
- (nullable NSData *)bdp_compressGZip;

/**
 * @brief 性能最好的 GZip 压缩, level 为 BDPCompressionLevelBestCompression, 速度慢
 *
 * @return GZip 压缩后的 NSData
 */
- (nullable NSData *)bba_bestCompressGZip BDP_FOUNDATION_DEPRECATED("please use bdp_bestCompressGZip");
- (nullable NSData *)bdp_bestCompressGZip;

/**
 * @brief GZip 压缩
 *
 * @param level 压缩 level 推荐 Z_DEFAULT_COMPRESSION 或 Z_BEST_COMPRESSION (分别代表 -1 和 9,注意不要用 0)
 * @param outputLength 估计的 output 长度, 如果最后长度与实际 output 不符合,会进行动态调整
 * @return GZip 压缩后的 NSData
 *
 * @note 建议使用上面压缩方法,其 outputLength = self.length / 2
 */
- (nullable NSData *)bba_compressGZipWithCompressionLevel:(int)level estimatedOutputLength:(NSUInteger)outputLength BDP_FOUNDATION_DEPRECATED("please use bdp_compressGZipWithLevel:");
- (nullable NSData *)bdp_compressGZipWithLevel:(BDPCompressionLevel)level;

/**
 * @brief GZip 解压
 *
 * @return GZip 解压后的 NSData
 */
- (nullable NSData *)bba_decompressGZip BDP_FOUNDATION_DEPRECATED("please use bdp_decompressGZip");
- (nullable NSData *)bdp_decompressGZip;

/**
 * @brief GZip 解压
 *
 * @param outputLength outputLength 估计的 output 长度, 如果最后长度与实际 output 不符合,会进行动态调整
 * @return GZip 解压后的 NSData
 *
 * @note 建议调用上面解压方法,其 outputLength = self.length * 2
 */
- (nullable NSData *)bba_decompressGZipWithEstimatedOutputLength:(NSUInteger)outputLength BDP_FOUNDATION_DEPRECATED("please use bdp_decompressGZip");

/**
 * @brief 判断是否是 GZip 压缩后的 NSData
 *
 * @return YES on success
 */
- (BOOL)bba_isCompressedGZipData BDP_FOUNDATION_DEPRECATED("please use bdp_isCompressedGZipData");
- (BOOL)bdp_isCompressedGZipData;

@end

NS_ASSUME_NONNULL_END