如何使用Zlib将char数组压缩到压缩的html页面中 [英] How can I compress a char array into a compressed html page using Zlib

查看:159
本文介绍了如何使用Zlib将char数组压缩到压缩的html页面中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C中有一个CGI应用程序,通过将char *保存为html页面来创建html页面:

I have a CGI application in C that creates an html page by saving a char* as a html page:

void saveTextFile(const char *filename, const char *str){.......}  

称为

called as

saveTextFile("..\\index.html",outputFile);

如何使用zlib作为输入outputFile字符数组并输出一个带有适当头文件的压缩html页面?

How do I use zlib to take as input the "outputFile" char array and output a zipped html page with appropriate headers?

gzopen 在这里使用,而不是我的saveTextFile函数?

Would the gzopen be used here instead of my saveTextFile function?

任何建议表示赞赏。

推荐答案

//****************************************************************************************
    //ZIP file: Take the char string "outputFile" as input to gzip. Create a zipped html file
    file = gzopen("..\\index.html.gz", "wb"); //create a zipped file
    if (file == NULL) {
        printf("Can't open zipped file");
        exit(1);
    }
    len   = strlen(outputFile); //need to know length of string
    compd = gzwrite(file, outputFile, (unsigned)len); //compress data into .gz file
    cls   = gzclose (file); //close .gz file
    //End zip*********************************************************************************** 

这篇关于如何使用Zlib将char数组压缩到压缩的html页面中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆