Socket
Socket
Sign inDemoInstall

compress-integers

Package Overview
Dependencies
4
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    compress-integers

Compress a series of related integers.


Version published
Maintainers
1
Install size
124 kB
Created

Readme

Source

compress-integers

Compress a series of related integers.

NPM version Build Status Build status

Installation

npm i compress-integers -S

Usage

  • on-line
IC = require('compress-integers');
IC.getCompressor({order: 2});
IC.write(10);
IC.write(10);
IC.getResult()
  • off-line shortcut
buffer = IC.compress([1, 2, 3, 4, 5], {order:1});
  • decompress
IC.decompress(buffer);

API

src

  • getCompressor (opts = {})

    Get an order N compressor with options

    • param: opts { Object={} }

      options

    • option: RLE { boolean }

      use Run-Length Encoding

    • option: order { number=1 }

      order of the compressor (0, 1 or 2)

    • return: { Compressor }

      an order N compressor

  • compress (arr, options = {})

    A shortcut for get a Compressor

    • param: arr { Array }

      array of integers

    • param: options { options={} }

      see getCompressor

    • return: { Buffer }

      compressed data

  • decompress (buffer)

    Decompress a buffer to an array of integers

    • param: buffer { Buffer }

      buffer to compress

    • return: { Array }

      array of integers

  • Compressor.write (int)

    write an integer

    • param: int { number }

      integer

  • Compressor.getResult ()

    Get the result buffer

    • return: { Buffer }

      buffer

HOW

  • Integers are encoded with zig-zag variable-length coding using binbone
  • A series of integers are stored as their differences. Order is the number of turns of making difference.
  • Run-length encoding is use to make it better.
  • This algorithm is not suitable for random integers.

For example:

  • [1, 2, 3, 4, 5]

    • order1: [1, 1, 1, 1, 1]
    • order2: [1, 1, 0, 0, 0] The second value is the base value.
  • [1, 1, 1, 1, 1]

    • order1: [1, 0, 0, 0, 0]
    • order2: [1, 0, 0, 0, 0]

Comparison

npm run compare

See result

License

MIT@Jingchen Zhao

FAQs

Last updated on 05 Aug 2015

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc