问题
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