I'm trying to create an OS X (Cocoa) application for file compression with Xcode 7.0+Swift2.
The library used for compression is ZipArchive (formerly SSZipArchive) and has two functions:
·Create compressed files from multiple files
createZipFileAtPath withFilesAtPaths
·Create a compressed file from a single folder and its contents
createZipFileAtPath withContentsOfDirectory
You can create compressed files with only one folder, but if you want to create compressed files based on multiple files and folders, you cannot mix folder paths with FilesAtPaths.
In that case, you can temporarily create a folder, copy everything you want to compress into it, and compress it with ContentsOfDirectory, but if it's a small file, it takes time to compress a large file into a temporary folder.
If possible, I would like to directly create a compressed file with a mixture of folders and files, but is there such a way?
Another library is fine.
[Additional note]
The development environment has changed to Swift 1.x → 2.x because the question has passed.
Hi, I've never used that library, so I can't give you a good answer.
If that's the case, why don't you use the standard libz.dylib library instead of using that library to zip through multiple files and folders one by one in your program?
Only a part of it, but
- (NSData*)zlibInflate
{
if ([self length] == 0)
{
return self;
}
NSUInteger full_length = [self length];
NSUInteger half_length = full_length/2;
NSMutableData*decompressed = NSMutableDataDataWithLength: (full_length+half_length);
int status;
z_stream strm;
strm.next_in=(Bytef*) [self bytes];
strm.avail_in=(NMUInt) full_length;
strm.total_out = 0;
strm.zalloc = Z_NULL;
strm.zfree=Z_NULL;
if (inflateInit(&strm) == Z_OK)
{
BOOL done = FALSE;
while(!done)
{
if(strm.total_out>=[decompressed length])
{
[decompressed increaseLengthBy: half_length];
}
strm.next_out = [decompressed mutableBytes] + strm.total_out;
strm.avail_out=([decompressed length]-strm.total_out);
status=inflate(&strm,Z_SYNC_FLUSH);
if(status==Z_STREAM_END)
{
done = TRUE;
}
else if (status!=Z_OK)
{
break;
}
}
if (inflateEnd(&strm) == Z_OK)
{
if(done)
{
[decompressed setLength: strm.total_out];
return [NSDataDataWithData:decompressed];
}
}
}
return self;
}
For your information.
If it takes time to copy, how about using symbolic link instead?
567 Who developed the "avformat-59.dll" that comes with FFmpeg?
567 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
577 PHP ssh2_scp_send fails to send files as intended
884 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
606 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.