Skip to content

class util.Zip

Ayhan Rashidov edited this page Sep 5, 2022 · 2 revisions

$.util.Zip Class

Class for manipulation of zip archives. It provides functionality for compressing, uncompressing, removal of entries and zip encryption.

Reference

SAP Help

https://help.sap.com/doc/3de842783af24336b6305a3c0223a369/2.0.03/en-US/$.util.Zip.html

Module

https://github.com/codbex/codbex-kronos/tree/main/modules/api/api-xsjs/src/main/resources/META-INF/dirigible/kronos/util

Sample Usage

Create a new zip object.

// Create a new zip object
var zip = new $.util.Zip();
// Set content to the zip object
zip['kronos.txt'] = 'This is Kronos';

// Download the zip file
$.response.status = $.net.http.OK;
$.response.contentType = 'application/zip';
$.response.headers.set('Content-Disposition', 'attachment; filename = test.zip');
$.response.setBody(zip.asArrayBuffer());

Create a zip object from byte array source.

// Zip byte array source
var source = [123, 34, 120, 115, 107, 46, 116, 120, 116, 34, 58, 34, 84, 104, 105, 115, 32, 105, 115, 32, 88, 83, 75, 34, 125];

var zip = new $.util.Zip({
    source: source
});

for (var entry in zip) {
    // Loop through zip entries and modify if needed
    if (entry === 'kronos.txt') {
        zip[entry] = 'Kronos is great'
    }
}

// Download the zip file
$.response.status = $.net.http.OK;
$.response.contentType = 'application/zip';
$.response.headers.set('Content-Disposition', 'attachment; filename = test.zip');
$.response.setBody(zip.asArrayBuffer());

Constructors

new $.util.Zip(config)

Parameters

  • Zip object
Name Description Type
config Object containing new zip configuration parameters. object
  • config object
Name Description Type
source Specifies the source for the compressed content. If no source is specified, an empty Zip object is created. byte array / $.db.ResultSet / $.web.Body
index If the first argument is of type ResultSet, the number specifies the index of a Blob column and is mandatory. number
settings Used to specify zip options. object
  • settings object
Name Description Type
password The password is mandatory when creating a zip object from an existing encrypted archive. string
maxUncompressedSizeInBytes A global restriction applies to the amount of data that can be uncompressed number

Coverage

Members Type Description Status
metadata object Contains meta information about the current zip object.
password string Setting a value to this property changes the password used for encryption of the zip object. Assigning an empty string disables encryption. Accessing this property will return undefined.
Methods Return Type Description Status
asArrayBuffer() byte array Returns the zip object as byte array.

Unit Tests ⚠️

https://github.com/codbex/codbex-kronos/tree/main/modules/engines/engine-xsjs/src/test/resources/META-INF/dirigible/test/kronos/util

Integration Tests ❌

Wiki icons legend

✅ - Feature implemented and working as supposed.
⚠️ - Feature partially implemented and needs to be finished.
❌ - Feature not implemented yet.

Clone this wiki locally