Skip to main content

getEventBodyAsBuffer

@h4ad/serverless-adapter > getEventBodyAsBuffer

(function) getEventBodyAsBuffer

Get the event body as buffer from body string with content length

Signature:

export declare function getEventBodyAsBuffer(body: string, isBase64Encoded: boolean): [body: Buffer, contentLength: number];

Parameters

ParameterTypeDescription
bodystringThe body string that can be encoded or not
isBase64EncodedbooleanTells if body string is encoded in base64

Returns:

[body: Buffer, contentLength: number]

Example

const body = '\{}';
const [buffer, contentLength] = getEventBodyAsBuffer(body, false);
console.log(buffer);
// <Buffer 7b 7d>
console.log(contentLength);
// 2