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

1

0

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.

Dethrone answered 13/5, 2009 at 17:0 Comment(0)
D
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*********************************************************************************** 
Dethrone answered 14/5, 2009 at 16:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.