1.0.0 • Published 4 years ago
@satellite-earth/parcel v1.0.0
Parcel is a container that gzips any data that can be represented as JSON. Such functionality is important for Satellite's State and Epoch classes since they both need to handle large, highly structured data, and for Client to conserve space in the browser cache.
Usage
const Parcel = require('@satellite-earth/parcel');
// Compress any value that can be represented as json
const parcel = new Parcel({ foo: 'bar' });
console.log(parcel.packed); // <Uint8Array>
// Uncompress data the same way
const parcel2 = new Parcel(compressed);
console.log(parcel.unpacked); // { foo: 'bar' }
Constructor
Object|String|Number|Boolean|Uint8Array
- Uncompressed data to be compressed, or compressed data to be uncompressed.
Properties
ratio
parcel.ratio // 0.618
Number
- ratio between compressed and uncompressed size
bytes
parcel.bytes // 2514924
Number
- Byte length of compressed data
parcel.packed // <Uint8Array>
Uint8Array
- Gzipped data
unpacked
parcel.unpacked // { foo: 'bar' }
Object|String|Number|Boolean
- Parsed, uncompressed JSON
1.0.0
4 years ago