Objective-Zip
Objective-Zip copied to clipboard
Error opening file in zipfile
Error Domain=ObjectiveZipErrorDomain Code=-102 "OZZipException" UserInfo={NSLocalizedDescription=OZZipException, NSLocalizedFailureReason=Error opening 'log.sqlite3' in zipfile}
I am trying to zip a sqlite file. The first time it works fine but if try continously try few times, it doesn't work and throw error at the line:
@throw [OZZipException zipExceptionWithError:err reason:@"Error opening '%@' in zipfile", fileNameInZip];
I understand that it's trying to open the file after creating the zip and failing. I made sure that the file.
NSError* error = nil;
@try {
OZZipFile *zipFile= [[OZZipFile alloc]initWithFileName:destinationPath mode:OZZipFileModeCreate legacy32BitMode:NO error:&error];
NSLog(@"error handling zipfile %@",error);
OZZipWriteStream *stream= [zipFile writeFileInZipWithName:[NSString stringWithFormat:@"%@.sqlite3",actualFilename] compressionLevel:OZZipCompressionLevelBest error:&error];
NSLog(@"error handling stream %@",error);
[stream writeData:[NSData dataWithContentsOfFile:dbFilePath] error:&error];
NSLog(@"error handling write data %@",error);
[stream finishedWritingWithError:&error];
NSLog(@"error handling finished write data %@",error);
[zipFile closeWithError:&error];
NSLog(@"error handling zip close %@",error);
}@catch (OZZipException *ze) {
NSLog(@"Zip exception caught: %ld - %@", (long) ze.error, [ze reason]);
} @catch (NSException *e) {
NSLog(@"Generic exception caught: %@ - %@", [[e class] description], [e description]);
}`
i found a similar issue on stackoverflow but no answer: https://stackoverflow.com/questions/51646894/getting-exception-while-creating-zip-file
any kind of help will be appreciated
Error code -102 corresponds to UNZ_PARAMERROR, which the underlying library returns for a number of reasons, the most probable being:
- The read buffer is bigger than 65535 bytes.
- The file name is longer than 256 bytes.
May one of these be your case?
@gianlucabertani thank you for your response. The file is ~39MB. The zip file name is like 'KIT=2018-11-13.15-47-09.zip' and the actual file name is 'dborder.sqlite3'. Let's say if I try to zip the file, it works fine at the first attempt. But it doesn't work afterwards.
That's weird.
Since UNZ_PARAMERROR
can be returned also if the file pointer is null, there may be some issues with the file from the second attempt on. You are creating the zip with OZZipFileModeCreate
, the file should be overwritten if already present, but if the stream remains open for some reason the second attempt may fail.
When creating the zip at the first attempt, check that this line:
NSLog(@"error handling zip close %@",error);
is present in the log and the error is nil.
You may also want to try to delete the zip file before your second attempt, with something like:
[[NSFileManager defaultManager] removeItemAtPath:destinationPath error:&error];
Also check that after deletion the error is nil.
Hope this helps.
Sorry for late reply. I didn't see notification.
the file should be overwritten if already present - Actually there is no way for this to be happened. Cause before creating the zip, I'm deleting all the zip files in that directory. After deleting the zip files,I run OZZipFile
functions. I know it's weird. But tbh, it's happening