json-shrink

0.0.124 • Public • Published

json-shrink

shrink objects/json with LZMA (7-zip) or Brotli compression + optional jsonpack

var shrunken = shrink(obj, outputAsString = false, doPack = true, doUseBrotli = false);
var unshrunk = unshrink(shrunken, doUnPack = true, doUseBrotli = false);

Installation

npm i json-shrink

Usage

var jsh = require('json-shrink');
var shrink = jsh.shrink;
var unshrink = jsh.unshrink;

//compressing json into buffer or string:
//shrink(obj, outputAsString = false, doPack = true, doUseBrotli=false)
var original_obj = {ok:"here is some text"};
var compressed_into_buffer = shrink(original_obj); //output as buffer
var compressed_into_string = shrink(original_obj, true); // output as base64 string

//uncompressing
//note - params used for uncompressing must align with the params used for compressing!
//unshrink(shrunken, doUnPack = true, doUseBrotli=false);
console.log("uncompressed str", unshrink(compressed_into_string));
console.log("uncompressed buffer", unshrink(compressed_into_buffer));

//result
//uncompressed str { ok: 'here is some text' }
//uncompressed buffer { ok: 'here is some text' }

Usage - jsonpack disabled

//with jsonpack disabled:
var compressed_buffer_nopack = shrink(original_obj, false, false);
var compressed_string_nopack = shrink(original_obj, true, false);

console.log("uncompressed str - no jsonpack", unshrink(compressed_string_nopack, false));
console.log("uncompressed buffer - no jsonpack", unshrink(compressed_buffer_nopack, false));

//result
//uncompressed str - no jsonpack { ok: 'here is some text' }
//uncompressed buffer - no jsonpack { ok: 'here is some text' }

See Also

stonks

Package Sidebar

Install

npm i json-shrink

Weekly Downloads

310

Version

0.0.124

License

MIT

Unpacked Size

7.09 kB

Total Files

5

Last publish

Collaborators

  • stonkpunk