fix multipart/form-data decoding

This commit is contained in:
Hazelnoot 2025-05-06 18:26:33 -04:00
parent c0f24eaf5d
commit 89cab66898
2 changed files with 42 additions and 10 deletions

View file

@ -3,6 +3,8 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { pipeline } from 'node:stream/promises';
import fs from 'node:fs';
import * as tmp from 'tmp';
export function createTemp(): Promise<[string, () => void]> {
@ -27,3 +29,14 @@ export function createTempDir(): Promise<[string, () => void]> {
);
});
}
export async function saveToTempFile(stream: NodeJS.ReadableStream): Promise<string> {
const [filepath, cleanup] = await createTemp();
try {
await pipeline(stream, fs.createWriteStream(filepath));
return filepath;
} catch (e) {
cleanup();
throw e;
}
}