Skip to content
This repository has been archived by the owner on Feb 28, 2020. It is now read-only.

Unable to read gzipped data from v1.financeReports #3

Open
christianbueschi opened this issue Feb 4, 2019 · 1 comment
Open

Unable to read gzipped data from v1.financeReports #3

christianbueschi opened this issue Feb 4, 2019 · 1 comment

Comments

@christianbueschi
Copy link

First of all, thank you for this awesome library. It's exactly what I was looking for!

Now I'm trying to get fincanceReports without any success! The response is a-gzip encoded and I don't know how to decode it by using nodes zlib module. I'm getting the error: Error: unexpected end of file. This is the adjusted code of the request:

async function call(api, path, method, options = {}) {
    let rawResponse;
    try {
        rawResponse = await got_1.default(path, {
            baseUrl: api.baseUrl,
            method,
            decompress: true,
            headers:
                 {
                    'Authorization': "Bearer" + api.token",
                    'Accept': '*/*',
                    'Content-Type': 'application/a-gzip',
                    'Accept-Encoding' : 'agzip, deflate',
                },
            query: query(options.query),
            body: options.body && JSON.stringify(options.body),
        });
    }
    catch (error) {
        throw new Error(error.response.body);
    }
    try {
        var buffer = [];
        var gunzip = zlib.createGunzip();            
        rawResponse.pipe(gunzip);
        gunzip.on('data', function(data) {
            // decompression chunk ready, add it to the buffer
            console.log(data.toString());
            buffer.push(data.toString())
        }).on("end", function() {
            // response and decompression complete, join the buffer and return
            buffer.join(""); 
            console.log(buffer);
        }).on("error", function(e) {
            console.log(e);
        })
    }
    catch (jsonError) {
        throw jsonError;
    }
    return json;
}

When I test the request with Postman I get the same response but I can then download the file over postman's UI and get a file.txt.gz. When I unzip that, I get a readable text file with the financeReport.

Do you have any idea what I am missing here?

@aaronsky
Copy link
Owner

I just put out a change in 0.2.1 that should make it easier to consume the compressed data. appstoreconnect will return a Buffer when hitting one of the two gzip endpoints. Could you try it out?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants