├── .npmignore ├── .gitignore ├── .babelrc ├── src └── index.js ├── package.json ├── LICENSE └── README.md /.npmignore: -------------------------------------------------------------------------------- 1 | src 2 | .babelrc 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.log 3 | dist 4 | lib 5 | node_modules 6 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { 4 | "targets": { 5 | "node": "0.12" 6 | } 7 | }] 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const zlib = require('zlib'); 4 | 5 | module.exports = { 6 | gzip: (input, options) => { 7 | const promise = new Promise(function(resolve, reject) { 8 | zlib.gzip(input, options, function (error, result) { 9 | if(!error) resolve(result); 10 | else reject(Error(error)); 11 | }); 12 | }); 13 | return promise; 14 | }, 15 | ungzip: (input, options) => { 16 | const promise = new Promise(function(resolve, reject) { 17 | zlib.gunzip(input, options, function (error, result) { 18 | if(!error) resolve(result); 19 | else reject(Error(error)); 20 | }); 21 | }); 22 | return promise; 23 | }, 24 | } 25 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-gzip", 3 | "version": "1.1.2", 4 | "description": "Simply gzip and ungzip in Node.js with promises", 5 | "main": "dist/index.js", 6 | "scripts": { 7 | "build": "rm -rf dist && mkdir dist && babel src --out-dir dist" 8 | }, 9 | "author": "Rebsos", 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/Rebsos/node-gzip.git" 13 | }, 14 | "keywords": [ 15 | "node", 16 | "gzip", 17 | "compress", 18 | "promise", 19 | "gunzip", 20 | "ungzip", 21 | "decompress", 22 | "uncompress", 23 | "gz", 24 | "zlib", 25 | "async", 26 | "await", 27 | "promises" 28 | ], 29 | "license": "MIT", 30 | "devDependencies": { 31 | "babel-cli": "^6.26.0", 32 | "babel-preset-env": "^1.6.1" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # node-gzip 2 | > Gzip and ungzip in Node.js 3 | 4 | Tiny and easy to use wrapper around [zlib.gzip](https://nodejs.org/api/zlib.html#zlib_zlib_gzip_buffer_options_callback) and [zlib.gunzip](https://nodejs.org/api/zlib.html#zlib_zlib_gunzip_buffer_options_callback) to support promises. 5 | 6 | ```js 7 | const compressed = await gzip('Hello World'); 8 | ``` 9 | 10 | ## Install 11 | ```sh 12 | npm install node-gzip --save 13 | ``` 14 | 15 | 16 | 17 | ## Examples 18 | 19 | #### With Promises 20 | 21 | ```js 22 | const {gzip, ungzip} = require('node-gzip'); 23 | 24 | gzip('Hello World') 25 | .then((compressed) => { 26 | return ungzip(compressed); 27 | }) 28 | .then((decompressed) => { 29 | console.log(decompressed.toString()); //Hello World 30 | }); 31 | ``` 32 | 33 | #### With async / await 34 | 35 | ```js 36 | const {gzip, ungzip} = require('node-gzip'); 37 | 38 | const compressed = await gzip('Hello World'); 39 | 40 | const decompressed = await ungzip(compressed); 41 | 42 | console.log(decompressed.toString()); //Hello World 43 | ``` 44 | 45 | 46 | 47 | 48 | ## Options 49 | 50 | Pass options just like with [Zlib](https://nodejs.org/api/zlib.html). See all [options](https://nodejs.org/api/zlib.html#zlib_class_options). 51 | 52 | ```js 53 | await gzip('Hello World', {...}); 54 | ``` 55 | 56 | ## Description 57 | 58 | #### gzip(input[,options]) 59 | 60 | * input: `Buffer | TypedArray | DataView | ArrayBuffer | string` 61 | * returns: `Buffer` 62 | 63 | #### ungzip(input[,options]) 64 | 65 | * input: `Buffer | TypedArray | DataView | ArrayBuffer | string` 66 | * returns: `Buffer` 67 | 68 | Use `toString()` after `ungzip` to convert the Buffer into a string. 69 | 70 | Supports Node.js version 0.12 and higher. 71 | 72 | --- 73 | 74 | ### License 75 | 76 | node-gzip is [MIT licensed](./LICENSE). 77 | --------------------------------------------------------------------------------