diff --git a/Classes/Objective_ZipViewController.m b/Classes/Objective_ZipViewController.m index 00df64b..3c30fd8 100644 --- a/Classes/Objective_ZipViewController.m +++ b/Classes/Objective_ZipViewController.m @@ -38,6 +38,9 @@ #import "../Objective-Zip/ZipWriteStream.h" #import "../Objective-Zip/ZipReadStream.h" +#define HUGE_TEST_BLOCK_LENGTH (63000) +#define HUGE_TEST_NUMBER_OF_BLOCKS (68149) + @implementation Objective_ZipViewController @@ -208,6 +211,8 @@ NSString *documentsDir= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; NSString *filePath= [documentsDir stringByAppendingPathComponent:@"huge_test.zip"]; + [[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL]; + [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 2: opening zip file for writing..." waitUntilDone:YES]; ZipFile *zipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeCreate]; @@ -218,22 +223,18 @@ [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]; + NSMutableData *data= [[NSMutableData alloc] initWithLength:HUGE_TEST_BLOCK_LENGTH]; + SecRandomCopyBytes(kSecRandomDefault, [data length], [data mutableBytes]); - NSData *bufferData= [buffer dataUsingEncoding:NSUTF8StringEncoding]; + NSData *checkData= [data subdataWithRange:NSMakeRange(0, 100)]; - NSMutableData *data= [[NSMutableData alloc] initWithLength:[buffer length]]; // For use later - NSData *lineData= [line dataUsingEncoding:NSUTF8StringEncoding]; // For use later + NSMutableData *buffer= [[NSMutableData alloc] initWithLength:HUGE_TEST_BLOCK_LENGTH]; // For use later - for (int i= 0; i < 100000; i++) { // 6300000000 bytes - [stream writeData:bufferData]; + for (int i= 0; i < HUGE_TEST_NUMBER_OF_BLOCKS; i++) { + [stream writeData:data]; if (i % 100 == 0) { - NSString *logLine= [[NSString alloc] initWithFormat:@"Test 2: written %d KB...", [line length] * (i +1)]; + NSString *logLine= [[NSString alloc] initWithFormat:@"Test 2: written %d KB...", ([data length] / 1024) * (i +1)]; [self performSelectorOnMainThread:@selector(log:) withObject:logLine waitUntilDone:YES]; [logLine release]; } @@ -259,24 +260,24 @@ [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]; + for (int i= 0; i < HUGE_TEST_NUMBER_OF_BLOCKS; i++) { + int bytesRead= [read readDataWithBuffer:buffer]; 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]) + if (bytesRead == [data length]) { + NSRange range= [buffer rangeOfData:checkData options:0 range:NSMakeRange(0, [buffer length])]; + if (range.location == 0) ok= YES; } if (!ok) { - NSString *logLine= [[NSString alloc] initWithFormat:@"Test 2: content of file is WRONG at position %d000", [line length] * i]; + NSString *logLine= [[NSString alloc] initWithFormat:@"Test 2: content of file is WRONG at position %d KB", ([buffer length] / 1024) * 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)]; + NSString *logLine= [[NSString alloc] initWithFormat:@"Test 2: read %d KB...", ([buffer length] / 1024) * (i +1)]; [self performSelectorOnMainThread:@selector(log:) withObject:logLine waitUntilDone:YES]; [logLine release]; } @@ -297,8 +298,8 @@ [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 2: test terminated succesfully" waitUntilDone:YES]; - [buffer release]; [data release]; + [buffer release]; } @catch (ZipException *ze) { [self performSelectorOnMainThread:@selector(log:) withObject:@"Test 2: caught a ZipException (see logs), terminating..." waitUntilDone:YES]; diff --git a/Objective_ZipViewController.xib b/Objective_ZipViewController.xib index 3ccce70..033fcc9 100644 --- a/Objective_ZipViewController.xib +++ b/Objective_ZipViewController.xib @@ -109,7 +109,7 @@ 0 0 1 - 6.3 GB Zip & Unzip (use with caution) + 4 GB Zip & Unzip (use with caution) 1 diff --git a/Objective_Zip_Prefix.pch b/Objective_Zip_Prefix.pch index 87a5d2b..cbd3029 100644 --- a/Objective_Zip_Prefix.pch +++ b/Objective_Zip_Prefix.pch @@ -5,4 +5,5 @@ #ifdef __OBJC__ #import #import + #import #endif