npm points-compressor
Install
$ npm install points-compressor
Usage
in javascript
const ptComp = ; const points = x: 123123 y: 321021 z: 11320001 x: 163222 y: 325322 z: 11350201const compressed = ptComp;const decompressed = ptComp;// R.equals(points, decompressed) must be true// R means ramdajs
in typescript
; ;;// R.equals(points, decompressed) must be true// R means ramdajs
limitation
- left of decimal must be smaller than 65535
- the length of right of decimal must be shorter than 5
453.44
,65000.4444
,1.0123
ok77777.1
,123.22223
not ok
Why?
- In my case, this limitation is enough to represent all data
- And it is very easy to implement the functions with such limitations.
- But if you want to exceed such limitation, please let me know by leaving issue on the Github repo.
Compression performance
- 10% ~ 15%
- 4.6kb to 0.6kb
- check by running
npm run test
Introduction
In many case of javascript applications, it is common to send arbitrary data using JSON.stringify.
And it is often inefficient to stringify a data which contains numbers.
For example
let num = 5555555;
The variable above occupies at most 4byte in memory.
let num2 = '5555.555';
But num2
occupies at least 16bytes(8 characters, 2bytes each character).
In my case, there are many number
s in message packet. So it is necessary to compress that kind of packets.
Point
let point1 = 'x': 111234 'y': 145501 'z': 1993134;
Interfaces
compress
string;
decompress
Point;