AK-21/Graphite-Industrial-Intelligence
0
1# etag2 3[![NPM Version][npm-image]][npm-url]4[![NPM Downloads][downloads-image]][downloads-url]5[![Node.js Version][node-version-image]][node-version-url]6[![Build Status][travis-image]][travis-url]7[![Test Coverage][coveralls-image]][coveralls-url]8 9Create simple HTTP ETags10 11This module generates HTTP ETags (as defined in RFC 7232) for use in12HTTP responses.13 14## Installation15 16This is a [Node.js](https://nodejs.org/en/) module available through the17[npm registry](https://www.npmjs.com/). Installation is done using the18[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):19 20```sh21$ npm install etag22```23 24## API25 26<!-- eslint-disable no-unused-vars -->27 28```js29var etag = require('etag')30```31 32### etag(entity, [options])33 34Generate a strong ETag for the given entity. This should be the complete35body of the entity. Strings, `Buffer`s, and `fs.Stats` are accepted. By36default, a strong ETag is generated except for `fs.Stats`, which will37generate a weak ETag (this can be overwritten by `options.weak`).38 39<!-- eslint-disable no-undef -->40 41```js42res.setHeader('ETag', etag(body))43```44 45#### Options46 47`etag` accepts these properties in the options object.48 49##### weak50 51Specifies if the generated ETag will include the weak validator mark (that52is, the leading `W/`). The actual entity tag is the same. The default value53is `false`, unless the `entity` is `fs.Stats`, in which case it is `true`.54 55## Testing56 57```sh58$ npm test59```60 61## Benchmark62 63```bash64$ npm run-script bench65 66> etag@1.8.1 bench nodejs-etag67> node benchmark/index.js68 69 http_parser@2.7.070 node@6.11.171 v8@5.1.281.10372 uv@1.11.073 zlib@1.2.1174 ares@1.10.1-DEV75 icu@58.276 modules@4877 openssl@1.0.2k78 79> node benchmark/body0-100b.js80 81 100B body82 83 4 tests completed.84 85 buffer - strong x 258,647 ops/sec ±1.07% (180 runs sampled)86 buffer - weak x 263,812 ops/sec ±0.61% (184 runs sampled)87 string - strong x 259,955 ops/sec ±1.19% (185 runs sampled)88 string - weak x 264,356 ops/sec ±1.09% (184 runs sampled)89 90> node benchmark/body1-1kb.js91 92 1KB body93 94 4 tests completed.95 96 buffer - strong x 189,018 ops/sec ±1.12% (182 runs sampled)97 buffer - weak x 190,586 ops/sec ±0.81% (186 runs sampled)98 string - strong x 144,272 ops/sec ±0.96% (188 runs sampled)99 string - weak x 145,380 ops/sec ±1.43% (187 runs sampled)100 101> node benchmark/body2-5kb.js102 103 5KB body104 105 4 tests completed.106 107 buffer - strong x 92,435 ops/sec ±0.42% (188 runs sampled)108 buffer - weak x 92,373 ops/sec ±0.58% (189 runs sampled)109 string - strong x 48,850 ops/sec ±0.56% (186 runs sampled)110 string - weak x 49,380 ops/sec ±0.56% (190 runs sampled)111 112> node benchmark/body3-10kb.js113 114 10KB body115 116 4 tests completed.117 118 buffer - strong x 55,989 ops/sec ±0.93% (188 runs sampled)119 buffer - weak x 56,148 ops/sec ±0.55% (190 runs sampled)120 string - strong x 27,345 ops/sec ±0.43% (188 runs sampled)121 string - weak x 27,496 ops/sec ±0.45% (190 runs sampled)122 123> node benchmark/body4-100kb.js124 125 100KB body126 127 4 tests completed.128 129 buffer - strong x 7,083 ops/sec ±0.22% (190 runs sampled)130 buffer - weak x 7,115 ops/sec ±0.26% (191 runs sampled)131 string - strong x 3,068 ops/sec ±0.34% (190 runs sampled)132 string - weak x 3,096 ops/sec ±0.35% (190 runs sampled)133 134> node benchmark/stats.js135 136 stat137 138 4 tests completed.139 140 real - strong x 871,642 ops/sec ±0.34% (189 runs sampled)141 real - weak x 867,613 ops/sec ±0.39% (190 runs sampled)142 fake - strong x 401,051 ops/sec ±0.40% (189 runs sampled)143 fake - weak x 400,100 ops/sec ±0.47% (188 runs sampled)144```145 146## License147 148[MIT](LICENSE)149 150[npm-image]: https://img.shields.io/npm/v/etag.svg151[npm-url]: https://npmjs.org/package/etag152[node-version-image]: https://img.shields.io/node/v/etag.svg153[node-version-url]: https://nodejs.org/en/download/154[travis-image]: https://img.shields.io/travis/jshttp/etag/master.svg155[travis-url]: https://travis-ci.org/jshttp/etag156[coveralls-image]: https://img.shields.io/coveralls/jshttp/etag/master.svg157[coveralls-url]: https://coveralls.io/r/jshttp/etag?branch=master158[downloads-image]: https://img.shields.io/npm/dm/etag.svg159[downloads-url]: https://npmjs.org/package/etag160 