Skip to content
v2.7 (latest)

Compression ​

Collection of compression functions.

Methods ​

gzip ​

javascript
gzip(data: string)

Compresses a string using GZIP.

Parameters

data string

The data to compress.

Return type

string

Examples

javascript
// Compress a string using GZIP
Compression.gzip('Hello, world!')

gunzip ​

javascript
gunzip(data: string)

Decompresses a string using GZIP.

Parameters

data string

The data to decompress.

Return type

string

Examples

javascript
// Decompress a string using gzip
Compression.gunzip('H4sIAAAAAAAA/8tIzcnJVyjPL8pJUQQAlK4JWgAAAA==')

unzip ​

javascript
unzip(data: string)

Unzips a zip archive and returns the files within the archive. The data of each file is returned as a base64 string, since it is possible a file is binary (e.g. images, PDFs). To get the string contents you will need to decode it using atob() to get the original string contents.

Parameters

data string

The zip archive data to unzip as a base64 string.

Return type

{ files: System.File[] }

Examples

javascript
// Unzip a zip archive
let directory = Compression.unzip('...base64 zip data...')
let fileContents = atob(directory.files[0].data)            // Decode base64 to string of the first file

zip ​

javascript
zip(files: System.File[])

Creates a zip archive from the given files. The data of each file should be provided as a base64 string.

Parameters

files System.File[]

The files to be added to the zip archive.

Return type

string

Examples

javascript
// Create a zip archive from files
let zipData = Compression.zip([ { name: 'hello.txt', data: btoa('Hello world!') } ])    // Create zip archive with a single file 'hello.txt' with string content 'Hello world!'