Code Monkey home page Code Monkey logo

gzip's Introduction

Build Codecov License Mastodon

Purpose

GZIP is category on NSData that provides simple gzip compression and decompression functionality.

Supported OS & SDK Versions

  • Supported build target - iOS 12.0 / Mac OS 10.14 (Xcode 10.1)
  • Earliest supported deployment target - iOS 11.0 / Mac OS 10.14.6
  • Earliest compatible deployment target - iOS 11.0 / Mac OS 10.6

NOTE: 'Supported' means that the library has been tested with this version. 'Compatible' means that the library should work on this iOS version (i.e. it doesn't rely on any unavailable SDK features) but is no longer being tested for compatibility and may require tweaking or bug fixes to run correctly.

ARC Compatibility

The GZIP category will work correctly in either ARC or non-ARC projects without modification.

Thread Safety

All the GZIP methods should be safe to call from multiple threads concurrently.

Installation

The simplest way to install GZIP is to use CocoaPods, by adding the following to your Podfile:

pod 'GZIP', '~> 1.3.2'

Alternatively you can use Carthage, or if you prefer to install manually, drag the GZIP.xcodeproj into your project or workspace and include GZIP.framework under the linked libraries in your target.

NSData Extensions

- (NSData *)gzippedDataWithCompressionLevel:(float)level;

This method will apply the gzip deflate algorithm and return the compressed data. The compression level is a floating point value between 0.0 and 1.0, with 0.0 meaning no compression and 1.0 meaning maximum compression. A value of 0.1 will provide the fastest possible compression. If you supply a negative value, this will apply the default compression level, which is equivalent to a value of around 0.7.

- (NSData *)gzippedData;

This method is equivalent to calling gzippedDataWithCompressionLevel: with the default compression level.

- (NSData *)gunzippedData;

This method will unzip data that was compressed using the deflate algorithm and return the result.

- (BOOL)isGzippedData;

This method will return YES if the data is gzip-encoded.

gzip's People

Contributors

ariezn avatar barksten avatar damirdavletov avatar dmiluski avatar edelabar avatar hyperspacemark avatar john-wolfe-bose avatar jparise avatar mmertsock avatar nicklockwood avatar rcdilorenzo avatar simonbs avatar y8k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gzip's Issues

Please add semantic version tags

I’ve recently added GZIP to the CocoaPods package manager repo.

CocoaPods is a tool for managing dependencies for OS X and iOS Xcode projects and provides a central repository for iOS/OS X libraries. This makes adding libraries to a project and updating them extremely easy and it will help users to resolve dependencies of the libraries they use.

However, GZIP doesn't have any version tags. I’ve added the current HEAD as version 0.0.1, but a version tag will make dependency resolution much easier.

Semantic version tags (instead of plain commit hashes/revisions) allow for resolution of cross-dependencies.

In case you didn’t know this yet; you can tag the current HEAD as, for instance, version 1.0.0, like so:

$ git tag -a 1.0.0 -m "Tag release 1.0.0"
$ git push --tags

About Z_BEST_COMPRESSION

hi,I use your open source for gzip,but i want to use best compression,so i change parms use best compression,but data isn't less than use default compression,
as:

define Z_NO_COMPRESSION 0

define Z_BEST_SPEED 1

define Z_BEST_COMPRESSION 9

define Z_DEFAULT_COMPRESSION (-1)

Add Carthage Support

We're using GZIP and would love to be able to include it in our project via Carthage

Ungzip while reading file

Is it possible to ungzip the file while reading it? Meaning, streaming so that it doesn't take too much memory? I have a gzip file that is over 1 gig, so I am needing to stream it.

Uncompress code causing crash

This code:

 //  read the file back into databuffer...
    NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSFileHandle *readFile = [NSFileHandle fileHandleForReadingAtPath:[documentsPath stringByAppendingPathComponent: chosenFilename]];
    NSData *databuffer = [readFile readDataToEndOfFile];
    [readFile closeFile];
    // decompress the file
    NSData *uncompressedData = [databuffer gunzippedData];

is causing this crash:
2014-10-24 08:45:03.801 BookstoreInventoryManager[12477:4168264] -[NSConcreteData gunzippedData]: unrecognized selector sent to instance 0x7a7f7800
2014-10-24 08:45:03.802 BookstoreInventoryManager[12477:4168264] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteData gunzippedData]: unrecognized selector sent to instance 0x7a7f7800'
*** First throw call stack:
(
0 CoreFoundation 0x02dcfdf6 exceptionPreprocess + 182
1 libobjc.A.dylib 0x022e4a97 objc_exception_throw + 44
2 CoreFoundation 0x02dd7a75 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x02d209c7 __forwarding
+ 1047
4 CoreFoundation 0x02d2058e _CF_forwarding_prep_0 + 14
5 BookstoreInventoryManager 0x000df35e -[SettingsViewController tableView:didSelectRowAtIndexPath:] + 574
6 UIKit 0x00dde4fc -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1559
7 UIKit 0x00dde6a7 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 285
8 UIKit 0x00de39a3 __38-[UITableView touchesEnded:withEvent:]_block_invoke + 43
9 UIKit 0x00cf862e ___afterCACommitHandler_block_invoke + 15
10 UIKit 0x00cf85d9 _applyBlockToCFArrayCopiedToStack + 415
11 UIKit 0x00cf83ee _afterCACommitHandler + 545
12 CoreFoundation 0x02cf2fbe CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 30
13 CoreFoundation 0x02cf2f00 __CFRunLoopDoObservers + 400
14 CoreFoundation 0x02ce893a __CFRunLoopRun + 1226
15 CoreFoundation 0x02ce81ab CFRunLoopRunSpecific + 443
16 CoreFoundation 0x02ce7fdb CFRunLoopRunInMode + 123
17 GraphicsServices 0x0445f24f GSEventRunModal + 192
18 GraphicsServices 0x0445f08c GSEventRun + 104
19 UIKit 0x00ccee16 UIApplicationMain + 1526
20 BookstoreInventoryManager 0x000a922d main + 141
21 libdyld.dylib 0x034c6ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
`
The file I'm trying to uncompress is here: http://en.file-upload.net/download-9736782/Backup10232014082349.zip.html

gzippedData returns nil

Hello. I started to use your GZIP via pods. I added libz.dylib to my project, but gzippedData returns nil. I noticed that error in deflateInit2, it returns -2, instead 0.

Crash on iOS 9

gzippedDataWithCompressionLevel(0.1) is crashing 100% of the time.
OS Version: iOS 9.0 (13A4305g)
Report Version: 105

I'm assuming it has to do with the line:
void *libz = dlopen("libz.dylib", RTLD_NOW);

Unfortunately I can't get that specific. No interesting crash log to report. The symbolicated crash log for the line looks like this:
0 ??? 000000000000000000 0 + 0

iOS GZIP value differs between iOS10 -> iOS11

I just noticed through one of our tests that gzipped() data which is base64Encoded yields a different value between iOS10 vs iOS 11.

Anyone notice similar issues? I wouldn't have noticed had I not set my target to unit test with (iPhone 7, iOS 11). I was aware this could differ between 32/64 bit, but I was surprised by the different between iOS10 vs iOS11?

It also might be an issue that I shouldn't be testing this code in my app anyway?

Use Case:

        guard let JSON = try? JSONSerialization.data(withJSONObject: jsonObject, options: []), !validContacts.isEmpty,
            let gZippedData = (JSON as NSData).gzipped() else { return nil }

        return gZippedData.base64EncodedString(options: [])
XCTAssertEqual failed: XCTAssertEqual failed: ("Optional("H4sIAAAAAAAAA1WOOwvCMBRG/0q4cynNQ1OdWtBNRHAsHYKGGptHaaAg0v9uE43olOE759w0T5CwbeAqvJGjV7a7VZ0RSucXZ6DNQMEWOGQwBGqF14QSxikNk12mXfTQOYgwZ5+aVs5KXU3SGvcbKlOIMco5JbhkKXSICqr1JH0MBX6z8DEotcrv+SDHXln//8Eg77VCp/f4dXGRjpECE1ZSTnHi64foBTo6uzwwty+Dt4izBQEAAA==")") is not equal to ("Optional("H4sIAAAAAAAAE1WOOwvCMBRG/0q4cynNQ1OdWtBNRHAsHYKGGptHaaAg0v9uE43olOE759w0T5CwbeAqvJGjV7a7VZ0RSucXZ6DNQMEWOGQwBGqF14QSxikNk12mXfTQOYgwZ5+aVs5KXU3SGvcbKlOIMco5JbhkKXSICqr1JH0MBX6z8DEotcrv+SDHXln//8Eg77VCp/f4dXGRjpECE1ZSTnHi64foBTo6uzwwty+Dt4izBQEAAA==")") - 

Don't use dlopen and dlsym in iOS App Store project

We had been rejected because of this.

This code, combined with a remote resource, can facilitate significant changes to your app’s behavior compared to when it was initially reviewed for the App Store. While you may not be using this functionality currently, it has the potential to load private frameworks, private methods, and enable future feature changes. This includes any code which passes arbitrary parameters to dynamic methods such as dlopen(), dlsym(), respondsToSelector:, performSelector:, method_exchangeImplementations(), and running remote scripts in order to change app behavior and/or call SPI, based on the contents of the downloaded script. Even if the remote resource is not intentionally malicious, it could easily be hijacked via a Man In The Middle (MiTM) attack, which can pose a serious security vulnerability to users of your app.

ASC-GZIP files

Hello,

Your GZip library has helped me immensely in my projects. I had a question about files of this type: asc-gzip. Trying to unzip these files always comes back null. Have you ever encountered this type of encoding before?

Thank you again for a great piece of code!

NSData+Gzip

Should the two files named GZIP.h & GZIP.m be named NSData+Gzip or NSData-Gzip? Or am I nitpicking?

deflateInit2 causing unknown crashes

We've experienced a few crashes that point to the deflateInit2 method when the gzippedDataWithCompressionLevel method in NSData+GZIP is called. Has there been any documentation of a crash like this before?

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.