changes in the import

This commit is contained in:
Patrick Santana 2014-04-29 16:18:19 -03:00
parent 0c0ad624d1
commit 1f68ac14a2
5 changed files with 52 additions and 1 deletions

View file

@ -18,7 +18,6 @@
// limitations under the License.
#import <Foundation/Foundation.h>
#import "OAMutableURLRequest.h"
#import "OAToken.h"
#import "OAServiceTicket.h"
#import "OADataFetcher.h"

View file

@ -0,0 +1 @@
../../SDWebImage/SDWebImage/NSData+ImageContentType.h

View file

@ -0,0 +1 @@
../../SDWebImage/SDWebImage/NSData+ImageContentType.h

View file

@ -0,0 +1,10 @@
//
// Created by Fabrice Aneche on 06/01/14.
// Copyright (c) 2014 Dailymotion. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSData (ImageContentType)
+ (NSString *)contentTypeForImageData:(NSData *)data;
@end

View file

@ -0,0 +1,40 @@
//
// Created by Fabrice Aneche on 06/01/14.
// Copyright (c) 2014 Dailymotion. All rights reserved.
//
#import "NSData+ImageContentType.h"
@implementation NSData (ImageContentType)
+ (NSString *)contentTypeForImageData:(NSData *)data {
uint8_t c;
[data getBytes:&c length:1];
switch (c) {
case 0xFF:
return @"image/jpeg";
case 0x89:
return @"image/png";
case 0x47:
return @"image/gif";
case 0x49:
case 0x4D:
return @"image/tiff";
case 0x52:
// R as RIFF for WEBP
if ([data length] < 12) {
return nil;
}
NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding];
if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) {
return @"image/webp";
}
return nil;
}
return nil;
}
@end