How can I compress a char array into a compressed html page using Zlib

北城余情 提交于 2019-12-25 04:04:43

问题


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);

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

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

Any advice is appreciated. Thanks.


回答1:


Got it -

//****************************************************************************************
    //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*********************************************************************************** 


来源:https://stackoverflow.com/questions/859155/how-can-i-compress-a-char-array-into-a-compressed-html-page-using-zlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!