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:
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user