From 77a094a87323dcc50a4f3c28315f6449064e629d Mon Sep 17 00:00:00 2001 From: Priyanshu Kumar Date: Tue, 17 Mar 2026 10:13:46 +0530 Subject: [PATCH] added buffer --- src/deploy.ts | 18 +++++++++--------- src/utils.ts | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/deploy.ts b/src/deploy.ts index 8f60350..6630cfb 100644 --- a/src/deploy.ts +++ b/src/deploy.ts @@ -20,7 +20,13 @@ import Progress from './cli/progress'; import { languageSelection, listSelection } from './cli/selection'; import { logs } from './logs'; import { isInteractive } from './tty'; -import { filterFiles, getEnv, loadFilesToRun, zip } from './utils'; +import { + filterFiles, + getEnv, + loadFilesToRun, + streamToBuffer, + zip +} from './utils'; import { debug } from './cli/messages'; export enum ErrorCode { @@ -68,14 +74,8 @@ export const deployPackage = async ( hide ); - // TODO: We should do something with the return value, for example - // check for error or show the output to the user - await api.upload( - name, - archive, - additionalJsons, - descriptor.runners - ); + const blob = await streamToBuffer(archive); + await api.upload(name, blob, additionalJsons, descriptor.runners); const env = await getEnv(rootPath, args['env'], args['envFile']); diff --git a/src/utils.ts b/src/utils.ts index f4888b4..a89b25e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -7,11 +7,13 @@ import { MetaCallJSON } from '@metacall/protocol/deployment'; import archiver, { Archiver } from 'archiver'; +import concat from 'concat-stream'; import { parse } from 'dotenv'; import { promises as fs } from 'fs'; import { prompt } from 'inquirer'; import { platform } from 'os'; import { basename, join, relative } from 'path'; +import { Readable } from 'stream'; import { error, info, printLanguage, warn } from './cli/messages'; import { consentSelection, fileSelection } from './cli/selection'; import { isInteractive } from './tty'; @@ -146,6 +148,18 @@ export const zip = async ( return archive; }; +/** + * Collect a readable stream into a Buffer. + * Required for multipart uploads with axios 1.x - streams cause wrong Content-Length. + */ +export const streamToBuffer = (stream: Readable): Promise => + new Promise((resolve, reject) => { + const collector = concat((buf: Buffer) => resolve(buf)); + stream.on('error', reject); + collector.on('error', reject); + stream.pipe(collector); + }); + /** * Parse a single KEY=VALUE string into an object entry */