{"name":"compression","version":"1.7.4","license":"MIT","_id":"compression@1.7.4","maintainers":[{"name":"dougwilson","email":"doug@somethingdoug.com"}],"contributors":[{"name":"Douglas Christopher Wilson","email":"doug@somethingdoug.com"},{"url":"http://jongleberry.com","name":"Jonathan Ong","email":"me@jongleberry.com"}],"homepage":"https://github.com/expressjs/compression#readme","bugs":{"url":"https://github.com/expressjs/compression/issues"},"dist":{"shasum":"95523eff170ca57c29a0ca41e6fe131f41e5bb8f","tarball":"http://registry-npm.ywwl.com/compression/download/compression-1.7.4.tgz","fileCount":5,"integrity":"sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==","signatures":[{"sig":"MEQCIFZg9vOvNJ6C7tUgL0/ZVqJ7Nv3aWCSrcgru+lJ1PXs1AiACKX62yShyDOgHTcq6xeqnyLzlr93nx/Q9zONhiNo/gQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":23306,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcj66MCRA9TVsSAnZWagAA5VcP/R4JRuhO78tvsnnBepBz\nzSdSm0onNd0iQp8ajRSpcrd3D1r0eYcQDe8qYraO9tTdzISngweiOZnrp3v/\nitiqTfINI0cFgffUe0LD6ZHP4hnerj04z6NQ3k1Ayr0yEywjLErjznuy+f4U\nznor4SRG8fb5fjel4VJXSVSpq5A7pisGJbb7tw5Bh8n/GQUm3i9bGBL7QRb3\nf++/H1YxTjQoMxMupbvZ6bDvBVVFKl6OLebi4lfVRSoLxKd0+F2KeZ0D1VzH\niZIPgjo5ojAzgmBlDD62dHcg7vwNSFT1UV8U0A6yDSx90hqDUqBK8f2oOL+C\n7mObbeSLqsgspXmM/evEIpkIcF0VeSDf44ClH2u5lAkNb07kf5CevOnRWs/o\nTneqN8c6hMEIriNY7xun9tX6837VRXn9/F98NdcSTiT3lidEMC4y5tXWikSE\n6FAXlJmutIiRNi8LOR50UqPGiWeFNCSVIgPGKBk1jHN78WbkXgvfSFvrRoB8\nj2eY/cK+9RmeXJrzG1oUdEDGHqTpHC0TkKmL0aZyOUEftby8bgEMP9wWa1z+\nGJTueAVQzeu3BCQEkMDiQoxVRoM1E9n8oZDm6CE1sTTmPtCk3rMQMmovpJWs\nrL10koK/Asp7oB3JctY5De2icreXAi08Mytf9pHh+Wibo0XIpxh23Y/BD6TR\nwaMv\r\n=n7iJ\r\n-----END PGP SIGNATURE-----\r\n","size":7824,"noattachment":false,"key":"/compression/-/compression-1.7.4.tgz"},"engines":{"node":">= 0.8.0"},"gitHead":"dd5055dc92fdeacad706972c4fcf3a7ff10066ef","scripts":{"lint":"eslint --plugin markdown --ext js,md .","test":"mocha --check-leaks --reporter spec --bail","test-cov":"istanbul cover node_modules/mocha/bin/_mocha -- --check-leaks --reporter dot","test-travis":"istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --check-leaks --reporter spec"},"_npmUser":{"name":"dougwilson","email":"doug@somethingdoug.com"},"repository":{"url":"git+https://github.com/expressjs/compression.git","type":"git"},"_npmVersion":"6.4.1","description":"Node.js compression middleware","directories":{},"_nodeVersion":"8.15.1","dependencies":{"vary":"~1.1.2","bytes":"3.0.0","debug":"2.6.9","accepts":"~1.3.5","on-headers":"~1.0.2","safe-buffer":"5.1.2","compressible":"~2.0.16"},"_hasShrinkwrap":false,"devDependencies":{"after":"0.8.2","mocha":"6.0.2","eslint":"5.15.1","istanbul":"0.4.5","supertest":"4.0.0","eslint-plugin-node":"7.0.1","eslint-plugin-import":"2.16.0","eslint-plugin-promise":"4.0.1","eslint-config-standard":"12.0.0","eslint-plugin-markdown":"1.0.0","eslint-plugin-standard":"4.0.0"},"_npmOperationalInternal":{"tmp":"tmp/compression_1.7.4_1552920204067_0.8065650793323169","host":"s3://npm-registry-packages"},"readme":"# compression\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Build Status][travis-image]][travis-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n\nNode.js compression middleware.\n\nThe following compression codings are supported:\n\n  - deflate\n  - gzip\n\n## Install\n\nThis is a [Node.js](https://nodejs.org/en/) module available through the\n[npm registry](https://www.npmjs.com/). Installation is done using the\n[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):\n\n```bash\n$ npm install compression\n```\n\n## API\n\n<!-- eslint-disable no-unused-vars -->\n\n```js\nvar compression = require('compression')\n```\n\n### compression([options])\n\nReturns the compression middleware using the given `options`. The middleware\nwill attempt to compress response bodies for all request that traverse through\nthe middleware, based on the given `options`.\n\nThis middleware will never compress responses that include a `Cache-Control`\nheader with the [`no-transform` directive](https://tools.ietf.org/html/rfc7234#section-5.2.2.4),\nas compressing will transform the body.\n\n#### Options\n\n`compression()` accepts these properties in the options object. In addition to\nthose listed below, [zlib](http://nodejs.org/api/zlib.html) options may be\npassed in to the options object.\n\n##### chunkSize\n\nThe default value is `zlib.Z_DEFAULT_CHUNK`, or `16384`.\n\nSee [Node.js documentation](http://nodejs.org/api/zlib.html#zlib_memory_usage_tuning)\nregarding the usage.\n\n##### filter\n\nA function to decide if the response should be considered for compression.\nThis function is called as `filter(req, res)` and is expected to return\n`true` to consider the response for compression, or `false` to not compress\nthe response.\n\nThe default filter function uses the [compressible](https://www.npmjs.com/package/compressible)\nmodule to determine if `res.getHeader('Content-Type')` is compressible.\n\n##### level\n\nThe level of zlib compression to apply to responses. A higher level will result\nin better compression, but will take longer to complete. A lower level will\nresult in less compression, but will be much faster.\n\nThis is an integer in the range of `0` (no compression) to `9` (maximum\ncompression). The special value `-1` can be used to mean the \"default\ncompression level\", which is a default compromise between speed and\ncompression (currently equivalent to level 6).\n\n  - `-1` Default compression level (also `zlib.Z_DEFAULT_COMPRESSION`).\n  - `0` No compression (also `zlib.Z_NO_COMPRESSION`).\n  - `1` Fastest compression (also `zlib.Z_BEST_SPEED`).\n  - `2`\n  - `3`\n  - `4`\n  - `5`\n  - `6` (currently what `zlib.Z_DEFAULT_COMPRESSION` points to).\n  - `7`\n  - `8`\n  - `9` Best compression (also `zlib.Z_BEST_COMPRESSION`).\n\nThe default value is `zlib.Z_DEFAULT_COMPRESSION`, or `-1`.\n\n**Note** in the list above, `zlib` is from `zlib = require('zlib')`.\n\n##### memLevel\n\nThis specifies how much memory should be allocated for the internal compression\nstate and is an integer in the range of `1` (minimum level) and `9` (maximum\nlevel).\n\nThe default value is `zlib.Z_DEFAULT_MEMLEVEL`, or `8`.\n\nSee [Node.js documentation](http://nodejs.org/api/zlib.html#zlib_memory_usage_tuning)\nregarding the usage.\n\n##### strategy\n\nThis is used to tune the compression algorithm. This value only affects the\ncompression ratio, not the correctness of the compressed output, even if it\nis not set appropriately.\n\n  - `zlib.Z_DEFAULT_STRATEGY` Use for normal data.\n  - `zlib.Z_FILTERED` Use for data produced by a filter (or predictor).\n    Filtered data consists mostly of small values with a somewhat random\n    distribution. In this case, the compression algorithm is tuned to\n    compress them better. The effect is to force more Huffman coding and less\n    string matching; it is somewhat intermediate between `zlib.Z_DEFAULT_STRATEGY`\n    and `zlib.Z_HUFFMAN_ONLY`.\n  - `zlib.Z_FIXED` Use to prevent the use of dynamic Huffman codes, allowing\n    for a simpler decoder for special applications.\n  - `zlib.Z_HUFFMAN_ONLY` Use to force Huffman encoding only (no string match).\n  - `zlib.Z_RLE` Use to limit match distances to one (run-length encoding).\n    This is designed to be almost as fast as `zlib.Z_HUFFMAN_ONLY`, but give\n    better compression for PNG image data.\n\n**Note** in the list above, `zlib` is from `zlib = require('zlib')`.\n\n##### threshold\n\nThe byte threshold for the response body size before compression is considered\nfor the response, defaults to `1kb`. This is a number of bytes or any string\naccepted by the [bytes](https://www.npmjs.com/package/bytes) module.\n\n**Note** this is only an advisory setting; if the response size cannot be determined\nat the time the response headers are written, then it is assumed the response is\n_over_ the threshold. To guarantee the response size can be determined, be sure\nset a `Content-Length` response header.\n\n##### windowBits\n\nThe default value is `zlib.Z_DEFAULT_WINDOWBITS`, or `15`.\n\nSee [Node.js documentation](http://nodejs.org/api/zlib.html#zlib_memory_usage_tuning)\nregarding the usage.\n\n#### .filter\n\nThe default `filter` function. This is used to construct a custom filter\nfunction that is an extension of the default function.\n\n```js\nvar compression = require('compression')\nvar express = require('express')\n\nvar app = express()\napp.use(compression({ filter: shouldCompress }))\n\nfunction shouldCompress (req, res) {\n  if (req.headers['x-no-compression']) {\n    // don't compress responses with this request header\n    return false\n  }\n\n  // fallback to standard filter function\n  return compression.filter(req, res)\n}\n```\n\n### res.flush\n\nThis module adds a `res.flush()` method to force the partially-compressed\nresponse to be flushed to the client.\n\n## Examples\n\n### express/connect\n\nWhen using this module with express or connect, simply `app.use` the module as\nhigh as you like. Requests that pass through the middleware will be compressed.\n\n```js\nvar compression = require('compression')\nvar express = require('express')\n\nvar app = express()\n\n// compress all responses\napp.use(compression())\n\n// add all routes\n```\n\n### Server-Sent Events\n\nBecause of the nature of compression this module does not work out of the box\nwith server-sent events. To compress content, a window of the output needs to\nbe buffered up in order to get good compression. Typically when using server-sent\nevents, there are certain block of data that need to reach the client.\n\nYou can achieve this by calling `res.flush()` when you need the data written to\nactually make it to the client.\n\n```js\nvar compression = require('compression')\nvar express = require('express')\n\nvar app = express()\n\n// compress responses\napp.use(compression())\n\n// server-sent event stream\napp.get('/events', function (req, res) {\n  res.setHeader('Content-Type', 'text/event-stream')\n  res.setHeader('Cache-Control', 'no-cache')\n\n  // send a ping approx every 2 seconds\n  var timer = setInterval(function () {\n    res.write('data: ping\\n\\n')\n\n    // !!! this is the important part\n    res.flush()\n  }, 2000)\n\n  res.on('close', function () {\n    clearInterval(timer)\n  })\n})\n```\n\n## License\n\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/compression.svg\n[npm-url]: https://npmjs.org/package/compression\n[travis-image]: https://img.shields.io/travis/expressjs/compression/master.svg\n[travis-url]: https://travis-ci.org/expressjs/compression\n[coveralls-image]: https://img.shields.io/coveralls/expressjs/compression/master.svg\n[coveralls-url]: https://coveralls.io/r/expressjs/compression?branch=master\n[downloads-image]: https://img.shields.io/npm/dm/compression.svg\n[downloads-url]: https://npmjs.org/package/compression\n","publish_time":1552920204201,"_cnpm_publish_time":1552920204201,"dist-tags":{"latest":"1.8.2"}}