MCPcopy Create free account
hub / github.com/anomalyco/opencode / sampledChecksum

Function sampledChecksum

packages/core/src/util/encode.ts:32–51  ·  view source on GitHub ↗
(content: string, limit = 500_000)

Source from the content-addressed store, hash-verified

30}
31
32export function sampledChecksum(content: string, limit = 500_000): string | undefined {
33 if (!content) return undefined
34 if (content.length <= limit) return checksum(content)
35
36 const size = 4096
37 const points = [
38 0,
39 Math.floor(content.length * 0.25),
40 Math.floor(content.length * 0.5),
41 Math.floor(content.length * 0.75),
42 content.length - size,
43 ]
44 const hashes = points
45 .map((point) => {
46 const start = Math.max(0, Math.min(content.length - size, point - Math.floor(size / 2)))
47 return checksum(content.slice(start, start + size)) ?? ""
48 })
49 .join(":")
50 return `${content.length}:${hashes}`
51}

Callers 2

FileTabContentFunction · 0.90
cacheKeyFunction · 0.90

Calls 1

checksumFunction · 0.85

Tested by

no test coverage detected