From 3d6408c154aae134913f7e654fcb9efd1bebba74 Mon Sep 17 00:00:00 2001 From: Dov Frankel Date: Tue, 2 Jul 2019 08:21:15 -0400 Subject: [PATCH 1/4] Removed deprecated extractData and writeData overloads (Issue #90) --- Source/UZKArchive.m | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Source/UZKArchive.m b/Source/UZKArchive.m index faf55c1..5129797 100644 --- a/Source/UZKArchive.m +++ b/Source/UZKArchive.m @@ -1025,16 +1025,6 @@ - (BOOL)writeData:(NSData *)data compressionMethod:(UZKCompressionMethod)method password:(NSString *)password overwrite:(BOOL)overwrite - error:(NSError * __autoreleasing*)error -{ - return [self writeData:data - filePath:filePath - fileDate:fileDate - posixPermissions:0 - compressionMethod:method - password:password - overwrite:overwrite - error:error]; } - (BOOL)writeData:(NSData *)data From 888f82d4a42a3276e5c9e19a3f15a1c12abc7598 Mon Sep 17 00:00:00 2001 From: Dov Frankel Date: Tue, 2 Jul 2019 16:32:18 -0400 Subject: [PATCH 2/4] Fixed accidental recursion --- Source/UZKArchive.m | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/UZKArchive.m b/Source/UZKArchive.m index 5129797..faf55c1 100644 --- a/Source/UZKArchive.m +++ b/Source/UZKArchive.m @@ -1025,6 +1025,16 @@ - (BOOL)writeData:(NSData *)data compressionMethod:(UZKCompressionMethod)method password:(NSString *)password overwrite:(BOOL)overwrite + error:(NSError * __autoreleasing*)error +{ + return [self writeData:data + filePath:filePath + fileDate:fileDate + posixPermissions:0 + compressionMethod:method + password:password + overwrite:overwrite + error:error]; } - (BOOL)writeData:(NSData *)data From c2b42b3b614c1d57906b8d73003b3df14b59bcae Mon Sep 17 00:00:00 2001 From: Dov Frankel Date: Tue, 2 Jul 2019 17:05:20 -0400 Subject: [PATCH 3/4] Fixed behavior that was causing progress within extraction of a single file to be lost (Issue #91) --- Source/UZKArchive.m | 5 +- Tests/ProgressReportingTests.m | 105 +++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) diff --git a/Source/UZKArchive.m b/Source/UZKArchive.m index faf55c1..44208c4 100644 --- a/Source/UZKArchive.m +++ b/Source/UZKArchive.m @@ -567,6 +567,8 @@ - (BOOL)extractFilesTo:(NSString *)destinationDirectory return; } + [progress becomeCurrentWithPendingUnitCount:info.uncompressedSize]; + UZKLogDebug("Extracting buffered data"); BOOL extractSuccess = [welf extractBufferedDataFromFile:info.filename error:&strongError @@ -576,6 +578,8 @@ - (BOOL)extractFilesTo:(NSString *)destinationDirectory bytesDecompressed += dataChunk.length; [deflatedFileHandle writeData:dataChunk]; }]; + + [progress resignCurrent]; UZKLogDebug("Closing file handle"); [deflatedFileHandle closeFile]; @@ -599,7 +603,6 @@ - (BOOL)extractFilesTo:(NSString *)destinationDirectory forKey:NSProgressFileCompletedCountKey]; [progress setUserInfoObject:@(fileInfo.count) forKey:NSProgressFileTotalCountKey]; - progress.completedUnitCount = bytesDecompressed; } } } diff --git a/Tests/ProgressReportingTests.m b/Tests/ProgressReportingTests.m index 4523470..87a0ba0 100644 --- a/Tests/ProgressReportingTests.m +++ b/Tests/ProgressReportingTests.m @@ -87,6 +87,111 @@ - (void)testProgressReporting_ExtractFiles_FractionCompleted } } +#if !TARGET_OS_IPHONE +- (void)testProgressReporting_ExtractFiles_FractionCompleted_LargeFile +{ + NSURL *largeTextFile = [self emptyTextFileOfLength:1000000]; + NSURL *testArchiveURL = [self archiveWithFiles:@[largeTextFile]]; + + NSString *extractDirectory = [self randomDirectoryWithPrefix:@"LargeFileProgress"]; + NSURL *extractURL = [self.tempDirectory URLByAppendingPathComponent:extractDirectory]; + + UZKArchive *archive = [[UZKArchive alloc] initWithURL:testArchiveURL error:nil]; + + NSProgress *extractFilesProgress = [NSProgress progressWithTotalUnitCount:1]; + [extractFilesProgress becomeCurrentWithPendingUnitCount:1]; + + NSString *observedSelector = NSStringFromSelector(@selector(fractionCompleted)); + + [extractFilesProgress addObserver:self + forKeyPath:observedSelector + options:NSKeyValueObservingOptionInitial + context:ExtractFilesContext]; + + NSError *extractError = nil; + BOOL success = [archive extractFilesTo:extractURL.path + overwrite:NO + error:&extractError]; + + XCTAssertNil(extractError, @"Error returned by extractFilesTo:overwrite:progress:error:"); + XCTAssertTrue(success, @"Archive failed to extract large file to %@", extractURL); + + [extractFilesProgress resignCurrent]; + [extractFilesProgress removeObserver:self forKeyPath:observedSelector]; + + XCTAssertEqualWithAccuracy(extractFilesProgress.fractionCompleted, 1.00, .0000000001, @"Progress never reported as completed"); + + NSUInteger expectedProgressUpdates = 5; + NSArray *expectedProgresses = @[@0, + @0.262144, + @0.524287, + @0.786431, + @1.0]; + + XCTAssertEqual(self.fractionsCompletedReported.count, expectedProgressUpdates, @"Incorrect number of progress updates"); + for (NSUInteger i = 0; i < expectedProgressUpdates; i++) { + float expectedProgress = expectedProgresses[i].floatValue; + float actualProgress = self.fractionsCompletedReported[i].floatValue; + + XCTAssertEqualWithAccuracy(actualProgress, expectedProgress, 0.00001f, @"Incorrect progress reported at index %ld", (long)i); + } +} + +- (void)testProgressReporting_ExtractFiles_FractionCompleted_TwoLargeFiles +{ + NSArray *largeTextFiles = @[ + [self emptyTextFileOfLength:1000000], + [self emptyTextFileOfLength:500000], + ]; + NSURL *testArchiveURL = [self archiveWithFiles:largeTextFiles]; + + NSString *extractDirectory = [self randomDirectoryWithPrefix:@"TwoLargeFilesProgress"]; + NSURL *extractURL = [self.tempDirectory URLByAppendingPathComponent:extractDirectory]; + + UZKArchive *archive = [[UZKArchive alloc] initWithURL:testArchiveURL error:nil]; + + NSProgress *extractFilesProgress = [NSProgress progressWithTotalUnitCount:1]; + [extractFilesProgress becomeCurrentWithPendingUnitCount:1]; + + NSString *observedSelector = NSStringFromSelector(@selector(fractionCompleted)); + + [extractFilesProgress addObserver:self + forKeyPath:observedSelector + options:NSKeyValueObservingOptionInitial + context:ExtractFilesContext]; + + NSError *extractError = nil; + BOOL success = [archive extractFilesTo:extractURL.path + overwrite:NO + error:&extractError]; + + XCTAssertNil(extractError, @"Error returned by extractFilesTo:overwrite:progress:error:"); + XCTAssertTrue(success, @"Archive failed to extract large file to %@", extractURL); + + [extractFilesProgress resignCurrent]; + [extractFilesProgress removeObserver:self forKeyPath:observedSelector]; + + XCTAssertEqualWithAccuracy(extractFilesProgress.fractionCompleted, 1.00, .0000000001, @"Progress never reported as completed"); + + NSUInteger expectedProgressUpdates = 7; + NSArray *expectedProgresses = @[@0, + @0.174762, + @0.349525, + @0.524287, + @0.666667, + @0.841429, + @1.0]; + + XCTAssertEqual(self.fractionsCompletedReported.count, expectedProgressUpdates, @"Incorrect number of progress updates"); + for (NSUInteger i = 0; i < expectedProgressUpdates; i++) { + float expectedProgress = expectedProgresses[i].floatValue; + float actualProgress = self.fractionsCompletedReported[i].floatValue; + + XCTAssertEqualWithAccuracy(actualProgress, expectedProgress, 0.00001f, @"Incorrect progress reported at index %ld", (long)i); + } +} +#endif + - (void)testProgressReporting_ExtractFiles_Description { NSString *testArchiveName = @"Test Archive.zip"; From f602fba27defa8e301c06f95cafa73a2926dab95 Mon Sep 17 00:00:00 2001 From: Dov Frankel Date: Tue, 2 Jul 2019 22:12:57 -0400 Subject: [PATCH 4/4] Updated change notes --- CHANGELOG.md | 1 + beta-notes.md | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67210bb..4a5e37e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 2.0 * Removed methods deprecated in v1.9 (Issue #90, PR #92) +* Fixed behavior of `-extractFilesTo:overwrite:error:`, so it shows the progress of each individual file as they extract (Issue #91, PR #94) ## 1.9 diff --git a/beta-notes.md b/beta-notes.md index dda93d3..1825edb 100644 --- a/beta-notes.md +++ b/beta-notes.md @@ -1 +1,2 @@ -* Removed methods deprecated in v1.9 (Issue #90, PR #92) \ No newline at end of file +* Removed methods deprecated in v1.9 (Issue #90, PR #92) +* Fixed behavior of `-extractFilesTo:overwrite:error:`, so it shows the progress of each individual file as they extract (Issue #91, PR #94) \ No newline at end of file