-
Notifications
You must be signed in to change notification settings - Fork 3
class util.Zip
Ayhan Rashidov edited this page Sep 5, 2022
·
2 revisions
Class for manipulation of zip archives. It provides functionality for compressing, uncompressing, removal of entries and zip encryption.
https://help.sap.com/doc/3de842783af24336b6305a3c0223a369/2.0.03/en-US/$.util.Zip.html
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());
new $.util.Zip(config)
- 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 |
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. | ✅ |
✅ - Feature implemented and working as supposed.
❌ - Feature not implemented yet.