📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

json-pack-gzip

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-pack-gzip

A module for compressing and decompressing JSON data using Gzip compression algorithm and HPack compression algorithm.

1.2.1
Source
npm
Version published
Weekly downloads
10
100%
Maintainers
1
Weekly downloads
 
Created
Source

json-pack-gzip

A module for compressing and decompressing JSON data using Gzip compression algorithm and HPack compression algorithm.

Installation

Use the package manager npm to install json-pack-gzip.

npm install json-pack-gzip

Usage

const jsonPackGzip = require('json-pack-gzip');

// Compress JSON data
const compressedData = jsonPackGzip.compress(jsonObject);

// Decompress JSON data
const decompressedData = jsonPackGzip.decompress(jsonBuffer);

// Calculate byte length of data
const byteLength = jsonPackGzip.calculateSize(data);

API

compress(jsonObject, debug = false)

Compresses a JSON object using Gzip compression algorithm. The input JSON object is first packed into a homogeneous array and then stringified before compression.

  • jsonObject(Array): The JSON object to be compressed.
  • debug(Boolean): options for debugging, defaults to false.

Returns a compressed data as a Buffer object.

decompress(jsonBuffer, debug = false)

Decompresses a Buffer object to a JSON object using Gzip decompression algorithm. The decompressed data is first parsed from a homogeneous array into a list of objects.

  • jsonBuffer (Buffer): The Buffer object to be decompressed.
  • debug(Boolean): options for debugging, defaults to false.

Returns a decompressed and unpacked JSON object as a list of objects.

calculateSize(data)

Calculates the byte length of the input data. It supports data types: String, Buffer, Array, and Object. For non-buffer objects, the function first stringifies them before calculating the size.

  • data (String|Buffer|Object|Array): The data to be size-calculated.

Returns the byte length of the input data.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

This module is licensed under the MIT License

Keywords

JSON

FAQs

Package last updated on 30 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts