Compression ​
Collection of compression functions.
Methods ​
gzip ​
gzip(data: string)Compresses a string using GZIP.
Parameters
data string
The data to compress.
Return type
string
Examples
// Compress a string using GZIP
Compression.gzip('Hello, world!')gunzip ​
gunzip(data: string)Decompresses a string using GZIP.
Parameters
data string
The data to decompress.
Return type
string
Examples
// Decompress a string using gzip
Compression.gunzip('H4sIAAAAAAAA/8tIzcnJVyjPL8pJUQQAlK4JWgAAAA==')unzip ​
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
// 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 filezip ​
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
// 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!'