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: Array<{ name: string, size: number, crc32: number, type: 'File' | 'Directory', dateLastModified: Date, data: string }> }
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 fileLast updated