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

Commit f3e204f

Browse files
committed
feat: Correct ZIP file match when parse.
1 parent eb45964 commit f3e204f

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

Source/SVGAParser.m

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#import <SSZipArchive/SSZipArchive.h>
1414
#import <CommonCrypto/CommonDigest.h>
1515

16+
#define ZIP_MAGIC_NUMBER "PK"
17+
1618
@interface SVGAParser ()
1719

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

181+
+ (BOOL)isZIPData:(NSData *)data {
182+
BOOL result = NO;
183+
if (!strncmp([data bytes], ZIP_MAGIC_NUMBER, strlen(ZIP_MAGIC_NUMBER))) {
184+
result = YES;
185+
}
186+
return result;
187+
}
188+
179189
- (void)parseWithData:(nonnull NSData *)data
180190
cacheKey:(nonnull NSString *)cacheKey
181191
completionBlock:(void ( ^ _Nullable)(SVGAVideoEntity * _Nonnull videoItem))completionBlock
@@ -192,9 +202,7 @@ - (void)parseWithData:(nonnull NSData *)data
192202
if (!data || data.length < 4) {
193203
return;
194204
}
195-
NSData *tag = [data subdataWithRange:NSMakeRange(0, 4)];
196-
NSString *fileTagDes = [tag description];
197-
if (![fileTagDes containsString:@"504b0304"]) {
205+
if (![SVGAParser isZIPData:data]) {
198206
// Maybe is SVGA 2.0.0
199207
[parseQueue addOperationWithBlock:^{
200208
NSData *inflateData = [self zlibInflate:data];

0 commit comments

Comments
 (0)