Coder Social home page Coder Social logo

nvhtargzipv2's Introduction

NVHTarGzip

IS

PR

  • nvh#24, merged
  • nvh#22, nvh#20, they fixed the bug with cutting off the name when it exceeds, while i use NAME_MAX, if other show up, contacts: [email protected]
  • nvh#12, partially merged, reject the fix about NSProgress multithreading issue.

Usage

Asynchronous

Inflate Gzip file

[[NVHTarGzip sharedInstance] unGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* gzipError) {
    if (gzipError != nil) {
        NSLog(@"Error ungzipping %@", gzipError);
    }
}];

Untar file

[[NVHTarGzip sharedInstance] unTarFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* tarError) {
    if (tarError != nil) {
        NSLog(@"Error untarring %@", tarError);
    }
}];

Inflate Gzip and Untar

[[NVHTarGzip sharedInstance] unTarGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* error) {
    if (error != nil) {
        NSLog(@"Error extracting %@", error);
    }
}];

Deflate Gzip file

[[NVHTarGzip sharedInstance] gzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* gzipError) {
    if (gzipError != nil) {
        NSLog(@"Error gzipping %@", gzipError);
    }
}];

Tar file

[[NVHTarGzip sharedInstance] tarFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* tarError) {
    if (tarError != nil) {
        NSLog(@"Error tarring %@", tarError);
    }
}];

Deflate Gzip and Tar

[[NVHTarGzip sharedInstance] tarGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* error) {
    if (error != nil) {
        NSLog(@"Error packing %@", error);
    }
}];

Synchronous

Inflate Gzip file

[[NVHTarGzip sharedInstance] unGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* gzipError) {
    if (gzipError != nil) {
        NSLog(@"Error ungzipping %@", gzipError);
    }
}];

Untar file

[[NVHTarGzip sharedInstance] unTarFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* tarError) {
    if (tarError != nil) {
        NSLog(@"Error untarring %@", tarError);
    }
}];

Inflate Gzip and Untar

[[NVHTarGzip sharedInstance] unTarGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* error) {
    if (error != nil) {
        NSLog(@"Error extracting %@", error);
    }
}];

Deflate Gzip file

[[NVHTarGzip sharedInstance] gzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* gzipError) {
    if (gzipError != nil) {
        NSLog(@"Error gzipping %@", gzipError);
    }
}];

Tar file

[[NVHTarGzip sharedInstance] tarFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* tarError) {
    if (tarError != nil) {
        NSLog(@"Error untarring %@", tarError);
    }
}];

Deflate Gzip and Tar

[[NVHTarGzip sharedInstance] tarGzipFileAtPath:sourcePath toPath:destinationPath completion:^(NSError* error) {
    if (error != nil) {
        NSLog(@"Error extracting %@", error);
    }
}];
Note

Sequential tar.gz packing and unpacking will either tar or ungzip the intermediate tar file to a temporary-directory, and subsequently gzip or untar it. After gzipping/untarring, the temporary-file is deleted. You can customize the cachePath by setting it on the singleton object before extracting:

[[NVHTarGzip sharedInstance] setCachePath:customCachePath];

Progress

NVHTarGzip uses NSProgress to handle progress reporting. To keep track of progress create your own progress instance and use KVO to inspect the fractionCompleted property. See the documentation of NSProgress and this great article by Ole Begemann for more information.

NSProgress* progress = [NSProgress progressWithTotalUnitCount:1];
NSString* keyPath = NSStringFromSelector(@selector(fractionCompleted));
[progress addObserver:self forKeyPath:keyPath options:NSKeyValueObservingOptionInitial context:NVHProgressFractionCompletedObserverContext];
[progress becomeCurrentWithPendingUnitCount:1];
[[NVHTarGzip sharedInstance] unTarGzipFileAtPath:self.demoSourceFilePath toPath:self.demoDestinationFilePath completion:^(NSError* error) {
    [progress resignCurrent];
    [progress removeObserver:self forKeyPath:keyPath];
}];

Checkout a full usage example in the example project; clone the repo, and run pod install from the Example directory first.

Todo

Add streaming support (NSStream). This would allow the usage of an intermediate file for tar.gz packing and unpacking, thus speeding things a bit.

Pull requests are welcome!

  • Current benchmark ?

    • Cpu Almost full payload
    • Memory Low when TarGzip?
    • Disk IO high payload
    • Network None

Installation

NVHTarGzip is available through CocoaPods, to install it simply add the following line to your Podfile:

pod "NVHTarGzip"

2th Author

Seven, [email protected]

nvhtargzipv2's People

Contributors

nvh avatar rsanchezsaez 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.