XSJS - Zip Support

In this article we will show you an XSJS example to demonstrate – How to create/read/process ZIP and GZIP archives in XSJS service.
Note: To check all the examples on XSJS, read the article SAP HANA XSJS Examples

Introduction:

The SAP HANA XS JavaScript Utilities API also includes the $.util.Zip tool, which enables you to perform a series of actions on Zip archives, for example:
  • Compress files into (zip) and extract files from (unzip) a Zip archive
  • Add new entries to, update existing entries in, and remove entries from a Zip archive
  • Encrypt Zip archives with password protection
  • The following code illustrates a simple usage of the Zip API.
Example:

Create an XSJS file and paste the below code.

var zip = new $.util.Zip();
zip["file1.txt"] = "This is the first file in ZIP, created by XSJS";
zip["folder1/file2.txt"] = "This is another file created inside folder folder1";
$.response.status = $.net.http.OK;
$.response.contentType = "application/zip";
$.response.headers.set('Content-Disposition', "attachment; filename = 'ZipExample.zip'");
$.response.setBody(zip.asArrayBuffer());

Run XSJS Service:

Run the XSJS service and a zip file will be downloaded with the content mentioned above.

Download Full Source Code:

Click here to download the full source code. Follow the steps mentioned in “How to Run.txt” to run it.

Continue reading:

No comments:

Post a Comment