Add one convenient method to use base64 encoded image data
This commit is contained in:
parent
68d73f4cb2
commit
c0602e6733
|
@ -234,7 +234,7 @@ FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextAnimat
|
|||
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextDownloadRequestModifier;
|
||||
|
||||
/**
|
||||
A id<SDWebImageDownloaderResponseModifier> instance to modify the image download response and download data. It's used for downloader to modify the original response and data from URL and options. This can be used for image data decryption, such as Gzipped image. If you provide one, it will ignore the `responseModifier` in downloader and use provided one instead. (id<SDWebImageDownloaderResponseModifier>)
|
||||
A id<SDWebImageDownloaderResponseModifier> instance to modify the image download response and download data. It's used for downloader to modify the original response and data from URL and options. This can be used for image data decryption, such as Base64 encoded image. If you provide one, it will ignore the `responseModifier` in downloader and use provided one instead. (id<SDWebImageDownloaderResponseModifier>)
|
||||
*/
|
||||
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextDownloadResponseModifier;
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ typedef SDImageLoaderCompletedBlock SDWebImageDownloaderCompletedBlock;
|
|||
@property (nonatomic, strong, nullable) id<SDWebImageDownloaderRequestModifier> requestModifier;
|
||||
|
||||
/**
|
||||
* Set the response modifier to modify the original download response or download data before decoding. This can be used for image data decryption, such as Gzipped image.
|
||||
* Set the response modifier to modify the original download response or download data before decoding. This can be used for image data decryption, such as Base64 encoded image.
|
||||
* This request modifier method will be called for each downloading image response. Return the original response or data means no modication. Return nil from either response or data, will mark this download failed, pay attention to this.
|
||||
* Defaults to nil, means does not modify the original download response or download data.
|
||||
* @note If you want to modify single response, consider using `SDWebImageContextDownloadResponseModifier` context option.
|
||||
|
|
|
@ -32,3 +32,12 @@ typedef NSData * _Nullable (^SDWebImageDownloaderResponseModifierDataBlock)(NSDa
|
|||
+ (nonnull instancetype)responseModifierWithResponseBlock:(nonnull SDWebImageDownloaderResponseModifierBlock)responseBlock dataBlock:(nonnull SDWebImageDownloaderResponseModifierDataBlock)dataBlock;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
/// Convenience way to create response modifier for common data encryption.
|
||||
@interface SDWebImageDownloaderResponseModifier (Conveniences)
|
||||
|
||||
/// Base64 Encoded image data
|
||||
@property (class, readonly, nonnull) SDWebImageDownloaderResponseModifier *base64ResponseModifier;
|
||||
|
||||
@end
|
||||
|
|
|
@ -47,3 +47,21 @@
|
|||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation SDWebImageDownloaderResponseModifier (Conveniences)
|
||||
|
||||
+ (SDWebImageDownloaderResponseModifier *)base64ResponseModifier {
|
||||
static SDWebImageDownloaderResponseModifier *responseModifier;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
responseModifier = [SDWebImageDownloaderResponseModifier responseModifierWithResponseBlock:^NSURLResponse * _Nullable(NSURLResponse * _Nonnull response) {
|
||||
return response;
|
||||
} dataBlock:^NSData * _Nullable(NSData * _Nonnull data, NSURLResponse * _Nullable response) {
|
||||
return [[NSData alloc] initWithBase64EncodedData:data options:NSDataBase64DecodingIgnoreUnknownCharacters];
|
||||
}];
|
||||
});
|
||||
return responseModifier;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue