Merge pull request #355 from Jnis/patch-2
Unzipping when no space; Stop unzipping when failed;
This commit is contained in:
@@ -20,6 +20,7 @@ typedef NS_ENUM(NSInteger, SSZipArchiveErrorCode) {
|
||||
SSZipArchiveErrorCodeFailedOpenFileInZip = -2,
|
||||
SSZipArchiveErrorCodeFileInfoNotLoadable = -3,
|
||||
SSZipArchiveErrorCodeFileContentNotReadable = -4,
|
||||
SSZipArchiveErrorCodeFailedToWriteFile = -5,
|
||||
};
|
||||
|
||||
@protocol SSZipArchiveDelegate;
|
||||
|
||||
@@ -383,7 +383,15 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
|
||||
FILE *fp = fopen((const char*)[fullPath fileSystemRepresentation], "wb");
|
||||
while (fp) {
|
||||
if (readBytes > 0) {
|
||||
fwrite(buffer, readBytes, 1, fp);
|
||||
if (0 == fwrite(buffer, readBytes, 1, fp)) {
|
||||
if (ferror(fp)) {
|
||||
NSString *message = [NSString stringWithFormat:@"Failed to write file (check your free space)"];
|
||||
NSLog(@"[SSZipArchive] %@", message);
|
||||
success = NO;
|
||||
*error = [NSError errorWithDomain:@"SSZipArchiveErrorDomain" code:SSZipArchiveErrorCodeFailedToWriteFile userInfo:@{NSLocalizedDescriptionKey: message}];
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@@ -515,7 +523,7 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
|
||||
progressHandler(strPath, fileInfo, currentFileNumber, globalInfo.number_entry);
|
||||
}
|
||||
}
|
||||
} while (ret == UNZ_OK && ret != UNZ_END_OF_LIST_OF_FILE);
|
||||
} while (ret == UNZ_OK && YES == success);
|
||||
|
||||
// Close
|
||||
unzClose(zip);
|
||||
|
||||
Reference in New Issue
Block a user