Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

refactor(media-server): simplify file concatenation with fs/promises

Richie McIlroy6be4cd60ea45
diff --git a/apps/media-server/src/routes/video.ts b/apps/media-server/src/routes/video.ts
index fff94ccf5..91becb856 100644
--- a/apps/media-server/src/routes/video.ts
+++ b/apps/media-server/src/routes/video.ts
@@ -1066,21 +1066,15 @@ async function streamConcatFiles(
inputPaths: string[],
outputPath: string,
): Promise<void> {
- const { createReadStream, createWriteStream } = await import("node:fs");
- const { pipeline } = await import("node:stream/promises");
- const outStream = createWriteStream(outputPath);
+ const { open, readFile } = await import("node:fs/promises");
+ const handle = await open(outputPath, "w");
try {
for (const filePath of inputPaths) {
- await pipeline(createReadStream(filePath), outStream, { end: false });
+ const data = await readFile(filePath);
+ await handle.write(data);
}
- outStream.end();
- await new Promise<void>((resolve, reject) => {
- outStream.on("finish", resolve);
- outStream.on("error", reject);
- });
- } catch (err) {
- outStream.destroy();
- throw err;
+ } finally {
+ await handle.close();
}
}