@types/compression
- Version 1.8.1
- Published
- 11.6 kB
- 2 dependencies
- MIT license
Install
npm i @types/compressionyarn add @types/compressionpnpm add @types/compressionOverview
TypeScript definitions for compression
Index
Functions
function compression
compression: typeof compression;Returns the compression middleware using the given
options. The middleware will attempt to compress response bodies for all request that traverse through the middleware, based on the givenoptions.This middleware will never compress responses that include a
Cache-Controlheader with theno-transformdirective, as compressing will transform the body.See Also
function filter
filter: (req: express.Request, res: express.Response) => boolean;The default
filterfunction. This is used to construct a custom filter function that is an extension of the default function.var compression = require('compression')var express = require('express')var app = express()app.use(compression({ filter: shouldCompress }))function shouldCompress (req, res) {if (req.headers['x-no-compression']) {// don't compress responses with this request headerreturn false}// fallback to standard filter functionreturn compression.filter(req, res)}See Also
Interfaces
interface CompressionFilter
interface CompressionFilter {}A function to decide if the response should be considered for compression.
call signature
(req: express.Request, res: express.Response): boolean;interface CompressionOptions
interface CompressionOptions {}compression() accepts these properties in the options object. In addition to those listed below,
zliboptions may be passed in to the options object.
property brotli
brotli?: zlib.BrotliOptions | undefined;Options for brotli compression.
property chunkSize
chunkSize?: number | undefined;zlib.constants.Z_DEFAULT_CHUNK or 16384
See Also
property enforceEncoding
enforceEncoding?: string | undefined;This is the default encoding to use when the client does not specify an encoding in the request's Accept-Encoding header. 'identity'
property filter
filter?: CompressionFilter | undefined;A function to decide if the response should be considered for compression. This function is called as
filter(req, res)and is expected to returntrueto consider the response for compression, orfalseto not compress the response.The default filter function uses the
compressiblemodule to determine ifres.getHeader('Content-Type')is compressible.See Also
property level
level?: number | undefined;The level of zlib compression to apply to responses. A higher level will result in better compression, but will take longer to complete. A lower level will result in less compression, but will be much faster.
This is an integer in the range of
0(no compression) to9(maximum compression). The special value-1can be used to mean the "default compression level", which is a default compromise between speed and compression (currently equivalent to level 6).-
-1Default compression level (alsozlib.constants.Z_DEFAULT_COMPRESSION). -0No compression (alsozlib.constants.Z_NO_COMPRESSION). -1Fastest compression (alsozlib.constants.Z_BEST_SPEED). -2-3-4-5-6(currently whatzlib.constants.Z_DEFAULT_COMPRESSIONpoints to). -7-8-9Best compression (alsozlib.constants.Z_BEST_COMPRESSION).**Note** in the list above,
zlibis fromzlib = require('zlib').zlib.constants.DEFAULT_COMPRESSION or -1
See Also
property memLevel
memLevel?: number | undefined;This specifies how much memory should be allocated for the internal compression state and is an integer in the range of
1(minimum level) and9(maximum level).zlib.constants.DEFAULT_MEMLEVEL or 8
See Also
property strategy
strategy?: number | undefined;This is used to tune the compression algorithm. This value only affects the compression ratio, not the correctness of the compressed output, even if it is not set appropriately.
-
zlib.constants.Z_DEFAULT_STRATEGYUse for normal data. -zlib.constants.Z_FILTEREDUse for data produced by a filter (or predictor). Filtered data consists mostly of small values with a somewhat random distribution. In this case, the compression algorithm is tuned to compress them better. The effect is to force more Huffman coding and less string matching; it is somewhat intermediate betweenzlib.constants.Z_DEFAULT_STRATEGYandzlib.constants.Z_HUFFMAN_ONLY. -zlib.constants.Z_FIXEDUse to prevent the use of dynamic Huffman codes, allowing for a simpler decoder for special applications. -zlib.constants.Z_HUFFMAN_ONLYUse to force Huffman encoding only (no string match). -zlib.constants.Z_RLEUse to limit match distances to one (run-length encoding). This is designed to be almost as fast aszlib.constants.Z_HUFFMAN_ONLY, but give better compression for PNG image data.**Note** in the list above,
zlibis fromzlib = require('zlib').
property threshold
threshold?: number | string | undefined;The byte threshold for the response body size before compression is considered for the response, defaults to 1kb. This is a number of bytes or any string accepted by the bytes module.
**Note** this is only an advisory setting; if the response size cannot be determined at the time the response headers are written, then it is assumed the response is *over* the threshold. To guarantee the response size can be determined, be sure set a
Content-Lengthresponse header.See Also
property windowBits
windowBits?: number | undefined;zlib.constants.Z_DEFAULT_WINDOWBITS or 15.
See Also
index signature
[property: string]: any;In addition ,
zliboptions may be passed in to the options object.
Namespaces
namespace global
namespace global {}namespace global.Express
namespace global.Express {}Package Files (1)
Dependencies (2)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/compression.
- Markdown[](https://www.jsdocs.io/package/@types/compression)
- HTML<a href="https://www.jsdocs.io/package/@types/compression"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3513 ms. - Missing or incorrect documentation? Open an issue for this package.
