@@ -35,11 +35,19 @@ - (void)parseWithURL:(nonnull NSURL *)URL
3535 completionBlock : (void ( ^ _Nonnull )(SVGAVideoEntity * _Nullable videoItem))completionBlock
3636 failureBlock : (void ( ^ _Nullable)(NSError * _Nullable error))failureBlock {
3737 [self parseWithURLRequest: [NSURLRequest requestWithURL: URL cachePolicy: NSURLRequestReturnCacheDataElseLoad timeoutInterval: 20.0 ]
38- completionBlock: completionBlock
39- failureBlock: failureBlock];
38+ completionBlock: completionBlock
39+ failureBlock: failureBlock];
4040}
4141
4242- (void )parseWithURLRequest : (NSURLRequest *)URLRequest completionBlock : (void (^)(SVGAVideoEntity * _Nullable))completionBlock failureBlock : (void (^)(NSError * _Nullable))failureBlock {
43+ if (URLRequest.URL == nil ) {
44+ if (failureBlock) {
45+ [[NSOperationQueue mainQueue ] addOperationWithBlock: ^{
46+ failureBlock ([NSError errorWithDomain: @" SVGAParser" code: 411 userInfo: @{NSLocalizedDescriptionKey : @" URL cannot be nil." }]);
47+ }];
48+ }
49+ return ;
50+ }
4351 if ([[NSFileManager defaultManager ] fileExistsAtPath: [self cacheDirectory: [self cacheKey: URLRequest.URL]]]) {
4452 [self parseWithCacheKey: [self cacheKey: URLRequest.URL] completionBlock: ^(SVGAVideoEntity * _Nonnull videoItem) {
4553 if (completionBlock) {
@@ -89,20 +97,18 @@ - (void)parseWithNamed:(NSString *)named
8997 completionBlock : (void (^)(SVGAVideoEntity * _Nonnull))completionBlock
9098 failureBlock : (void (^)(NSError * _Nonnull))failureBlock {
9199 NSString *filePath = [(inBundle ?: [NSBundle mainBundle ]) pathForResource: named ofType: @" svga" ];
92- if (filePath != nil ) {
93- NSString *cacheKey = [self cacheKey: [NSURL fileURLWithPath: filePath]];
94- [self parseWithData: [NSData dataWithContentsOfFile: filePath]
95- cacheKey: cacheKey
96- completionBlock: completionBlock
97- failureBlock: failureBlock];
98- }
99- else {
100+ if (filePath == nil ) {
100101 if (failureBlock) {
101102 [[NSOperationQueue mainQueue ] addOperationWithBlock: ^{
102103 failureBlock ([NSError errorWithDomain: @" SVGAParser" code: 404 userInfo: @{NSLocalizedDescriptionKey : @" File not exist." }]);
103104 }];
104105 }
106+ return ;
105107 }
108+ [self parseWithData: [NSData dataWithContentsOfFile: filePath]
109+ cacheKey: [self cacheKey: [NSURL fileURLWithPath: filePath]]
110+ completionBlock: completionBlock
111+ failureBlock: failureBlock];
106112}
107113
108114- (void )parseWithCacheKey : (nonnull NSString *)cacheKey
@@ -360,7 +366,7 @@ - (NSString *)MD5String:(NSString *)str {
360366- (NSData *)zlibInflate : (NSData *)data
361367{
362368 if ([data length ] == 0 ) return data;
363-
369+
364370 unsigned full_length = (unsigned )[data length ];
365371 unsigned half_length = (unsigned )[data length ] / 2 ;
366372
0 commit comments