MCPcopy
hub / github.com/coder/mux / readRegularFileBytes

Function readRegularFileBytes

src/node/utils/attachments/readAttachmentFromPath.ts:156–178  ·  view source on GitHub ↗
(
  args: ReadAttachmentFromPathArgs,
  resolvedPath: string,
  expectedSize: number
)

Source from the content-addressed store, hash-verified

154}
155
156async function readRegularFileBytes(
157 args: ReadAttachmentFromPathArgs,
158 resolvedPath: string,
159 expectedSize: number
160): Promise<Buffer> {
161 if (expectedSize > MAX_ATTACH_FILE_SIZE_BYTES) {
162 throw new Error(buildTooLargeMessage(expectedSize));
163 }
164
165 let bytes: Buffer;
166 try {
167 bytes = await readStreamToBuffer(args.runtime.readFile(resolvedPath, args.abortSignal));
168 } catch (error) {
169 throw buildMissingFileError(resolvedPath, error);
170 }
171
172 assert(
173 bytes.length === expectedSize,
174 `Expected to read ${expectedSize} bytes from '${resolvedPath}', got ${bytes.length}`
175 );
176
177 return bytes;
178}
179
180function createUnsupportedAttachmentError(
181 args: ReadAttachmentFromPathArgs,

Callers 1

readAttachFileFromPathFunction · 0.85

Calls 5

buildTooLargeMessageFunction · 0.85
buildMissingFileErrorFunction · 0.85
readStreamToBufferFunction · 0.70
readFileMethod · 0.65
assertFunction · 0.50

Tested by

no test coverage detected