UNPKG

730 BJavaScriptView Raw
1
2/**
3 * Module dependencies.
4 */
5
6var crypto = require('crypto');
7
8/**
9 * Return a weak ETag from the given `path` and `stat`.
10 *
11 * @param {String} path
12 * @param {Object} stat
13 * @return {String}
14 * @api private
15 */
16
17exports.etag = function etag(path, stat) {
18 var tag = String(stat.mtime.getTime()) + ':' + String(stat.size) + ':' + path;
19 var str = crypto
20 .createHash('md5')
21 .update(tag, 'utf8')
22 .digest('base64');
23 return 'W/"' + str + '"';
24};
25
26/**
27 * decodeURIComponent.
28 *
29 * Allows V8 to only deoptimize this fn instead of all
30 * of send().
31 *
32 * @param {String} path
33 * @api private
34 */
35
36exports.decode = function(path){
37 try {
38 return decodeURIComponent(path);
39 } catch (err) {
40 return -1;
41 }
42};