How do I compress and decompress data?
Objective: This article explains how use the compress and decompress utilities.
Example:
import { compress } from '@hectare/platform.components.utils'
const obj = { ... } // Primitive data types only
const json = JSON.stringify(obj)
const data = compress(Jjson)
import { decompress } from '@hectare/platform.components.utils'
const data = '...' // The compressed string
const json = decompress(data)
const obj = JSON.parse(json)
Troubleshooting:
- The decompression fails with a dictionary error: Your input object is too large, try reducing its size.
Related Articles: