-4

how to use gzip.compressstring() function using chilkat. the syntax is

bool CompressString(const char *inStr, const char *outCharset, CkByteData &outBytes);
// COMPRESSSTRING_END
// COMPRESSSTRINGTOFILE_BEGIN .but i dont know how to implement it in c++.

below is the code i tried to acheive the following but wasn't succeeded in it

CkGzip gzip;

bool success;
CkByteData data;
char buffer[100] = {0};
success = gzip.CompressString("helloworld", "utf8", data);
data = buffer;
cout << buffer;

if (success != true) {
    printf("%s\n", gzip.lastErrorText());
    return;
}

Note: i want "hello world" to be in compressed form as an output.

lotus
  • 1
  • 1

1 Answers1

0

from Documentation link http://www.chilkatsoft.com/refdoc/vcCkGZipRef.html

bool CompressString(const char *inStr, const char *destCharset, CkByteData &outBytes);

Gzip compresses a string and writes the output to a byte array. The string is first converted to the charset specified by destCharset. Typical charsets are "utf-8", "iso-8859-1", "shift_JIS", etc.

Returns true for success, false for failure.

This means user need to do something like this: const char *instr = "test"; const char *destCharset = "utf-8"; // or "iso-8859-1", "shift_JIS", etc CkByteData outBytes; //can also allocate on heap by new

if (CompressString(inStr, destCharset, outBytes)) count << "success\n"; //now user can poke inside outBytes else cout << "fail\n";

Ritesh
  • 1,809
  • 1
  • 14
  • 16
  • CkGzip gzip; bool success; CkByteData data; char buffer[100] = {0}; success = gzip.CompressString("helloworld", "utf8", data); data = buffer; cout << buffer; if (success != true) { printf("%s\n", gzip.lastErrorText()); return; } i tried in this way but i guess i am wrong somewhere. – lotus Aug 25 '15 at 12:40
  • You do not need char buffer[100] = {0}; Rather you need to do use CkByteData api const unsigned char *getBytes(void); you should call data.getBytes to get the compressed buffer. To get the length of the compressed buffer, call something like data.getSize(); – Ritesh Aug 25 '15 at 14:44