( b: Readable | ReadableStream | Blob | undefined )
| 199 | * @returns Promise<ArrayBuffer> |
| 200 | */ |
| 201 | const 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 | |
| 223 | const getS3Client = (s3Config: S3Config) => { |
| 224 | let endpoint = s3Config.s3Endpoint; |
no test coverage detected