Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
feat: Correct ZIP file match when parse.
Browse files Browse the repository at this point in the history
  • Loading branch information
errnull committed Sep 29, 2019
1 parent eb45964 commit f3e204f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Source/SVGAParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#import <SSZipArchive/SSZipArchive.h>
#import <CommonCrypto/CommonDigest.h>

#define ZIP_MAGIC_NUMBER "PK"

@interface SVGAParser ()

@end
Expand Down Expand Up @@ -176,6 +178,14 @@ - (void)clearCache:(nonnull NSString *)cacheKey {
[[NSFileManager defaultManager] removeItemAtPath:cacheDir error:NULL];
}

+ (BOOL)isZIPData:(NSData *)data {
BOOL result = NO;
if (!strncmp([data bytes], ZIP_MAGIC_NUMBER, strlen(ZIP_MAGIC_NUMBER))) {
result = YES;
}
return result;
}

- (void)parseWithData:(nonnull NSData *)data
cacheKey:(nonnull NSString *)cacheKey
completionBlock:(void ( ^ _Nullable)(SVGAVideoEntity * _Nonnull videoItem))completionBlock
Expand All @@ -192,9 +202,7 @@ - (void)parseWithData:(nonnull NSData *)data
if (!data || data.length < 4) {
return;
}
NSData *tag = [data subdataWithRange:NSMakeRange(0, 4)];
NSString *fileTagDes = [tag description];
if (![fileTagDes containsString:@"504b0304"]) {
if (![SVGAParser isZIPData:data]) {
// Maybe is SVGA 2.0.0
[parseQueue addOperationWithBlock:^{
NSData *inflateData = [self zlibInflate:data];
Expand Down

0 comments on commit f3e204f

Please sign in to comment.