Increase size of tarball upload (#20767)

- check size while reading stream instead of checking after reading all
stream
- move MAX_TARBALL_UPLOAD_SIZE_BYTES to config variables
- increase MAX_TARBALL_UPLOAD_SIZE_BYTES default from 50Mb to 100Mb
This commit is contained in:
martmull
2026-05-20 14:39:11 +02:00
committed by GitHub
parent 3d49c17e34
commit 127fb2a470
5 changed files with 101 additions and 23 deletions
@@ -1,7 +1,11 @@
import { type Readable } from 'stream';
export const streamToBuffer = async (stream: Readable): Promise<Buffer> => {
export const streamToBuffer = async (
stream: Readable,
maxSizeBytes?: number,
): Promise<Buffer> => {
const chunks: Buffer[] = [];
let totalSize = 0;
return new Promise((resolve, reject) => {
if (stream.readableEnded) {
@@ -27,6 +31,21 @@ export const streamToBuffer = async (stream: Readable): Promise<Buffer> => {
const onData = (chunk: Buffer) => {
if (!isResolved) {
totalSize += chunk.length;
if (maxSizeBytes !== undefined && totalSize > maxSizeBytes) {
isResolved = true;
cleanup();
stream.destroy();
reject(
new Error(
`Stream exceeds maximum allowed size of ${maxSizeBytes} bytes`,
),
);
return;
}
chunks.push(chunk);
}
};