#include <stdio.h>
#include <string.h> // for strlen
#include <assert.h>
#include "zlib.h"
#include <iostream>
#include <fstream>
#include <sstream>
using std::cout; using std::cerr;
using std::endl; using std::string;
using std::ifstream; using std::ostringstream;
// adapted from: http://stackoverflow.com/questions/7540259/deflate-and-inflate-zlib-h-in-c
int main(int argc, char* argv[])
{
char a[50] = "Hello, world!";
char b[50];
char c[50];
uLong ucompSize = strlen(a)+1; // "Hello, world!" + NULL delimiter.
uLong compSize = compressBound(ucompSize);
// Deflate
compress((Bytef *)b, &compSize, (Bytef *)a, ucompSize);
printf("compress data is %s",c);
// Inflate
uncompress((Bytef *)c, &ucompSize, (Bytef *)b, compSize);
printf("uncompress data is %s",c);
return 0;
}
zlib解压http deflate demo
最新推荐文章于 2024-11-14 20:00:00 发布