compressed
a tiny JSON compression lib with great power.
Install
npm install compressed
Compression Ratio
Demo by compressing a 3.1M json response from Hubspot demo sandbox.
[String Length]
Original String Length (3252404)
Packed String Length (190816)
Size Ratio: 0.058 to Orinial. Compressed about 17x in string length!
[File Size]
Original File Size (3252437)
Compressed Packed File Size (143111)
Size Ratio: 0.044 to Orinial. Compressed about 22x in file size!
API
pack(originalJSON [, bufferMode = false])
Compress an Object|Array|JSON string
into compressed base64 string.
- originalJSON {any} a JSON
string|Buffer|Array|Object
. - bufferMode {bool} [Optional, default = false] directly output the buffer without converting to string.
@async This is an async funtion and returns a promise.
- @returns {Promise} a compressed string in base64 encoding.
unpack(packedJSON [, bufferMode = false])
Unpack an compressed Buffer back into JSON string
- packedJSON {string} the compressed base64 JSON string.
- bufferMode {bool} [Optional, default = false] if packedJSON is a buffer from
pack()
in bufferMode. @async This is an async funtion and returns a promise.
- @returns {Promise} a JSON string in utf8 encoding. */
Example
const comp = ; // Promise Stylecomp; // eJyrVkpUsjLUUVBKUrIyAlLJSlZKafn5SrUASpgGHA== comp; // {"a":1, "b":2, "c":"foo"} // Async/Awaitconst packed = await comp;const unpacked = await comp;
License
Licensed under MIT Copyright (c) 2017 Phoenix Song