rapidjson icon indicating copy to clipboard operation
rapidjson copied to clipboard

add gzfilereadstream (zlib reader)

Open vindex10 opened this issue 5 years ago • 5 comments

Add support for reading directly from gzipped file:

Example:

Input json:

{"a": 1, "x": 10, "y": [1,2,3], "m": {"c": "z"}}

Test:

#include <iostream>
#include <zlib.h>

#include "rapidjson/document.h"
#include "rapidjson/gzfilereadstream.h"

using namespace rapidjson;
using namespace std;

int main(int argc, char* argv[]) {
    gzFile_s* fp = gzopen(argv[1], "r");

    char readBuffer[65536];
    GzFileReadStream is(fp, readBuffer, sizeof(readBuffer));

    Document d;
    d.ParseStream(is);
    cout << d["m"].GetObject()["c"].GetString() << endl;

    gzclose(fp);
    return 0;
}

NOTE: compile with -lz: g++ -lz main.cpp

vindex10 avatar Jul 04 '20 12:07 vindex10

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

tencent-adm avatar Jul 04 '20 12:07 tencent-adm

Coverage Status

Coverage increased (+0.0001%) to 99.739% when pulling fb45704458d03c601e157db4ddf8426549654333 on vindex10:feature/add_gzfilestream into 88bd956d66d348f478bceebfdadb8e26c6844695 on Tencent:master.

coveralls avatar Jul 04 '20 13:07 coveralls

I think including this in the main library will add extra dependency to this project. I suggest moving this to /contrib/gzip/. What do you think?

miloyip avatar Aug 06 '20 06:08 miloyip

What is the status of this PR? The code seems to work fine, so we'd like to pick this change up, that's easier when it's merged :-) . Thanks in advance

pieterdavid avatar Oct 21 '21 14:10 pieterdavid

I have trouble signing the agreement. The page doesn't open for me

vindex10 avatar Oct 21 '21 21:10 vindex10