| 4 | import { Stats } from 'fs' |
| 5 | |
| 6 | const entityTag = (entity: string | Buffer) => { |
| 7 | if (entity.length === 0) { |
| 8 | // fast-path empty |
| 9 | return '"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"' |
| 10 | } else { |
| 11 | // generate hash |
| 12 | const hash = createHash('sha1') |
| 13 | .update(entity as string, 'utf8') |
| 14 | .digest('base64') |
| 15 | .substring(0, 27) |
| 16 | |
| 17 | const len = typeof entity === 'string' ? Buffer.byteLength(entity, 'utf8') : entity.length |
| 18 | |
| 19 | return '"' + len.toString(16) + '-' + hash + '"' |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | const statTag = ({ mtime, size }: Stats) => { |
| 24 | return '"' + mtime.getTime().toString(16) + '-' + size.toString(16) + '"' |