This repository was archived by the owner on Feb 6, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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];
You can’t perform that action at this time.
0 commit comments