| | 6 | |
| | 7 | The gzip_when_done is only supported in client version 5.8 (version # needs to be confirmed) and more recently. If you will receive files from clients that do not support the gzip_when_done flag then you should open the files with a function similar to this: |
| | 8 | |
| | 9 | int read_gzip_file_string(string file, string* result) { |
| | 10 | FILE *infile; |
| | 11 | char cmd[512]; |
| | 12 | char buf[4096]; |
| | 13 | result->erase(); |
| | 14 | |
| | 15 | //build the command |
| | 16 | cmd[0]='\0'; |
| | 17 | strcat(cmd, "gzip -dcf "); |
| | 18 | strcat(cmd, file.c_str()); |
| | 19 | |
| | 20 | infile = popen(cmd, "r"); |
| | 21 | if (infile == NULL) { |
| | 22 | return ERR_FOPEN; |
| | 23 | } |
| | 24 | |
| | 25 | while( fgets(buf, 4096, infile) != NULL ) { |
| | 26 | result->append(buf); |
| | 27 | } |
| | 28 | result->append("\0"); |
| | 29 | if (pclose(infile) != 0) { |
| | 30 | fprintf(stderr, "%s: pclose failed\n", file.c_str()); |
| | 31 | return 1; |
| | 32 | } |
| | 33 | return 0; |
| | 34 | } |
| | 35 | |
| | 36 | This will automatically uncompress the file if it is compressed or it will open it without modification if it is not compressed. |
| | 37 | |