iOS Objective-Zip corruption issues - ios

I am using flyingdolphinstudio's Objective-Zip which is an Objective-C zipping library. I am using this to zip a .txt file following the answer given in this question.
For my case, I do not have an array to cycle through so just for a single file I have the following:
ZipFile *zipFile= [[ZipFile alloc] initWithFileName:zip_file_name mode:ZipFileModeCreate];
NSDictionary *attributes = [[NSFileManager defaultManager]attributesOfItemAtPath:txt_file_name error:&error];
NSDate *Date = [attributes objectForKey:NSFileCreationDate];
NSData *filedata = [NSData dataWithContentsOfFile:txt_file_name];
ZipWriteStream *stream = [zipFile writeFileInZipWithName:txt_file_name fileDate:Date compressionLevel:ZipCompressionLevelBest];
[stream writeData:filedata];
[stream finishedWriting];
[zipFile close];
The zipping process seems to work, I get a .zip file with the correct name and a non-zero size. However, when I try and un-zip this on my mac, it runs into a .cpgz loop. And judging by this article, I presume its because my file is getting corrupted somewhere in there. Also when I upload it to a server and we try to open it on a linux machine, it spits it back out at us with the error:
$ unzip COCR2_100.zip
Archive: COCR2_100.zip
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
note: COCR2_100.zip may be a plain executable, not an archive
unzip: cannot find zipfile directory in one of COCR2_100.zip or
COCR2_100.zip.zip, and cannot find COCR2_100.zip.ZIP, period.
Which also suggests it is corrupted.
Does anybody have any ideas as to why it may be getting corrupted?
Thanks!

Solved this by switching to a different Zip client. Moved from Objective-Zip to ZipArchive and that seemed to work just fine.

Related

Access any file inside Zip File [duplicate]

I'm trying to port an existing Android application to iOS,
In the Android application i was using a ZipInputStream to extract a single file from the zip archive and store it in as a temporary file.
How could i extract a single file from a Zip Archive without having to extract the whole archive (As it is very large)?
I just found the answer,
I had to modify SSZipArchive to insert a method that will extract a single file from the ZIP archive (Based on its name)
You could find the modified version here, if someone finds this useful i might clean it up, add the delegate, the tests and propose for pull in SSZipArchive.
Usage is straightforward:
NSString *zipEntityToExtract = #"example.aac";
NSString *destinationFilePath = ...; //(Includes filename)
NSString *zipPath = ...;
[SSZipArchive unzipEntityName:zipEntityToExtract fromFilePath:zipPath toDestination:filePath];
//File is now in destinationFilePath

Unzipping a single file from Archive

I'm trying to port an existing Android application to iOS,
In the Android application i was using a ZipInputStream to extract a single file from the zip archive and store it in as a temporary file.
How could i extract a single file from a Zip Archive without having to extract the whole archive (As it is very large)?
I just found the answer,
I had to modify SSZipArchive to insert a method that will extract a single file from the ZIP archive (Based on its name)
You could find the modified version here, if someone finds this useful i might clean it up, add the delegate, the tests and propose for pull in SSZipArchive.
Usage is straightforward:
NSString *zipEntityToExtract = #"example.aac";
NSString *destinationFilePath = ...; //(Includes filename)
NSString *zipPath = ...;
[SSZipArchive unzipEntityName:zipEntityToExtract fromFilePath:zipPath toDestination:filePath];
//File is now in destinationFilePath

Compress CSV file with GZIP in xcode

I need to create a big table to csv file and compress it.
I can create the csv file like this: Xcode - Create csv/spreadsheet file
It is possible compress it with GZIP?
Thanks for all.
Best regards.
I recommend you use SSZipArchive: https://github.com/soffes/ssziparchive
Then you can do:
NSString *content = #"1,2,3"
NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:#"somefile.zip"];
SSZipArchive *zip = [[SSZipArchive alloc] initWithPath:path];
[zip open];
[zip writeData:[content dataUsingEncoding:NSUTF8StringEncoding] filename:#"data.csv"];
[zip close];
That will produce a zip file named "somefile.zip" in the temporary directory, containing one file inside named "data.csv"
The easiest way is to probably not use a standard copy build phase to move the file into place, but instead use shell script build phase to copy the file and then compress it in place with gzip.

Objective-Zip: Store content when unzip file (iOS)

I just want to create a file with the data of unzipped file in iOS.
I am using the Objective-Zip library, and I can zip files rightly.
Now, I am trying to extract the files of this zip file.
ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeUnzip];
//Checking files inside zip
NSArray *infos= [unzipFile listFileInZipInfos];
for (FileInZipInfo *info in infos)
NSLog(#"Test 1: - %# %# %d (%d)", info.name, info.date, info.size, info.level);
[unzipFile goToFirstFileInZip];
ZipReadStream *read= [unzipFile readCurrentFileInZipWithPassword:password];
How I can pass the ZipReadStream to a NSData object? Then I would convert NSData to the right file, is not?
Thanks in advance.
Sorry, it seems to be duplicate: unzip NSData using objective zip
Looking at the headers for the ZipReadStream class, it looks like there is a method readDataOfLength. It appears that you call that method repeatedly until you have all the data from the file. I would expect a method to find out the length of the unzipped file, but did not see such a method from a quick glance.
As a side-note, I've never heard of the Objective-Zip library until a few minutes ago, and I found the 'readDataOfLength:' method in less than a minute. Perhaps you should spend some time looking through the library's header and sample code?

Error while deleting the file

While deleting existing the file with this command:
[[NSFileManager defaultManager] removeItemAtPath:self.sourceFileName error:&error];
I got the following error
Error: ImageIO: CGImageReadCreateDataWithMappedFile 'open' failed '/Users/asdasd/Library/Application Support/iPhone Simulator/7.1/Applications/DD251D7D-F0AF-40E1-A033-F221623D589D/Library/ScanSession/Source/page3.jpeg
error = 2 (No such file or directory)'
This happens while I copied pic from album into app folder. The most interesting thing is that file exists, but not fully copied. Is there a way to check wether file is file operation completed?
check weather your file & Directory available
for (NSString *filename in files) {
NSString *path = [yourPath stringByAppendingPathComponent:yourFileName];
BOOL isDir;
if([[NSFileManager defaultManager] fileExistsAtPath:yourPath isDirectory:&isAvilDir] && isAvilDir){
NSLog(#"%# Check is a directory", your path file);
}
else {
NSLog (#"%# Check is a file",your path file);
}
}
I have a similar problem right now, and it seems as though when you delete a file that certain other methods you may have called immediately prior may actually not have completed yet. I'm considering delaying the actual deletion of files to allow for background processes to complete.
Solved it 2 yars ago. Forgot to post & close the question. It was caused by another thread, where the file was deleted first. I think its one of the standart mutlithreading issues while working with CoreData

Resources