Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error opening file in zipfile #73

Open
mjm918 opened this issue Nov 13, 2018 · 4 comments
Open

Error opening file in zipfile #73

mjm918 opened this issue Nov 13, 2018 · 4 comments

Comments

@mjm918
Copy link

mjm918 commented Nov 13, 2018

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

@mjm918 mjm918 changed the title Error opening 'log.sqlite3' in zipfile Error opening file in zipfile Nov 13, 2018
@gianlucabertani
Copy link
Owner

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?

@mjm918
Copy link
Author

mjm918 commented Nov 19, 2018

@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.

@gianlucabertani
Copy link
Owner

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.

@mjm918
Copy link
Author

mjm918 commented Nov 22, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants