MCPcopy Create free account
hub / github.com/Noumena-Network/code / resolveMetadataBuf

Function resolveMetadataBuf

src/utils/sessionStorage.ts:3312–3329  ·  view source on GitHub ↗
(
  carry: Buffer | null,
  chunkBuf: Buffer,
)

Source from the content-addressed store, hash-verified

3310// null = carry spans whole chunk. Skips concat when carry provably isn't
3311// a metadata line (markers sit at byte 1 after `{`).
3312function resolveMetadataBuf(
3313 carry: Buffer | null,
3314 chunkBuf: Buffer,
3315): Buffer | null {
3316 if (carry === null || carry.length === 0) return chunkBuf
3317 if (carry.length < METADATA_PREFIX_BOUND) {
3318 return Buffer.concat([carry, chunkBuf])
3319 }
3320 if (carry[0] === 0x7b /* { */) {
3321 for (const m of METADATA_MARKER_BUFS) {
3322 if (carry.compare(m, 0, m.length, 1, 1 + m.length) === 0) {
3323 return Buffer.concat([carry, chunkBuf])
3324 }
3325 }
3326 }
3327 const firstNl = chunkBuf.indexOf(0x0a)
3328 return firstNl === -1 ? null : chunkBuf.subarray(firstNl + 1)
3329}
3330
3331/**
3332 * Lightweight forward scan of [0, endOffset) collecting only metadata-entry lines.

Callers 1

scanPreBoundaryMetadataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected