这并非又是一个围绕LZMA SDK C部分的包装库,具有所有其局限性。基于C++ LZMA SDK的15.14版本(1514 - 目前最新的)并在iOS & Mac OS平台上进行了修补。
这并非又是一个围绕LZMA SDK C部分的包装库,具有所有其局限性。基于C++ LZMA SDK的15.14版本(1514 - 目前最新的)并在iOS & Mac OS平台上进行了修补。
主要优势是
use_frameworks!
platform :ios, '8.0'
pod 'LzmaSDK-ObjC', :inhibit_warnings => true
// select full path to archive file with 7z or xz extension
NSString * archivePath = <path to archive>;
// 1.1 Create and hold strongly reader object.
self.reader = [[LzmaSDKObjCReader alloc] initWithFileURL:[NSURL fileURLWithPath:archivePath]];
// 1.2 Or create with predefined archive type if path doesn't containes suitable extension
self.reader = [[LzmaSDKObjCReader alloc] initWithFileURL:[NSURL fileURLWithPath:archivePath]
andType:LzmaSDKObjCFileType7z];
// Optionaly: assign weak delegate for tracking extract progress.
_reader.delegate = self;
// If achive encrypted - define password getter handler.
// NOTES:
// - Encrypted file needs password for extract process.
// - Encrypted file with encrypted header needs password for list(iterate) and extract archive items.
_reader.passwordGetter = ^NSString*(void){
return @"password to my achive";
};
import LzmaSDK_ObjC
...
// replace path with your actual path to archive
let archivePath = "path to archive"
let reader: LzmaSDKObjCReader = LzmaSDKObjCReader(fileURL: NSURL(string: archivePath)!)
reader.passwordGetter = {() -> String? in
return "password to my achive"
}
// Open archive, with or without error. Error can be nil.
NSError * error = nil;
if (![_reader open:&error])
{
NSLog(@"Open error: %@", error);
}
NSLog(@"Open error: %@", _reader.lastError);
do {
try reader.open()
}
catch {
// process exception
}
// Iterate all archive items, track what items do you need & hold them in array.
NSMutableArray * items = [NSMutableArray array]; // Array with selected items.
[_reader iterateWithHandler:^BOOL(LzmaSDKObjCItem * item, NSError * error){
NSLog(@"\n%@", item);
if (item) [items addObject:item]; // if needs this item - store to array.
return YES; // YES - continue iterate, NO - stop iteration
}];
NSLog(@"Iteration error: %@", _reader.lastError);
var items = [LzmaSDKObjCItem]()
reader.iterateWithHandler({(item: LzmaSDKObjCItem, error: NSError?) -> Bool in
items.append(item)
return true
})
// Extract selected items from prev. step.
// YES - create subfolders structure for the items.
// NO - place item file to the root of path(in this case items with the same names will be overwrited automaticaly).
[_reader extract:items
toPath:@"/extract/path"
withFullPaths:YES];
NSLog(@"Extract error: %@", _reader.lastError);
// Test selected items from prev. step.
[_reader test:items];
NSLog(@"test error: %@", _reader.lastError);
// Extract selected items from prev. step.
reader.extract(items, toPath: "/extract/path", withFullPaths: true)
原始的C++ LZMA SDK部分进行了修补,以便能够调整默认(内嵌)设置。对于列表和提取功能,定义了以下全局变量:kLzmaSDKObjCStreamReadSize
、kLzmaSDKObjCStreamWriteSize
、kLzmaSDKObjCDecoderReadSize
和 kLzmaSDKObjCDecoderWriteSize
。这些变量以字节为单位存储大小值,因此,对于单个读取器对象,这4个值之和将被分配。
请注意:内存操作比磁盘I/O操作快得多,所以请阅读以下情境。
switch (<what do I need ?>)
{
case <I need faster list and extract>:
//TODO: Increase stream and decoder size of buffers
Result:
1. more allocated memory
2. less IO read/write operations and less delays
3. less smoothed progress
4. more CPU load (do a job, not distracted to read/write data)
break;
case <I need use less memory or more smoothed progress>:
//TODO: Decrease stream and decoder size of buffers
Result:
1. less allocated memory
2. more IO read/write operations and more delays
3. more smoothed progress
4. less CPU load (wait for read/write data)
break;
default:
//TODO: use current settings
break;
};
注意:在创建和使用读取器对象之前修改全局变量。
注意:此分配大小不影响档案字典分配的内存。
通过使用此协议,您接受原始的 LZMA SDK 和 MIT 许可协议(《see below》)。
MIT 许可协议 (MIT)
版权(c)2015 - 2016 Kulykov Oleh [email protected]
特此允许任何人免费获取此软件及其相关文档文件(“软件”),在不受限制的情况下处理软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件的副本,并允许将软件提供给他人,以便进行上述操作,前提是以下条件
上述版权声明和本许可证声明应包括在软件的所有副本或实质性部分中。
软件按“原样”提供,不提供任何形式的质量保证,无论是明确保证还是默示保证,包括但不限于适销性、适用于特定用途以及非侵权性保证。在任何情况下,无论是否基于合同、侵权或任何其他行为,无论是在软件本身、使用或与其他研究、使用软件的过程有关的情况下,作者或版权所有者不对任何索赔、损害或其他责任承担责任。