From b048646401383fd14bd9ea05084c920bd4309120 Mon Sep 17 00:00:00 2001 From: Derek Cormier Date: Mon, 25 Nov 2024 07:50:25 -0800 Subject: [PATCH] fix: xz decompression issues --- src/domain/release-archive.ts | 5 +++++ src/infrastructure/xzdec/xzdec.ts | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/domain/release-archive.ts b/src/domain/release-archive.ts index 72be809..7f0c271 100644 --- a/src/domain/release-archive.ts +++ b/src/domain/release-archive.ts @@ -99,6 +99,11 @@ export class ReleaseArchive { cwd: extractDir }); await decompressXz(reader, writer); + await new Promise(resolve => { + writer.on('finish', resolve); + writer.end(); + }); + return; } diff --git a/src/infrastructure/xzdec/xzdec.ts b/src/infrastructure/xzdec/xzdec.ts index 208d150..13c3450 100644 --- a/src/infrastructure/xzdec/xzdec.ts +++ b/src/infrastructure/xzdec/xzdec.ts @@ -126,7 +126,14 @@ export async function decompress(r: stream.Readable, w: stream.Writable) { } const outputLen = peekU32(mem, outputLenPtr); if (outputLen > 0) { - w.write(Buffer.from(mem.buffer, outputPtr, outputLen)); + await new Promise((resolve) => { + if (!w.write(Buffer.from(mem.buffer, outputPtr, outputLen))) { + w.once('drain', resolve) + } + else { + resolve(null); + } + }); } } }