diff --git a/Classes/Objective_ZipViewController.h b/Classes/Objective_ZipViewController.h index 496c5d8..9a9bb50 100644 --- a/Classes/Objective_ZipViewController.h +++ b/Classes/Objective_ZipViewController.h @@ -41,8 +41,10 @@ } - (IBAction) zipUnzip; +- (IBAction) zipUnzip2; - (void) test; +- (void) test2; - (void) log:(NSString *)text; @end diff --git a/Classes/Objective_ZipViewController.m b/Classes/Objective_ZipViewController.m index a6fc23d..00df64b 100644 --- a/Classes/Objective_ZipViewController.m +++ b/Classes/Objective_ZipViewController.m @@ -66,6 +66,14 @@ [_testThread start]; } +- (IBAction) zipUnzip2 { + if (_testThread) + [_testThread release]; + + _testThread= [[NSThread alloc] initWithTarget:self selector:@selector(test2) object:nil]; + [_testThread start]; +} + - (void) test { NSAutoreleasePool *pool= [[NSAutoreleasePool alloc] init]; @@ -73,59 +81,59 @@ NSString *documentsDir= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; NSString *filePath= [documentsDir stringByAppendingPathComponent:@"test.zip"]; - [self performSelectorOnMainThread:@selector(log:) withObject:@"Opening zip file for writing..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: opening zip file for writing..." waitUntilDone:YES]; ZipFile *zipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeCreate]; - [self performSelectorOnMainThread:@selector(log:) withObject:@"Adding first file..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: adding first file..." waitUntilDone:YES]; ZipWriteStream *stream1= [zipFile writeFileInZipWithName:@"abc.txt" fileDate:[NSDate dateWithTimeIntervalSinceNow:-86400.0] compressionLevel:ZipCompressionLevelBest]; - [self performSelectorOnMainThread:@selector(log:) withObject:@"Writing to first file's stream..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: writing to first file's stream..." waitUntilDone:YES]; NSString *text= @"abc"; [stream1 writeData:[text dataUsingEncoding:NSUTF8StringEncoding]]; - [self performSelectorOnMainThread:@selector(log:) withObject:@"Closing first file's stream..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: closing first file's stream..." waitUntilDone:YES]; [stream1 finishedWriting]; - [self performSelectorOnMainThread:@selector(log:) withObject:@"Adding second file..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: adding second file..." waitUntilDone:YES]; ZipWriteStream *stream2= [zipFile writeFileInZipWithName:@"x/y/z/xyz.txt" compressionLevel:ZipCompressionLevelNone]; - [self performSelectorOnMainThread:@selector(log:) withObject:@"Writing to second file's stream..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: writing to second file's stream..." waitUntilDone:YES]; NSString *text2= @"XYZ"; [stream2 writeData:[text2 dataUsingEncoding:NSUTF8StringEncoding]]; - [self performSelectorOnMainThread:@selector(log:) withObject:@"Closing second file's stream..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: closing second file's stream..." waitUntilDone:YES]; [stream2 finishedWriting]; - [self performSelectorOnMainThread:@selector(log:) withObject:@"Closing zip file..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: closing zip file..." waitUntilDone:YES]; [zipFile close]; [zipFile release]; - [self performSelectorOnMainThread:@selector(log:) withObject:@"Opening zip file for reading..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: opening zip file for reading..." waitUntilDone:YES]; ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeUnzip]; - [self performSelectorOnMainThread:@selector(log:) withObject:@"Reading file infos..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: reading file infos..." waitUntilDone:YES]; NSArray *infos= [unzipFile listFileInZipInfos]; for (FileInZipInfo *info in infos) { - NSString *fileInfo= [NSString stringWithFormat:@"- %@ %@ %d (%d)", info.name, info.date, info.size, info.level]; + NSString *fileInfo= [NSString stringWithFormat:@"Test 1: - %@ %@ %d (%d)", info.name, info.date, info.size, info.level]; [self performSelectorOnMainThread:@selector(log:) withObject:fileInfo waitUntilDone:YES]; } - [self performSelectorOnMainThread:@selector(log:) withObject:@"Opening first file..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: opening first file..." waitUntilDone:YES]; [unzipFile goToFirstFileInZip]; ZipReadStream *read1= [unzipFile readCurrentFileInZip]; - [self performSelectorOnMainThread:@selector(log:) withObject:@"Reading from first file's stream..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: reading from first file's stream..." waitUntilDone:YES]; NSMutableData *data1= [[[NSMutableData alloc] initWithLength:256] autorelease]; int bytesRead1= [read1 readDataWithBuffer:data1]; @@ -138,20 +146,20 @@ } if (ok) - [self performSelectorOnMainThread:@selector(log:) withObject:@"Content of first file is OK" waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: content of first file is OK" waitUntilDone:YES]; else - [self performSelectorOnMainThread:@selector(log:) withObject:@"Content of first file is WRONG" waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: content of first file is WRONG" waitUntilDone:YES]; - [self performSelectorOnMainThread:@selector(log:) withObject:@"Closing first file's stream..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: closing first file's stream..." waitUntilDone:YES]; [read1 finishedReading]; - [self performSelectorOnMainThread:@selector(log:) withObject:@"Opening second file..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: opening second file..." waitUntilDone:YES]; [unzipFile goToNextFileInZip]; ZipReadStream *read2= [unzipFile readCurrentFileInZip]; - [self performSelectorOnMainThread:@selector(log:) withObject:@"Reading from second file's stream..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: reading from second file's stream..." waitUntilDone:YES]; NSMutableData *data2= [[[NSMutableData alloc] initWithLength:256] autorelease]; int bytesRead2= [read2 readDataWithBuffer:data2]; @@ -164,30 +172,143 @@ } if (ok) - [self performSelectorOnMainThread:@selector(log:) withObject:@"Content of second file is OK" waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: content of second file is OK" waitUntilDone:YES]; else - [self performSelectorOnMainThread:@selector(log:) withObject:@"Content of second file is WRONG" waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: content of second file is WRONG" waitUntilDone:YES]; - [self performSelectorOnMainThread:@selector(log:) withObject:@"Closing second file's stream..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: closing second file's stream..." waitUntilDone:YES]; [read2 finishedReading]; - [self performSelectorOnMainThread:@selector(log:) withObject:@"Closing zip file..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: closing zip file..." waitUntilDone:YES]; [unzipFile close]; [unzipFile release]; - [self performSelectorOnMainThread:@selector(log:) withObject:@"Test terminated succesfully" waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: test terminated succesfully" waitUntilDone:YES]; } @catch (ZipException *ze) { - [self performSelectorOnMainThread:@selector(log:) withObject:@"Caught a ZipException (see logs), terminating..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: caught a ZipException (see logs), terminating..." waitUntilDone:YES]; - NSLog(@"ZipException caught: %d - %@", ze.error, [ze reason]); + NSLog(@"Test 1: ZipException caught: %d - %@", ze.error, [ze reason]); } @catch (id e) { - [self performSelectorOnMainThread:@selector(log:) withObject:@"Caught a generic exception (see logs), terminating..." waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 1: caught a generic exception (see logs), terminating..." waitUntilDone:YES]; - NSLog(@"Exception caught: %@ - %@", [[e class] description], [e description]); + NSLog(@"Test 1: Exception caught: %@ - %@", [[e class] description], [e description]); + } + + [pool drain]; +} + +- (void) test2 { + NSAutoreleasePool *pool= [[NSAutoreleasePool alloc] init]; + + @try { + NSString *documentsDir= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; + NSString *filePath= [documentsDir stringByAppendingPathComponent:@"huge_test.zip"]; + + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 2: opening zip file for writing..." waitUntilDone:YES]; + + ZipFile *zipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeCreate]; + + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 2: adding file..." waitUntilDone:YES]; + + ZipWriteStream *stream= [zipFile writeFileInZipWithName:@"huge_file.txt" compressionLevel:ZipCompressionLevelBest]; + + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 2: writing to file's stream..." waitUntilDone:YES]; + + NSString *line= @"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; // 63 bytes + + NSMutableString *buffer= [[NSMutableString alloc] init]; // 63000 bytes + for (int i= 0; i < 1000; i++) + [buffer appendString:line]; + + NSData *bufferData= [buffer dataUsingEncoding:NSUTF8StringEncoding]; + + NSMutableData *data= [[NSMutableData alloc] initWithLength:[buffer length]]; // For use later + NSData *lineData= [line dataUsingEncoding:NSUTF8StringEncoding]; // For use later + + for (int i= 0; i < 100000; i++) { // 6300000000 bytes + [stream writeData:bufferData]; + + if (i % 100 == 0) { + NSString *logLine= [[NSString alloc] initWithFormat:@"Test 2: written %d KB...", [line length] * (i +1)]; + [self performSelectorOnMainThread:@selector(log:) withObject:logLine waitUntilDone:YES]; + [logLine release]; + } + } + + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 2: closing file's stream..." waitUntilDone:YES]; + + [stream finishedWriting]; + + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 2: closing zip file..." waitUntilDone:YES]; + + [zipFile close]; + [zipFile release]; + + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 2: opening zip file for reading..." waitUntilDone:YES]; + + ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeUnzip]; + + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 2: opening file..." waitUntilDone:YES]; + + [unzipFile goToFirstFileInZip]; + ZipReadStream *read= [unzipFile readCurrentFileInZip]; + + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 2: reading from file's stream..." waitUntilDone:YES]; + + for (int i= 0; i < 100000; i++) { + int bytesRead= [read readDataWithBuffer:data]; + + BOOL ok= NO; + if (bytesRead == [buffer length]) { + NSRange range= [data rangeOfData:lineData options:NSDataSearchBackwards range:NSMakeRange(0, [buffer length])]; + if (range.location == [buffer length] - [line length]) + ok= YES; + } + + if (!ok) { + NSString *logLine= [[NSString alloc] initWithFormat:@"Test 2: content of file is WRONG at position %d000", [line length] * i]; + [self performSelectorOnMainThread:@selector(log:) withObject:logLine waitUntilDone:YES]; + [logLine release]; + } + + if (i % 100 == 0) { + NSString *logLine= [[NSString alloc] initWithFormat:@"Test 2: read %d KB...", [line length] * (i +1)]; + [self performSelectorOnMainThread:@selector(log:) withObject:logLine waitUntilDone:YES]; + [logLine release]; + } + } + + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 2: closing file's stream..." waitUntilDone:YES]; + + [read finishedReading]; + + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 2: closing zip file..." waitUntilDone:YES]; + + [unzipFile close]; + [unzipFile release]; + + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 2: deleting zip file..." waitUntilDone:YES]; + + [[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL]; + + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 2: test terminated succesfully" waitUntilDone:YES]; + + [buffer release]; + [data release]; + + } @catch (ZipException *ze) { + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 2: caught a ZipException (see logs), terminating..." waitUntilDone:YES]; + + NSLog(@"Test 2: ZipException caught: %d - %@", ze.error, [ze reason]); + + } @catch (id e) { + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 2: caught a generic exception (see logs), terminating..." waitUntilDone:YES]; + + NSLog(@"Test 2: Exception caught: %@ - %@", [[e class] description], [e description]); } [pool drain]; diff --git a/Objective_ZipViewController.xib b/Objective_ZipViewController.xib index 5c4dcb7..3ccce70 100644 --- a/Objective_ZipViewController.xib +++ b/Objective_ZipViewController.xib @@ -1,39 +1,40 @@ - 784 - 10C540 - 740 - 1038.25 - 458.00 + 1552 + 12E55 + 3084 + 1187.39 + 626.00 com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 62 + 2083 - + YES - + IBProxyObject + IBUIButton + IBUIImageView + IBUITextView + IBUIView YES com.apple.InterfaceBuilder.IBCocoaTouchPlugin - YES - - YES - - - YES - + PluginDependencyRecalculationVersion + YES IBFilesOwner + IBCocoaTouchFramework IBFirstResponder + IBCocoaTouchFramework @@ -45,10 +46,13 @@ 292 {{0, -20}, {320, 480}} + + NO NO 4 NO + IBCocoaTouchFramework NSImage Default.png @@ -59,15 +63,13 @@ 292 {{20, 20}, {280, 37}} + + NO NO + IBCocoaTouchFramework 0 0 - - Helvetica-Bold - 15 - 16 - 1 Zip & Unzip @@ -78,31 +80,71 @@ 1 MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA - + 3 MC41AA + + Helvetica-Bold + Helvetica + 2 + 15 + + + Helvetica-Bold + 15 + 16 + + + + + 292 + {{20, 64}, {280, 37}} + + + + NO + NO + IBCocoaTouchFramework + 0 + 0 + 1 + 6.3 GB Zip & Unzip (use with caution) + + + 1 + MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA + + + + 292 - {{20, 65}, {280, 375}} + {{20, 108}, {280, 332}} + + 3 MAA NO 0.5 + IBCocoaTouchFramework 274 - {{20, 65}, {280, 375}} + {{20, 108}, {280, 332}} + + NO YES YES + IBCocoaTouchFramework NO NO NO @@ -110,11 +152,24 @@ NO - + + IBCocoaTouchFramework + + + 1 + 17 + + + Helvetica + 17 + 16 + - {320, 460} + {{0, 20}, {320, 460}} + + 3 MC43NQA @@ -124,6 +179,7 @@ NO + IBCocoaTouchFramework @@ -154,13 +210,24 @@ 14 + + + zipUnzip2 + + + 7 + + 17 + YES 0 - + + YES + @@ -184,6 +251,7 @@ + @@ -210,6 +278,11 @@ + + 15 + + + @@ -217,21 +290,25 @@ YES -1.CustomClassName + -1.IBPluginDependency -2.CustomClassName + -2.IBPluginDependency 10.IBPluginDependency 13.IBPluginDependency - 6.IBEditorWindowLastContentRect + 15.IBPluginDependency 6.IBPluginDependency 8.IBPluginDependency 9.IBPluginDependency - + YES Objective_ZipViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin UIResponder com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin - {{731, 409}, {320, 480}} + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -240,20 +317,16 @@ YES - - YES - + YES - - YES - + - 14 + 17 @@ -262,248 +335,67 @@ Objective_ZipViewController UIViewController - zipUnzip - id + YES + + YES + zipUnzip + zipUnzip2 + + + YES + id + id + + + + YES + + YES + zipUnzip + zipUnzip2 + + + YES + + zipUnzip + id + + + zipUnzip2 + id + + _textView UITextView + + _textView + + _textView + UITextView + + IBProjectSource - Classes/Objective_ZipViewController.h - - - - - YES - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSError.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSFileManager.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSKeyValueCoding.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSKeyValueObserving.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSKeyedArchiver.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSNetServices.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSObject.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSPort.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSRunLoop.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSStream.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSThread.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSURL.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSURLConnection.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSXMLParser.h - - - - NSObject - - IBFrameworkSource - UIKit.framework/Headers/UIAccessibility.h - - - - NSObject - - IBFrameworkSource - UIKit.framework/Headers/UINibLoading.h - - - - NSObject - - IBFrameworkSource - UIKit.framework/Headers/UIResponder.h - - - - UIButton - UIControl - - IBFrameworkSource - UIKit.framework/Headers/UIButton.h - - - - UIControl - UIView - - IBFrameworkSource - UIKit.framework/Headers/UIControl.h - - - - UIImageView - UIView - - IBFrameworkSource - UIKit.framework/Headers/UIImageView.h - - - - UIResponder - NSObject - - - - UIScrollView - UIView - - IBFrameworkSource - UIKit.framework/Headers/UIScrollView.h - - - - UISearchBar - UIView - - IBFrameworkSource - UIKit.framework/Headers/UISearchBar.h - - - - UISearchDisplayController - NSObject - - IBFrameworkSource - UIKit.framework/Headers/UISearchDisplayController.h - - - - UITextView - UIScrollView - - IBFrameworkSource - UIKit.framework/Headers/UITextView.h - - - - UIView - - IBFrameworkSource - UIKit.framework/Headers/UITextField.h - - - - UIView - UIResponder - - IBFrameworkSource - UIKit.framework/Headers/UIView.h - - - - UIViewController - - IBFrameworkSource - UIKit.framework/Headers/UINavigationController.h - - - - UIViewController - - IBFrameworkSource - UIKit.framework/Headers/UITabBarController.h - - - - UIViewController - UIResponder - - IBFrameworkSource - UIKit.framework/Headers/UIViewController.h + ./Classes/Objective_ZipViewController.h 0 + IBCocoaTouchFramework com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 YES - Objective-Zip.xcodeproj 3 - 3.1 + + Default.png + {320, 480} + + 2083