MCPcopy Index your code
hub / github.com/tinyhttp/tinyhttp / entityTag

Function entityTag

packages/etag/src/index.ts:6–21  ·  view source on GitHub ↗
(entity: string | Buffer)

Source from the content-addressed store, hash-verified

4import { Stats } from 'fs'
5
6const 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
23const statTag = ({ mtime, size }: Stats) => {
24 return '"' + mtime.getTime().toString(16) + '-' + size.toString(16) + '"'

Callers 1

eTagFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected