MCPcopy
hub / github.com/remotely-save/remotely-save / getObjectBodyToArrayBuffer

Function getObjectBodyToArrayBuffer

src/fsS3.ts:201–221  ·  view source on GitHub ↗
(
  b: Readable | ReadableStream | Blob | undefined
)

Source from the content-addressed store, hash-verified

199 * @returns Promise<ArrayBuffer>
200 */
201const getObjectBodyToArrayBuffer = async (
202 b: Readable | ReadableStream | Blob | undefined
203) => {
204 if (b === undefined) {
205 throw Error(`ObjectBody is undefined and don't know how to deal with it`);
206 }
207 if (b instanceof Readable) {
208 return (await new Promise((resolve, reject) => {
209 const chunks: Uint8Array[] = [];
210 b.on("data", (chunk) => chunks.push(chunk));
211 b.on("error", reject);
212 b.on("end", () => resolve(bufferToArrayBuffer(Buffer.concat(chunks))));
213 })) as ArrayBuffer;
214 } else if (b instanceof ReadableStream) {
215 return await new Response(b, {}).arrayBuffer();
216 } else if (b instanceof Blob) {
217 return await b.arrayBuffer();
218 } else {
219 throw TypeError(`The type of ${b} is not one of the supported types`);
220 }
221};
222
223const getS3Client = (s3Config: S3Config) => {
224 let endpoint = s3Config.s3Endpoint;

Callers 1

_readFileFromRootMethod · 0.85

Calls 1

bufferToArrayBufferFunction · 0.90

Tested by

no test coverage detected