Giter VIP home page Giter VIP logo

snappy-objc's Introduction

Snappy-ObjC

Google's Snappy compression power as NSData/NSString categories. All you need to know to use it:

#import "Snappy-ObjC.h"
NSData *someCompressedData = [NSData dataWithContentsOfURL:somewhereOnDiskWhereThereIsCompressedData];
NSData *uncompressedData = [someCompressedData snappy_decompressedData];
NSData *backToCompressedData = [uncompressedData snappy_compressedData];
NSAssert([backToCompressedData isEqualToData:someCompressedData], @"IT SHOULD HAVE BEEN EQUAL!");

// It works with NSString (UTF8 only) too!
NSString *imGoingToGetShrinked = @"Hello, World!";
NSData *shrinked = [imGoingToGetShrinked snappy_compressedString];
NSString *imBackAsAWhole = [shrinked snappy_decompressedString];
NSAssert([imGoingToGetShrinked isEqualToString:imBackAsAWhole], @"IT SHOULD HAVE BEEN EQUAL!");

It uses snappy-c, a C port of Google's Snappy compression library (originally written in C++). It performs pretty well, by trading off some compression ratio. In their own words:

Snappy is a compression/decompression library. It does not aim for maximum compression, or compatibility with any other compression library; instead, it aims for very high speeds and reasonable compression. For instance, compared to the fastest mode of zlib, Snappy is an order of magnitude faster for most inputs, but the resulting compressed files are anywhere from 20% to 100% bigger. On a single core of a Core i7 processor in 64-bit mode, Snappy compresses at about 250 MB/sec or more and decompresses at about 500 MB/sec or more.

Installation

Using CocoaPods (which you should be using), only add a line saying pod 'Snappy' and compress away.

Method prefix

If you want to do without the snappy_* prefix in front of all method names, simply add a preprocessor macro named SNAPPY_NO_PREFIX.

If you are using cocoapods, that means going to the Pods-Snappy target in your "Pods" Xcode project, to its build settings, finding the "Preprocessor Macros" setting and adding the above macro. Note that you'll have to do this after every run of cocoapod (everytime you type pod [something] in your project's folder), since cocoapod overrides that setting when it runs. There is going to be a fix for this sometime in the future. Meanwhile, you can add this code to your project's Podfile:

post_install do |rep|
  rep.project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= '$(inherited)'
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] <<= " SNAPPY_NO_PREFIX=1"
    end
  end
end

Testing

The project includes a (simple) [test suite](Tests/Snappy-ObjC Tests/Snappy_ObjC_Tests.m).

  1. Clone the repo
  2. Go in Tests/
  3. pod install
  4. Open Snappy-ObjC.xcworkspace and run the tests

License

The MIT License (MIT)

Copyright (c) 2013 Mathieu D'Amours

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

snappy-objc's People

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.