Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/open-next/src/http/openNextResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,20 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
}

private _internalWrite(chunk: any, encoding: BufferEncoding) {
const buffer = Buffer.from(chunk, encoding);
// When encoding === 'buffer', chunk is already a Buffer
// and does not need to be converted again.
// @ts-expect-error TS2367 'encoding' can be 'buffer', but it's not in the
// official type definition
const buffer = encoding === "buffer" ? chunk : Buffer.from(chunk, encoding);
this.bodyLength += buffer.length;
if (this.streamCreator?.retainChunks !== false) {
// Avoid keeping chunks around when the `StreamCreator` supports it to save memory
this._chunks.push(buffer);
}
this.push(chunk, encoding);
// No need to pass the encoding for buffers
// unnecessary additional conversion down the stream pipeline.
// @ts-expect-error TS2345 'buffer' is not in the official type definition
this.push(buffer);
this.streamCreator?.onWrite?.();
}

Expand Down
Loading