Compressing large files in zip vs `streaming`
Closed this issue · 1 comments
noxytrux commented
Hi my problem is that I'm tying to zip a folder containing multiple files which can be executed e.g this way:
[OZZipFile *zFile = [[OZZipFile alloc] initWithFileName:zipFilePath mode:OZZipFileModeCreate];
NSFileManager *fm = [NSFileManager new];
NSDirectoryEnumerator *directoryEnumerator = [fm enumeratorAtPath:folderPath];
BOOL isDir;
for (NSString *file in directoryEnumerator)
{
NSString *path = [folderPath stringByAppendingPathComponent:file];
[fm fileExistsAtPath:path
isDirectory:&isDir];
if (isDir)
{
continue;
}
OZZipWriteStream *stream = [zFile writeFileInZipWithName:file
compressionLevel:compressionLevel];
NSData *inputDataBuffer;
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
[readHandle seekToFileOffset:0];
while( [(inputDataBuffer = [readHandle readDataOfLength:2048 * 32]) length] != 0 ) {
@autoreleasepool {
[stream writeData:inputDataBuffer];
}
}
[stream finishedWriting];
}
[zFile close];
The problem is that some of those files may be big like i have 600mb video there, so the compression on even quiet good iPad may fail like iPad Air1 will not be able to compress the file.
I even tried doing some NSFileHandle as shown up and chunking write, but no memory footprint reduction at all.
So my question is. Does it really write like a stream or its just a name ? is there any other way to somehow compress big file in memory efficient way?
Regards
Marcin
noxytrux commented
Ok turns out while is wrong and generates leak after fix all work as expected/