0

I compressed a json string in gzipped format. But I want to compress a .json file into .json.gz file format. How can I do that in c++?

  • 1
    Does this answer your question? [How do I read / write gzipped files in C++?](https://stackoverflow.com/questions/624250/how-do-i-read-write-gzipped-files-in-c) – tevemadar Jan 15 '21 at 14:46
  • I don't think so. I don't need to read/write gzip files rather need to convert a file into .gz file format. Also I can't use boost gzip . – Mahedi Hasan Jan 15 '21 at 15:31
  • Converting it to .gz format _is_ reading in the json and writing it back out as a gzipped file. So the linked answer is highly relevant. – Mark Adler Jan 15 '21 at 19:00
  • @MarkAdler I got it. For this I will need to use gzstream library. But I cant use external library. Is there any way to do that with c++ std library? – Mahedi Hasan Jan 16 '21 at 05:33
  • Sure. Just copy the source code from [zlib](https://zlib.net/) into your program. – Mark Adler Jan 16 '21 at 06:27

1 Answers1

0

I could compress a file into .gz file in cpp that I needed. Used linux terminal command for file gzip

char Command[] = "gzip filepath/filename.json";

Then executed the command in code by using

int sysRet = system(Command);

Then in device storage desired filepath filename.json.gz file will be created.