Skip to content

Commit

Permalink
refactor: simplify normalizeLambdaOutgoingBody
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 23, 2023
1 parent 2aa862c commit 58b4853
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/runtime/utils.lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,11 @@ export async function normalizeLambdaOutgoingBody(
if (!body) {
return "";
}
body = await _toBuffer(body as any);
if (Buffer.isBuffer(body)) {
const contentType = (headers["content-type"] as string) || "";
if (isTextType(contentType)) {
return body.toString("utf8");
}
return body.toString("base64");
}
throw new Error(`Unsupported body type: ${typeof body}`);
const buffer = await _toBuffer(body as any);
const contentType = (headers["content-type"] as string) || "";
return isTextType(contentType)
? buffer.toString("utf8")
: buffer.toString("base64");
}

function _toBuffer(data: ReadableStream | Readable | Uint8Array) {
Expand Down

0 comments on commit 58b4853

Please sign in to comment.