Coder Social home page Coder Social logo

gzip's Introduction

Gzip

数据请求 GZip数据压缩和解压缩问题

主要使用了官方的libz.1.2.3.dylib库

I recently had to write a utility for compressing data in memory using the gzip format.

Thankfully, there’s a C library called zlib you can use to do the actual compression (and thankfully you can link to libz.dylib on the iPhone). Using the library is not trivial, however, so I had to spend a day reading the zlib headers/documentation and also searching for examples from other developers (one example shared by Robbie Hanson was particularly helpful). While Robbie’s example is great,I wanted something a bit more robust and easier to “plug in” to any existing project. As part of making it “plug ‘n play,”I also wanted to make it developer-friendly: if something goes wrong,the utility should be helpful in solving the problem instead of just exiting with a cryptic error code.That means adding a healthy amount of documentation and descriptive error message logging so that like me Developer–who just wanted to copy and paste the utility into his project and move on–can quickly understand the code and the error message if problems come up.

整体客户端-服务端数据压缩解压流程:(

客户端生成request,设置header允许使用压缩("Accept-Encoding","gzip"), 即是告诉服务器,客户端支持压缩,但凡可以实现压缩的,服务器当收到这个header, 如果它支持压缩,可以通过压缩方式输出数据,然后再写入response的header("Content-Encoding","gzip")

Author cuishengxi
E-mail [email protected]

主要代码:

使用时#import "GzipUtil.h"

// 数据压缩

+ (NSData *)compressData:(NSData*)uncompressedData;

// 数据解压缩

+ (NSData *)decompressData:(NSData *)compressedData;

What's wrong, please communicate more, thank you!

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.