Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
db8b8b0
Added ZipWriteArgs class in Swift
abbeycode Aug 1, 2019
c72cf40
Updated UZKArchive to use ZipWriteArgs and deprecate the old methods …
abbeycode Aug 1, 2019
be57807
Updated CRC fields and variables to use uLong (unsigned long) consist…
abbeycode Aug 2, 2019
17b33a4
Trying to fix unit tests
abbeycode Aug 2, 2019
41be9ff
Upgraded platform targets to latest iOS and macOS releases
abbeycode Aug 6, 2019
6051b13
Updated demo project and podspec
abbeycode Aug 6, 2019
57d527c
Fixed check for existing files
abbeycode Aug 12, 2019
ff7aeba
Fixed bug causing invalid CRCs (no CRCs) to get written to archived f…
abbeycode Aug 10, 2019
8ae0636
Updated Travis build to validate the CocoaPod lib as both a static li…
abbeycode Aug 12, 2019
cddcd7f
Renamed 'ZipWriteArgs' to 'ZipFileProperties'
abbeycode Aug 12, 2019
8183cd0
Reverted change to Podspec
abbeycode Aug 12, 2019
93729d7
Made copies of all test cases using now-deprecated methods to have co…
abbeycode Aug 12, 2019
55a3dab
Updated syntax for deprecated overloads' property assignments to use …
abbeycode Aug 12, 2019
3aec486
Replaced '#import' with '@import' in Obj-C test cases that use ZipFil…
abbeycode Aug 13, 2019
bbf2afc
Replaced remaining '#import UnzipKit' with '@import' in unit tests, d…
abbeycode Aug 13, 2019
bfd55e9
Fixed Swift import for static library builds
abbeycode Aug 19, 2019
a90c3f9
Tweaked Swift import header generator script
abbeycode Aug 20, 2019
a247625
Updated README
abbeycode Aug 20, 2019
594bcc1
Added -testIsPasswordProtected_PasswordRequired_LastFileOnly_deprecat…
abbeycode Aug 20, 2019
b6bfb81
Added comment to remind myself why this check is done this way
abbeycode Aug 20, 2019
83fe505
Fixed indentation
abbeycode Aug 20, 2019
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ build
**/xcuserdata/*
analyzer-output/**

# Generated by a Run Script build phase
Source/GeneratedSwiftImport.h

UnzipKitDemo/Pods/*
UnzipKitDemo/Podfile.lock
UnzipKitDemo/Carthage/*
Expand Down
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ matrix:
script: ./Scripts/install-demo-libs.sh && xcodebuild -workspace UnzipKitDemo/UnzipKitDemo.xcworkspace -scheme UnzipKitDemo -destination 'platform=iOS Simulator,name=iPhone 7,OS=latest' -configuration Release analyze test ENABLE_NS_ASSERTIONS=1 CLANG_ANALYZER_OUTPUT=html CLANG_ANALYZER_OUTPUT_DIR=analyzer-output && [[ -z `find analyzer-output -name "*.html"` ]]

- stage: Validate
env: Name=CocoaPods
env: Name=CocoaPods-Framework
script: ./Scripts/cocoapod-validate.sh

- stage: Validate
env: Name=CocoaPods-Static-Lib
script: ./Scripts/cocoapod-validate.sh --use-libraries

- stage: Validate
env: Name=Carthage
script: ./Scripts/carthage-validate.sh
Expand Down
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ You can also modify Zip archives:
* Write data as a stream to the archive (from disk or over the network), using a block:

```Objective-C
BOOL success = [archive writeIntoBuffer:@"dir/filename.png"
error:&error
block:
BOOL success = [archive writeIntoBufferAtPath:@"dir/filename.png"
error:&error
block:
^BOOL(BOOL(^writeData)(const void *bytes, unsigned int length), NSError**(actionError)) {
for (NSUInteger i = 0; i <= someFile.length; i += bufferSize) {
const void *bytes = // some data
Expand Down Expand Up @@ -139,9 +139,7 @@ The following methods support `NSProgress` and `NSProgressReporting`:
* `performOnDataInArchive:error:`
* `extractBufferedDataFromFile:error:action:`
* `writeData:filePath:error:`*
* `writeData:filePath:fileDate:error:`*
* `writeData:filePath:fileDate:compressionMethod:password:error:`*
* `writeData:filePath:fileDate:compressionMethod:password:overwrite:error:`*
* `writeData:props:error:`*

_* the `writeData...` methods don't support cancellation like the read-only methods do

Expand Down Expand Up @@ -203,7 +201,7 @@ If you don't have a hierarchy of `NSProgress` instances, or if you want to obser

Using either method above, you can call `[progress cancel]` to stop the operation in progress. It will cause the operation to fail, returning `nil` or `NO` (depending on the return type, and give an error with error code `UZKErrorCodeUserCancelled`.

Note: Cancellation is only supported on extraction methods, not write methods.
_Note: Cancellation is only supported on extraction methods, not write methods.__


# Documentation
Expand Down
2 changes: 1 addition & 1 deletion Scripts/cocoapod-validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ pod env

# Using sed to remove logging from output until CocoaPods issue #7577 is implemented and I can use the
# OS_ACTIVITY_MODE = disable environment variable from the test spec scheme
pod lib lint --verbose | sed -l '/xctest\[/d; /^$/d'
pod lib lint --verbose "$@" | sed -l '/xctest\[/d; /^$/d'

. Scripts/unset-travis-tag.sh
34 changes: 34 additions & 0 deletions Scripts/generate-swift-import-header.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

# Different styles of import statement need to be used for the Swift generated header,
# depending on the target type (static library or dynamic framework). This script reads
# the PACKAGE_TYPE environment variable Xcode sets to create the correct one at build
# time, allowing the library to be built as either type from CocoaPods

# static library: com.apple.product-type.library.static
# dynamic framework: com.apple.package-type.wrapper.framework
[[ "${PACKAGE_TYPE}" = "com.apple.package-type.wrapper.framework" ]] \
&& SWIFTIMPORT="<${PRODUCT_MODULE_NAME}/${PRODUCT_MODULE_NAME}-Swift.h>" \
|| SWIFTIMPORT="\"${PRODUCT_MODULE_NAME}-Swift.h\""

if [ -z "$PODS_TARGET_SRCROOT" ]; then
PODS_TARGET_SRCROOT=${SOURCE_ROOT}
echo "Building in Xcode instead of CocoaPods. Overriding PODS_TARGET_SRCROOT with SOURCE_ROOT"
fi

IMPORT_TEXT=\
"/**
*
* This header was generated by a Run Script build phase. See
* Scripts/generate-swift-import-header.sh for more information
*
*/

#ifndef GeneratedSwiftImport_h
#define GeneratedSwiftImport_h

#import ${SWIFTIMPORT}

#endif /* GeneratedSwiftImport_h */
"
echo "$IMPORT_TEXT" > ${PODS_TARGET_SRCROOT}/Source/GeneratedSwiftImport.h
91 changes: 70 additions & 21 deletions Source/UZKArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#import "UZKFileInfo.h"

@class ZipFileProperties;

/**
* Defines the various error codes that the listing and extraction methods return.
* These are returned in NSError's [code]([NSError code]) field.
Expand Down Expand Up @@ -406,7 +408,22 @@ extern NSString *UZKErrorDomain;
error:(NSError **)error;

/**
* Writes the data to the zip file, overwriting it if a file of that name already exists in the archive
* Writes the data to the zip file, overwriting it if a file of that name already exists
* in the archive. Supports NSProgress for progress reporting, which DOES NOT allow cancellation
* in the middle of writing
*
* @param data Data to write into the archive
* @param props Specifies the properties of the file being archived
* @param error Contains an NSError object when there was an error writing to the archive
*
* @return YES if successful, NO on error
*/
- (BOOL)writeData:(NSData *)data
props:(ZipFileProperties *)props
error:(NSError **)error;

/**
* DEPRECATED: Writes the data to the zip file, overwriting it if a file of that name already exists in the archive
*
* @param data Data to write into the archive
* @param filePath The full path to the target file in the archive
Expand All @@ -418,10 +435,11 @@ extern NSString *UZKErrorDomain;
- (BOOL)writeData:(NSData *)data
filePath:(NSString *)filePath
fileDate:(nullable NSDate *)fileDate
error:(NSError **)error;
error:(NSError **)error
__deprecated_msg("Use -writeData:props:error: instead");

/**
* Writes the data to the zip file, overwriting it if a file of that name already exists in the archive
* DEPRECATED: Writes the data to the zip file, overwriting it if a file of that name already exists in the archive
*
* @param data Data to write into the archive
* @param filePath The full path to the target file in the archive
Expand All @@ -437,10 +455,11 @@ extern NSString *UZKErrorDomain;
fileDate:(nullable NSDate *)fileDate
compressionMethod:(UZKCompressionMethod)method
password:(nullable NSString *)password
error:(NSError **)error;
error:(NSError **)error
__deprecated_msg("Use -writeData:props:error: instead");

/**
* Writes the data to the zip file, overwriting only if specified with the overwrite flag. Overwriting
* DEPRECATED: Writes the data to the zip file, overwriting only if specified with the overwrite flag. Overwriting
* presents a tradeoff: the whole archive needs to be copied (minus the file to be overwritten) before
* the write begins. For a large archive, this can be slow. On the other hand, when not overwriting,
* the size of the archive will grow each time the file is written.
Expand All @@ -463,10 +482,11 @@ compressionMethod:(UZKCompressionMethod)method
compressionMethod:(UZKCompressionMethod)method
password:(nullable NSString *)password
overwrite:(BOOL)overwrite
error:(NSError **)error;
error:(NSError **)error
__deprecated_msg("Use -writeData:props:error: instead");

/**
* Writes the data to the zip file, overwriting only if specified with the overwrite flag. Overwriting
* DEPRECATED: Writes the data to the zip file, overwriting only if specified with the overwrite flag. Overwriting
* presents a tradeoff: the whole archive needs to be copied (minus the file to be overwritten) before
* the write begins. For a large archive, this can be slow. On the other hand, when not overwriting,
* the size of the archive will grow each time the file is written.
Expand All @@ -491,7 +511,8 @@ compressionMethod:(UZKCompressionMethod)method
compressionMethod:(UZKCompressionMethod)method
password:(nullable NSString *)password
overwrite:(BOOL)overwrite
error:(NSError **)error;
error:(NSError **)error
__deprecated_msg("Use -writeData:props:error: instead");

/**
* Writes data to the zip file in pieces, allowing you to stream the write, so the entire contents
Expand All @@ -511,12 +532,34 @@ compressionMethod:(UZKCompressionMethod)method
*
* @return YES if successful, NO on error
*/
- (BOOL)writeIntoBuffer:(NSString *)filePath
- (BOOL)writeIntoBufferAtPath:(NSString *)filePath
error:(NSError **)error
block:(BOOL(^)(BOOL(^writeData)(const void *bytes, unsigned int length), NSError **actionError))action;

/**
* Writes data to the zip file in pieces, allowing you to stream the write, so the entire contents
* don't need to reside in memory at once. It overwrites an existing file with the same name.
*
* @param props Specifies the properties of the file being archived
* @param error Contains an NSError object when there was an error writing to the archive
* @param action Contains your code to loop through the source bytes and write them to the
* archive. Each time a chunk of data is ready to be written, call writeData,
* passing in a pointer to the bytes and their length. Return YES if successful,
* or NO on error (in which case, you should assign the actionError parameter
*
* - *writeData* Call this block to write some bytes into the archive. It returns NO if the
* write failed. If this happens, you should return from the action block, and
* handle the NSError returned into the error reference
* - *actionError* Assign to an NSError instance before returning NO
*
* @return YES if successful, NO on error
*/
- (BOOL)writeIntoBuffer:(ZipFileProperties *)props
error:(NSError **)error
block:(BOOL(^)(BOOL(^writeData)(const void *bytes, unsigned int length), NSError **actionError))action;

/**
* Writes data to the zip file in pieces, allowing you to stream the write, so the entire contents
* DEPRECATED: Writes data to the zip file in pieces, allowing you to stream the write, so the entire contents
* don't need to reside in memory at once. It overwrites an existing file with the same name.
*
* @param filePath The full path to the target file in the archive
Expand All @@ -537,10 +580,11 @@ compressionMethod:(UZKCompressionMethod)method
- (BOOL)writeIntoBuffer:(NSString *)filePath
fileDate:(nullable NSDate *)fileDate
error:(NSError **)error
block:(BOOL(^)(BOOL(^writeData)(const void *bytes, unsigned int length), NSError **actionError))action;
block:(BOOL(^)(BOOL(^writeData)(const void *bytes, unsigned int length), NSError **actionError))action
__deprecated_msg("Use -writeIntoBuffer:props:error:block: instead");

/**
* Writes data to the zip file in pieces, allowing you to stream the write, so the entire contents
* DEPRECATED: Writes data to the zip file in pieces, allowing you to stream the write, so the entire contents
* don't need to reside in memory at once. It overwrites an existing file with the same name.
*
* @param filePath The full path to the target file in the archive
Expand All @@ -563,10 +607,11 @@ compressionMethod:(UZKCompressionMethod)method
fileDate:(nullable NSDate *)fileDate
compressionMethod:(UZKCompressionMethod)method
error:(NSError **)error
block:(BOOL(^)(BOOL(^writeData)(const void *bytes, unsigned int length), NSError **actionError))action;
block:(BOOL(^)(BOOL(^writeData)(const void *bytes, unsigned int length), NSError **actionError))action
__deprecated_msg("Use -writeIntoBuffer:props:error:block: instead");

/**
* Writes data to the zip file in pieces, allowing you to stream the write, so the entire contents
* DEPRECATED: Writes data to the zip file in pieces, allowing you to stream the write, so the entire contents
* don't need to reside in memory at once. It overwrites an existing file with the same name, only if
* specified with the overwrite flag. Overwriting presents a tradeoff: the whole archive needs to be
* copied (minus the file to be overwritten) before the write begins. For a large archive, this can
Expand Down Expand Up @@ -597,10 +642,11 @@ compressionMethod:(UZKCompressionMethod)method
compressionMethod:(UZKCompressionMethod)method
overwrite:(BOOL)overwrite
error:(NSError **)error
block:(BOOL(^)(BOOL(^writeData)(const void *bytes, unsigned int length), NSError **actionError))action;
block:(BOOL(^)(BOOL(^writeData)(const void *bytes, unsigned int length), NSError **actionError))action
__deprecated_msg("Use -writeIntoBuffer:props:error:block: instead");

/**
* Writes data to the zip file in pieces, allowing you to stream the write, so the entire contents
* DEPRECATED: Writes data to the zip file in pieces, allowing you to stream the write, so the entire contents
* don't need to reside in memory at once. It overwrites an existing file with the same name, only if
* specified with the overwrite flag. Overwriting presents a tradeoff: the whole archive needs to be
* copied (minus the file to be overwritten) before the write begins. For a large archive, this can
Expand Down Expand Up @@ -634,10 +680,11 @@ compressionMethod:(UZKCompressionMethod)method
overwrite:(BOOL)overwrite
CRC:(unsigned long)preCRC
error:(NSError **)error
block:(BOOL(^)(BOOL(^writeData)(const void *bytes, unsigned int length), NSError **actionError))action;
block:(BOOL(^)(BOOL(^writeData)(const void *bytes, unsigned int length), NSError **actionError))action
__deprecated_msg("Use -writeIntoBuffer:props:error:block: instead");

/**
* Writes data to the zip file in pieces, allowing you to stream the write, so the entire contents
* DEPRECATED: Writes data to the zip file in pieces, allowing you to stream the write, so the entire contents
* don't need to reside in memory at once. It overwrites an existing file with the same name, only if
* specified with the overwrite flag. Overwriting presents a tradeoff: the whole archive needs to be
* copied (minus the file to be overwritten) before the write begins. For a large archive, this can
Expand Down Expand Up @@ -673,11 +720,12 @@ compressionMethod:(UZKCompressionMethod)method
CRC:(unsigned long)preCRC
password:(nullable NSString *)password
error:(NSError **)error
block:(BOOL(^)(BOOL(^writeData)(const void *bytes, unsigned int length), NSError **actionError))action;
block:(BOOL(^)(BOOL(^writeData)(const void *bytes, unsigned int length), NSError **actionError))action
__deprecated_msg("Use -writeIntoBuffer:props:error:block: instead");


/**
* Writes data to the zip file in pieces, allowing you to stream the write, so the entire contents
* DEPRECATED: Writes data to the zip file in pieces, allowing you to stream the write, so the entire contents
* don't need to reside in memory at once. It overwrites an existing file with the same name, only if
* specified with the overwrite flag. Overwriting presents a tradeoff: the whole archive needs to be
* copied (minus the file to be overwritten) before the write begins. For a large archive, this can
Expand Down Expand Up @@ -715,7 +763,8 @@ compressionMethod:(UZKCompressionMethod)method
CRC:(unsigned long)preCRC
password:(nullable NSString *)password
error:(NSError **)error
block:(BOOL(^)(BOOL(^writeData)(const void *bytes, unsigned int length), NSError **actionError))action;
block:(BOOL(^)(BOOL(^writeData)(const void *bytes, unsigned int length), NSError **actionError))action
__deprecated_msg("Use -writeIntoBuffer:props:error:block: instead");

/**
* Removes the given file from the archive
Expand Down
Loading