Skip to content

Commit

Permalink
Try alternate write method
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvNC committed Jul 12, 2024
1 parent 7993d57 commit 2067257
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/util/downloadDumps.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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`);
Expand Down

0 comments on commit 2067257

Please sign in to comment.