MCPcopy Create free account
hub / github.com/apache/maka / validateDocumentBytes

Function validateDocumentBytes

packages/storage/src/memory-bundle-model.ts:122–138  ·  view source on GitHub ↗
(name: MemoryDocumentName, input: Uint8Array)

Source from the content-addressed store, hash-verified

120}
121
122export function validateDocumentBytes(name: MemoryDocumentName, input: Uint8Array): Buffer {
123 if (!(input instanceof Uint8Array)) {
124 throw invalidMemoryDocument(`${displayName(name)} bytes are required`);
125 }
126 const bytes = Buffer.from(input);
127 if (bytes.byteLength > MEMORY_DOCUMENT_MAX_BYTES) {
128 throw invalidMemoryDocument(
129 `${displayName(name)} exceeds its ${MEMORY_DOCUMENT_MAX_BYTES} byte limit`,
130 );
131 }
132 try {
133 new TextDecoder('utf-8', { fatal: true }).decode(bytes);
134 } catch (error) {
135 throw invalidMemoryDocument(`${displayName(name)} is not valid UTF-8`, error);
136 }
137 return bytes;
138}
139
140export function bundleTarget(
141 memory: Buffer,

Callers 1

commitMemoryBundleFunction · 0.85

Calls 3

invalidMemoryDocumentFunction · 0.85
fromMethod · 0.80
displayNameFunction · 0.70

Tested by

no test coverage detected