Foxx external API: compress (zip) json data for POST

34 views
Skip to first unread message

Benjamin Corliss

unread,
Sep 10, 2015, 2:07:08 PM9/10/15
to ArangoDB
Context: I'm publishing the results of a query to an external (proprietary) db with a rest API from a Foxx app.  It's max payload size is 20MB but it accepts gzip as a content-type.  My uncompressed JSON is bigger than the max payload, so I want to compress.  
Question: I know how to compress a payload node/express - but how do I compress the payload in Foxx?

Jan

unread,
Sep 14, 2015, 7:21:23 AM9/14/15
to ArangoDB
Hi,

it's possible to zip a file using the following command:

    require("fs").zipFile("/path/to/outfile", "/path/to/source/directory", [ "file1", "file2", ... ]);

for example, to zip the contents of file "/tmp/test" into "/tmp/out.zip":

    require("fs").zipFile("/tmp/out.zip", "/tmp", [ "test" ]);

The zipped file could then be sent from Foxx to a client application via

    response.sendFile("/tmp/out.zip", { });

or be sent to a remote API using

    require("internal").download(remoteUrl, require("fs").readBuffer("/tmp/out.zip"), { method: "post" });

or something similar.

That is zip and not gzip, but maybe it helps anyway. I think there is no gzip function exposed in Foxx, but it could be added if necessary.

Best regards
J

CoDEmanX

unread,
Sep 16, 2015, 8:45:33 AM9/16/15
to ArangoDB
Support for streamed gzip would be nifty, so that no temporary file is written to disk.
It would be used like this:

    require("internal").download(remoteUrl, gzipStream("/path/to/source/directory", [ "file1", "file2", ... ]), { method: "post" });

Maybe another paramter is needed to set the download name.
Reply all
Reply to author
Forward
0 new messages