LzmaSDKObjC 1.0.5

LzmaSDKObjC 1.0.5

测试已测试
语言语言 C++C++
许可证 MIT
发布最新发布2016年3月

Oleh Kulykov维护。



  • 作者:
  • OlehKulykov

这并非又是一个围绕LZMA SDK C部分的包装库,具有所有其局限性。基于C++ LZMA SDK的15.14版本(1514 - 目前最新的)并在iOS & Mac OS平台上进行了修补。

描述


这并非又是一个围绕LZMA SDK C部分的包装库,具有所有其局限性。基于C++ LZMA SDK的15.14版本(1514 - 目前最新的)并在iOS & Mac OS平台上进行了修补。

主要优势是

  • 列出查看7z文件(Lzma & Lzma2压缩方法)。
  • 列出查看加密的(受密码保护的)7z文件(Lzma & Lzma2压缩方法)。
  • 列出、提取加密码+加密头部(无可见内容、文件列表,无需密码)的7z文件(Lzma & Lzma2压缩方法)。
  • 在列出一、"提取"过程中管理内存分配。以下部分有详细说明:优化速度、性能和磁盘IO操作。
  • 优化以达到小于500Kb的列一、"提取"大小,可轻松在运行时更改(无硬编码定义)。以下部分有详细说明:优化速度、性能和磁盘IO操作。
  • 管理读/写IO操作,也可在运行时轻松更改(无硬编码定义)。以下部分有详细说明:优化速度、性能和磁盘IO操作。
  • 跟踪平滑进度,这是由于先前版本而实现的。
  • 支持读取大于4GB的归档文件,提取超过4GB的文件。
  • Unicode支持。

Podfile

use_frameworks!
platform :ios, '8.0'

pod 'LzmaSDK-ObjC', :inhibit_warnings => true

Objective-C和Swift示例


列出和提取

创建和设置带有归档路径和/或归档类型的读取器,可选委托和可选密码获取器块,在加密归档的情况下
Objective-C
// 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";
};
Swift
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"
}
打开归档,例如,找出归档类型,定位解码器并读取归档标题
Cocoa
// 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);
Swift
do {
    try reader.open()
}
catch {
// process exception
}
迭代存档项,选择并存储所需项目以供未来处理
Cocoa
// 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);
Swift
var items = [LzmaSDKObjCItem]()
reader.iterateWithHandler({(item: LzmaSDKObjCItem, error: NSError?) -> Bool in
            items.append(item)
            return true
        })
提取或测试存档项
Cocoa
// 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);
Swift
// Extract selected items from prev. step.
reader.extract(items, toPath: "/extract/path", withFullPaths: true)

优化速度、性能和磁盘I/O操作


原始的C++ LZMA SDK部分进行了修补,以便能够调整默认(内嵌)设置。对于列表和提取功能,定义了以下全局变量:kLzmaSDKObjCStreamReadSizekLzmaSDKObjCStreamWriteSizekLzmaSDKObjCDecoderReadSizekLzmaSDKObjCDecoderWriteSize。这些变量以字节为单位存储大小值,因此,对于单个读取器对象,这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/*.7z
    • [x] 列表
      • [x] 正常存档。《code>tests/files/lzma.7z
      • [x] 加密的存档,使用AES256加密。《code>tests/files/lzma_aes256.7z
      • [x] 加密的存档+加密的头部(没有可见内容,文件列表,无密码)使用AES256。《code>tests/files/lzma_aes256_encfn.7z
    • [x] 提取
      • [x] 正常存档。《code>tests/files/lzma.7z
      • [x] 加密的存档,使用AES256加密。《code>tests/files/lzma_aes256.7z
      • [x] 加密的存档+加密的头部(没有可见内容,文件列表,无密码)使用AES256。《code>tests/files/lzma_aes256_encfn.7z
    • [ ] 创建
    • [ ] 更新
  • [ ] Lzma2/*.7z
    • [x] 列表
      • [x] 正常存档。《code>tests/files/lzma2.7z
      • [x] 加密的存档,使用AES256加密。《code>tests/files/lzma2_aes256.7z
      • [x] 加密的存档+加密的头部(没有可见内容,文件列表,无密码)使用AES256。《code>tests/files/lzma2_aes256_encfn.7z
    • [x] 提取
      • [x] 正常存档。《code>tests/files/lzma2.7z
      • [x] 加密的存档,使用AES256加密。《code>tests/files/lzma2_aes256.7z
      • [x] 加密的存档+加密的头部(没有可见内容,文件列表,无密码)使用AES256。《code>tests/files/lzma2_aes256_encfn.7z
    • [ ] 创建
    • [ ] 更新
  • [ ] 省略未使用代码,减少可构建代码和原始代码的大小。

许可协议


通过使用此协议,您接受原始的 LZMA SDK 和 MIT 许可协议(《see below》)。

MIT 许可协议 (MIT)

版权(c)2015 - 2016 Kulykov Oleh [email protected]

特此允许任何人免费获取此软件及其相关文档文件(“软件”),在不受限制的情况下处理软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件的副本,并允许将软件提供给他人,以便进行上述操作,前提是以下条件

上述版权声明和本许可证声明应包括在软件的所有副本或实质性部分中。

软件按“原样”提供,不提供任何形式的质量保证,无论是明确保证还是默示保证,包括但不限于适销性、适用于特定用途以及非侵权性保证。在任何情况下,无论是否基于合同、侵权或任何其他行为,无论是在软件本身、使用或与其他研究、使用软件的过程有关的情况下,作者或版权所有者不对任何索赔、损害或其他责任承担责任。