From 2067257271a5f78917f82b724dceea1122c50932 Mon Sep 17 00:00:00 2001 From: MarvNC Date: Thu, 11 Jul 2024 22:00:55 -0700 Subject: [PATCH] Try alternate write method --- src/util/downloadDumps.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/util/downloadDumps.ts b/src/util/downloadDumps.ts index ab175e6..e6c15f0 100644 --- a/src/util/downloadDumps.ts +++ b/src/util/downloadDumps.ts @@ -1,4 +1,4 @@ -import { $ } from 'bun'; +import * as Bun from 'bun'; import { exists, mkdir } from 'node:fs/promises'; import { join } from 'path'; import { LanguageCode } from '../constants'; @@ -38,13 +38,30 @@ export async function downloadDumps(lang: LanguageCode, date: string) { if (!fileExists && !archiveExists) { const url = URL(lang, date); console.log(`Downloading ${url}`); - await $`wget ${url} -O ${archivePath}`; + await Bun.$`wget ${url} -O ${archivePath}`; } // Extract the archive if it does not exist if (!fileExists) { console.log(`Extracting ${archivePath}`); - await $`bzip2 -dk ${archivePath}`; + const process = Bun.spawn(['bzip2', '-dkc', archivePath]); + const writeStream = Bun.file(filePath).writer(); + + // Create a reader from the stdout stream + const reader = process.stdout.getReader(); + + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + // Write each chunk to the file + await writeStream.write(value); + } + } finally { + reader.releaseLock(); + await writeStream.flush(); + await writeStream.end(); + } } console.log(`Finished downloading and extracting ${lang} dump`);