Coder Social home page Coder Social logo

patchpackagedemo's Introduction

增量包合并和解压

基于源码编译

7z (lzma1900) https://www.7-zip.org/sdk.html

bzip2(1.0.6) https://sourceforge.net/projects/bzip2/

bsdiff(4.3) http://www.daemonology.net/bsdiff/

简单用法

合并增量包&解压合并后的全量包

- (void)testExample {
    /**
     1、合并增量包
    1.0.7z + 1.0-1.1.patch = 1.1.7z
     */
    NSString *oldFilePath = [[NSBundle bundleForClass:self.class] pathForResource:@"1.0.7z" ofType:nil];
    NSString *patchFilePath = [[NSBundle bundleForClass:self.class] pathForResource:@"1.0-1.1.patch" ofType:nil];;
    NSString *newFilePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject stringByAppendingPathComponent:@"1.1.7z"];
   
    NSError *error = NULL;
    BOOL success = [BSDiffUtil merge:oldFilePath withPatchFile:patchFilePath toNewFile:newFilePath error:&error];
    NSLog(@"=======error====== %@", error.localizedDescription);
    NSLog(@"=====newFilePath====== %@", newFilePath);
    
    /**
     2、解压合并后的全量包 1.1.7z
     */
    NSString *archiveResPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    archiveResPath = [archiveResPath stringByAppendingPathComponent:@"1.1.7z"];
    NSLog(@"=======7z====== %@", archiveResPath);
    
    NSString *destinationPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    destinationPath = [destinationPath stringByAppendingPathComponent:@"Extract7z"];
    NSLog(@"=======destinationPath====== %@", destinationPath);
    
    error = NULL;
    success = [SevenZDec extract7zArchive:archiveResPath toDestination:destinationPath error:&error];
    
    NSLog(@"=======error====== %@", error.localizedDescription);
    
    NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:destinationPath error:nil];
    for (NSString *entryPath in contents) {
      NSData *outputData = [NSData dataWithContentsOfFile:entryPath];
      NSString *outStr = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];

      NSLog(@"%@", entryPath);
      NSLog(@"%@", outStr);
    }
}

patchpackagedemo's People

Contributors

karosli avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.