Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion Source/UZKArchive.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -576,6 +578,8 @@ - (BOOL)extractFilesTo:(NSString *)destinationDirectory
bytesDecompressed += dataChunk.length;
[deflatedFileHandle writeData:dataChunk];
}];

[progress resignCurrent];

UZKLogDebug("Closing file handle");
[deflatedFileHandle closeFile];
Expand All @@ -599,7 +603,6 @@ - (BOOL)extractFilesTo:(NSString *)destinationDirectory
forKey:NSProgressFileCompletedCountKey];
[progress setUserInfoObject:@(fileInfo.count)
forKey:NSProgressFileTotalCountKey];
progress.completedUnitCount = bytesDecompressed;
}
}
}
Expand Down
105 changes: 105 additions & 0 deletions Tests/ProgressReportingTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSNumber *> *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<NSURL*> *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<NSNumber *> *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";
Expand Down
3 changes: 2 additions & 1 deletion beta-notes.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* Removed methods deprecated in v1.9 (Issue #90, PR #92)
* 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)