Skip to content

Commit d4861aa

Browse files
committed
added two methods for append zip file
1 parent 0f940d8 commit d4861aa

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

ZipArchive.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ typedef void(^ZipArchiveProgressUpdateBlock)(int percentage, int filesProcessed,
9595
-(id) initWithFileManager:(NSFileManager*) fileManager;
9696

9797
-(BOOL) CreateZipFile2:(NSString*) zipFile;
98+
-(BOOL) CreateZipFile2:(NSString*) zipFile append:(BOOL)isAppend;
9899
-(BOOL) CreateZipFile2:(NSString*) zipFile Password:(NSString*) password;
100+
-(BOOL) CreateZipFile2:(NSString*) zipFile Password:(NSString*) password append:(BOOL)isAppend;
99101
-(BOOL) addFileToZip:(NSString*) file newname:(NSString*) newname;
100102
-(BOOL) addDataToZip:(NSData*) data fileAttributes:(NSDictionary *)attr newname:(NSString*) newname;
101103
-(BOOL) CloseZipFile2;
@@ -105,6 +107,10 @@ typedef void(^ZipArchiveProgressUpdateBlock)(int percentage, int filesProcessed,
105107
-(BOOL) UnzipFileTo:(NSString*) path overWrite:(BOOL) overwrite;
106108
-(NSDictionary *)UnzipFileToMemory;
107109
-(BOOL) UnzipCloseFile;
108-
-(NSArray*) getZipFileContents; // list the contents of the zip archive. must be called after UnzipOpenFile
110+
111+
// List the contents of the zip archive. must be called after UnzipOpenFile.
112+
// If zip file was appended with `CreateZipFile2:append:` or ``CreateZipFile2:Password:append:`,
113+
// `getZipFileContents` result won't be updated until re-unzip-open after close write handle (`CloseZipFile2` then `UnzipCloseFile` then (`UnzipOpenFile:` or `UnzipOpenFile:Password`) get called).
114+
-(NSArray*) getZipFileContents;
109115

110116
@end

ZipArchive.m

+12-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ -(void) dealloc
7777

7878
-(BOOL) CreateZipFile2:(NSString*) zipFile
7979
{
80-
_zipFile = zipOpen( (const char*)[zipFile UTF8String], 0 );
80+
return [self CreateZipFile2:zipFile append:NO];
81+
}
82+
83+
-(BOOL) CreateZipFile2:(NSString*) zipFile append:(BOOL)isAppend
84+
{
85+
_zipFile = zipOpen( (const char*)[zipFile UTF8String], (isAppend ? APPEND_STATUS_ADDINZIP : APPEND_STATUS_CREATE) );
8186
if( !_zipFile )
8287
return NO;
8388
return YES;
@@ -97,6 +102,12 @@ -(BOOL) CreateZipFile2:(NSString*) zipFile Password:(NSString*) password
97102
return [self CreateZipFile2:zipFile];
98103
}
99104

105+
-(BOOL) CreateZipFile2:(NSString*) zipFile Password:(NSString*) password append:(BOOL)isAppend
106+
{
107+
self.password = password;
108+
return [self CreateZipFile2:zipFile append:isAppend];
109+
}
110+
100111
/**
101112
* add an existing file on disk to the zip archive, compressing it.
102113
*

0 commit comments

Comments
 (0)