MCPcopy
hub / github.com/promptfoo/promptfoo / hashBytesForCacheKey

Function hashBytesForCacheKey

src/cache.ts:437–450  ·  view source on GitHub ↗
(bytes: ArrayBuffer | ArrayBufferView)

Source from the content-addressed store, hash-verified

435}
436
437function hashBytesForCacheKey(bytes: ArrayBuffer | ArrayBufferView) {
438 const buffer = ArrayBuffer.isView(bytes)
439 ? Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)
440 : Buffer.from(bytes);
441 return {
442 byteLength: buffer.byteLength,
443 hmacSha256: crypto
444 .createHmac('sha256', FETCH_CACHE_SECRET_HMAC_SALT)
445 .update(`${FETCH_CACHE_SECRET_HMAC_CONTEXT}:bytes`)
446 .update('\0')
447 .update(buffer)
448 .digest('hex'),
449 };
450}
451
452function getBodyForFetchCacheKey(body: RequestInit['body'] | ReadableStream | null | undefined) {
453 if (body == null) {

Callers 1

getBodyForFetchCacheKeyFunction · 0.85

Calls 1

updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…