forked from davekeck/EBDownloadCaching
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEBImageDownloadCache.m
More file actions
32 lines (24 loc) · 1.32 KB
/
EBImageDownloadCache.m
File metadata and controls
32 lines (24 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#import "EBImageDownloadCache.h"
#import <ImageIO/ImageIO.h>
#import <EBFoundation/EBFoundation.h>
@implementation EBImageDownloadCache
- (instancetype)initWithMemoryCache: (NSCache *)memoryCache diskCache: (EBDiskCache *)diskCache
{
NSValueTransformer *transformer = [EBBlockValueTransformer newWithForwardBlock: ^id(id data)
{
/* We have to use NSCParameterAssert, because NSParameterAssert maintains a strong reference to `self`! */
NSCParameterAssert(data && [data isKindOfClass: [NSData class]]);
id imageSource = CFBridgingRelease(CGImageSourceCreateWithData((__bridge CFDataRef)data, nil));
EBAssertOrRecover(imageSource, return nil);
id image = CFBridgingRelease(CGImageSourceCreateImageAtIndex((__bridge CGImageSourceRef)imageSource, 0, nil));
EBAssertOrRecover(image, return nil);
return image;
}];
return [super initWithMemoryCache: memoryCache diskCache: diskCache transformer: transformer];
}
- (instancetype)initWithMemoryCache: (NSCache *)memoryCache diskCache: (EBDiskCache *)diskCache transformer: (NSValueTransformer *)transformer
{
EBRaise(@"%@ cannot be initialized via %@!", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
return nil;
}
@end