1.0.2 • Published 7 years ago

compress-str v1.0.2

Weekly downloads
47
License
MIT
Repository
github
Last release
7 years ago

Compress-Str

Base on "zlib" module to compress string - base64 for database saving (redis or mongodb ...). Support both callback and native Promise

Build status

Notice

gzip function is a high CPU consumption, not support to use at high I/O case.

Installation

$ npm install compress-str

Example

'use strict'

var compress = require('compress-str')
var str = 'this_is_a_very_very_very_very_very_very_very_very_very_very_very_very_long_string'

console.log(str.length) // 85

// for callback
compress.gzip(str, function (err, m) {
    if (err) {
        console.error(err)
    } else {
        console.log(m.length) // 45

        compress.gunzip(m, function (err, n) {
            if (err) {
                console.error(err)
            } else {
                console.log(n.length) // 85
                console.log(n === str) // true
            }
        })
    }
})

// for Promise
compress.gzip(str).then(function (m) {
    console.log(m.length) // 45
    return compress.gunzip(m)
}).then(function (n) {
    console.log(n.length) // 85
    console.log(n === str) // true
}).catch(function (err) {
    console.error(err)
})

FAQ

this module use native Promise for node.js v0.12 +, when your node.js version can't support Promise, you may use bluebird or do something yourself with callback

'use strict'

var compress = require('compress-str')
var Promise = require('bluebird')

compress.Promise = Promise
// to do can do well

API

.gzip(string || object, callback)

gzip string (return a Promise when missing callback)

.gunzip(string, callback)

gunzip string from gzip (return a Promise when missing callback)

License

MIT

1.0.2

7 years ago

1.0.1

7 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago

1.0.0

8 years ago