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

Function materializeEmbeddedAssetGroup

src/shims/nativeAssetRuntime.ts:86–119  ·  view source on GitHub ↗
(
  groupKey: string,
  assets: readonly MaterializedAsset[],
)

Source from the content-addressed store, hash-verified

84}
85
86export function materializeEmbeddedAssetGroup(
87 groupKey: string,
88 assets: readonly MaterializedAsset[],
89): MaterializedAssetGroup {
90 const hash = createHash('sha256')
91 for (const asset of assets) {
92 hash.update(asset.relativePath)
93 hash.update(readFileSync(resolveEmbeddedAssetPath(asset.embeddedPath)))
94 }
95
96 const baseDir = join(
97 tmpdir(),
98 'ncode-native-assets',
99 `${sanitizeGroupKey(groupKey)}-${hash.digest('hex').slice(0, 16)}`,
100 )
101 const paths: Record<string, string> = {}
102
103 for (const asset of assets) {
104 const targetPath = join(baseDir, asset.relativePath)
105 paths[asset.relativePath] = targetPath
106 if (!existsSync(targetPath)) {
107 writeAtomically(
108 targetPath,
109 Buffer.from(readFileSync(resolveEmbeddedAssetPath(asset.embeddedPath))),
110 asset.mode,
111 )
112 }
113 }
114
115 return {
116 baseDir,
117 paths,
118 }
119}

Callers 3

loadEmbeddedSharpFunction · 0.85
getBuiltinRipgrepConfigFunction · 0.85

Calls 5

resolveEmbeddedAssetPathFunction · 0.85
sanitizeGroupKeyFunction · 0.85
existsSyncFunction · 0.85
writeAtomicallyFunction · 0.85
readFileSyncFunction · 0.50

Tested by

no test coverage detected