how to send multiple previously compressed files in a single http response to be consumed by a script?

707 views Asked by At

We have a scenario where we are sending multiple json files in a single response. These json files are stored as separate blobs in the backend (aerospike blobstore) and are fetched dynamically in response to a single request.

As long as we send these blobs uncompressed its working fine. i.e. we add a separator after each blob and use this separator to isolate each json blob something like this -

{
// first json here
}
-- JSONEND--blobid1

{
// second json here
}
-- JSONEND--blobid2

and so on.

As long as the blobs are uncompressed from the source i.e. blob store it works fine and we are able to isolate each json in javascript into a separate variable after parsing.

But our challenge is - these blobs are precompressed and saved into the blobstore for various reasons (performance / reduced diskspace ) and we want to simply send these compressed blobs in one response to the client. Scripts on client side use these blobs and parse them into separate json object trees.

Is this possible ? how ? We need to support only chrome and possibly firefox.

2

There are 2 answers

0
AudioBubble On

this is correct answer:

gzlog.c
gzlog.h
    efficiently and robustly maintain a message log file in gzip format
    - illustrates use of raw deflate, Z_PARTIAL_FLUSH, deflatePrime(),
      and deflateSetDictionary()
    - illustrates use of a gzip header extra field

OR

zpipe.c
    reads and writes zlib streams from stdin to stdout
    - illustrates the proper use of deflate() and inflate()
    - deeply commented in zlib_how.html (see above)

OR

zran.c
    index a zlib or gzip stream and randomly access it
    - illustrates the use of Z_BLOCK, inflatePrime(), and
      inflateSetDictionary() to provide random access
2
аlex On

if you using Gzip and you have a nodejs server

see here, how to use gzjoin

gzjoin.c
    join gzip files without recalculating the crc or recompressing
    - illustrates the use of the Z_BLOCK flush parameter for inflate()
    - illustrates the use of crc32_combine()

https://github.com/nodejs/node/tree/master/deps/zlib/examples

Zlib documentation: https://nodejs.org/api/zlib.html#zlib_zlib