Skip to main content
Version: 2025.2

pack

Methods

addMultiToZip

addMultiToZip(pZipFile, pEntries): void

Adds multiple files to a zip file.

Parameters

pZipFile
string | number | boolean

The path to the zip file.

pEntries
any

The entries to be added, as a map: entries[key] = value. key: the path in the zip file, value: the data.

Returns

void

Throws

May throw an exception.

Example

var toZip = {};
toZip["offer.pdf"] = // Here, execute fileIO.getData()
toZip["conditions.txt"] = // Here, execute fileIO.getData()
pack.addMultiToZip("c:\offer_20180102.zip", toZip);

addToZip

addToZip(pZipFile, pPathInFile, pBytes): void

Adds more files to a zip file on the server.

To perform this action on the client, please use the swing.doClientIntermediate() methods with the swing.CLIENTCMD_ADDTOZIP client command.

If the zip file does not exist yet, it will be created.

Parameters

pZipFile
string | number | boolean

The path to the zip file.

pPathInFile
string | number | boolean

The path within the zip file to which the added file will be saved.

pBytes
string | number | boolean

The data to be added to the zip file, Base64-encoded as well.

Returns

void

Throws

May throw an exception.

Example

var file = question.askQuestion("Which zip file?", question.QUESTION_FILECHOOSER, "");
if (file != null)
{
var infile = question.askQuestion("Which file to add?", question.QUESTION_FILECHOOSER, "");

if (infile != null)
{
var data = swing.doClientIntermediate(swing.CLIENTCMD_GETDATA, new Array(infile, util.DATA_BINARY));
var newzip = pack.addToZip(file, "offer20180102/offer.doc", data);
}

}

deflate

deflate(pOrginalBytes): string

Compresses the bytes you passed using the DEFLATE algorithm.

Parameters

pOrginalBytes
string | number | boolean

The data to be compressed (Base64 encoded).

Returns

string

The packed data (Base64 encoded).

Throws

May throw an exception.

Example

var file = question.askQuestion("Which file?", question.QUESTION_FILECHOOSER, "");
var data = swing.doClientIntermediate(swing.CLIENTCMD_GETDATA, [file, util.DATA_BINARY]);
question.showMessage(data.length);

var zData = pack.deflate(data);
question.showMessage(zData.length);

var uData = pack.inflate(zData);
question.showMessage(uData.length == data.length);

getFromZip

getFromZip(pZipFile, pPathInFile): string

Extracts a file from a zip archive.

Parameters

pZipFile
string | number | boolean

The path to the Base64-encoded zip file.

pPathInFile
string | number | boolean

The path within the zip file from where to extract the other file.

Returns

string

The data or 'null' if the file or entry does not exist.

Throws

May throw an exception.

Example

var file = question.askQuestion("Which zip file?", question.QUESTION_FILECHOOSER, "");

if (file != null)
{
var fileinzipname = question.askQuestion("Name of the file?", question.QUESTION_EDIT, "");
// For the sake of simplicity, no check for null
var extractFile = pack.getFromZip(file, fileinzipname);
var dirToStore = question.askQuestion("Location for saving?", question.QUESTION_FILECHOOSER, "");

swing.doClientIntermediate(swing.CLIENTCMD_STOREDATA, new Array(dirToStore, extractfFile, util.DATA_BINARY, false, "UTF-8"));
}

getZipEntries

getZipEntries(pZipFile): string[]

This method returns the names of the entries within a zip file.

Parameters

pZipFile
string | number | boolean

The path to the Base64-encoded zip file.

Returns

string[]

The names of the zip entries, or 'null' if the zip file does not exist.

Throws

May throw an exception.

Example

var file = question.askQuestion("Which zip file?", question.QUESTION_FILECHOOSER, "");
if (file != null)
{
var zipcontent = pack.getZipEntries(file);
question.showMessage(zipcontent.join("\n"));
}

gunzip

gunzip(pZippedBytes): string

Unpacks the gzip-compressed data you passed.

Parameters

pZippedBytes
string | number | boolean

The zipped data (Base64-encoded).

Returns

string

The unzipped data (Base64-encoded).

Throws

May throw an exception.

Example

var zipped = db.cell("SELECT BINDATA FROM ASYS_BINARIES WHERE ID = 'a13f-789bd'");
var unzipped = pack.gunzip(zipped);

gzip

gzip(pUnzippedBytes): string

Zips the data you passed.

Parameters

pUnzippedBytes
string | number | boolean

The uncompressed data (Base64-encoded).

Returns

string

The compressed data (Base64-encoded).

Throws

May throw an exception.

Example

var fname = question.askQuestion("Which file?", question.QUESTION_FILECHOOSER, "");
var data = swing.doClientIntermediate(swing.CLIENTCMD_GETDATA, [fname, util.DATA_BINARY]);
var zipped = pack.gzip(data);

inflate

inflate(pCompressedBytes): string

Decompresses the bytes you passed. They must have been compressed using the DEFLATE algorithm.

Parameters

pCompressedBytes
string | number | boolean

The data to be decompressed.

Returns

string

The unzipped data (Base64-encoded).

Throws

May throw an exception.

Example

var file = question.askQuestion("Which file?", question.QUESTION_FILECHOOSER, "");
var data = swing.doClientIntermediate(swing.CLIENTCMD_GETDATA, [file, util.DATA_BINARY]);
question.showMessage(data.length);

var zData = pack.deflate(data);
question.showMessage(zData.length);

var uData = pack.inflate(zData);
question.showMessage(uData.length == data.length);

isGzipped

isGzipped(pBase64): boolean

Indicates whether a binary value that was passed (as Base64) was compressed with GZIP or not.

Parameters

pBase64
string | number | boolean

The Base64-encoded data.

Returns

boolean

'true' if the data were compressed using GZIP; otherwise 'false'.

Throws

May throw an exception.

Example

var file = question.askQuestion("Which file?", question.QUESTION_FILECHOOSER, "");
var data = swing.doClientIntermediate(swing.CLIENTCMD_GETDATA, [file, util.DATA_BINARY]);
question.showMessage(pack.isGzipped(data));

data = pack.gzip(data);
question.showMessage(pack.isGzipped(data));