4.0.1 • Published 9 months ago

set-compressor v4.0.1

Weekly downloads
121
License
MIT
Repository
github
Last release
9 months ago

Set-Compressor

Build Status Test Coverage Dependabot Status Dependencies NPM Downloads Semantic-Release Gardener

Compress and decompress Sets of non-negative Integers.

Getting Started

$ npm install --save set-compressor

Usage

Consider an sequential array with gaps of the form [0, 1, 2, ..., 498, 499, 500, 700, 701, 702, ..., 998, 999, 1000]. We want to store this efficiently. This is where this utility comes in handy.

const compressor = require('set-compressor').Compressor({/* options */});

compressor.compress([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
// => /wc=

compressor.decompress('/wc=');
// => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Further examples can be found below.

Compressor

Options

The following options can be passed in when creating a Compressor.

gzip

Type: constants.GZIP_MODE Default: AUTO

Controls how to use gzip: AUTO, FORCE and NEVER, where the default only uses compression if it improves the result size.

gzipLevel

Type: zlib.constants Default: Z_BEST_COMPRESSION

Can be set to control the gzip compression level.

Functions

The following functions are available on the created Compressor.

compress(\<iterable>)

Takes Iterable of non-negative Integers as input and returns compressed string.

decompress(\<string>)

Takes compressed string as input and returns Array of unique, non-negative, sorted Integers.

Constants

GZIP_MODE

Values AUTO, NEVER, FORCE

Defines gzip mode used internally.

Examples

const compressor = require('set-compressor').Compressor({/* options */});

compressor.compress([0, 1, 2, /* ..., */ 9998, 9999, 10000]);
// => "H4sIAAAAAAACA/v/fxSMglEwCoYrYAAAhHk44+MEAIA="

compressor.decompress('H4sIAAAAAAACA/v/fxSMglEwCoYrYAAAhHk44+MEAIA=');
// => [0, 1, 2, ..., 9998, 9999, 10000]

compressor.decompress(compressor.compress([2, 2, 5, 1, 0]));
// => [0, 1, 2, 5]

Gotchas and Lmitations

This library operates with Arrays for performance reasons.

Any iterable containing non-negative integers can be provided as input, but re-inflating always outputs a unique and ordered Array.

This library is not meant to be used with and wont work well with huge Integers.

4.0.1

9 months ago

4.0.0

9 months ago

3.0.0

2 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.1.29

3 years ago

1.1.28

3 years ago

1.1.27

3 years ago

1.1.26

4 years ago

1.1.25

4 years ago

1.1.24

4 years ago

1.1.23

4 years ago

1.1.22

4 years ago

1.1.21

4 years ago

1.1.20

4 years ago

1.1.19

4 years ago

1.1.18

4 years ago

1.1.17

5 years ago

1.1.16

5 years ago

1.1.15

5 years ago

1.1.14

5 years ago

1.1.13

5 years ago

1.1.12

5 years ago

1.1.11

5 years ago

1.1.10

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago