Skip to content

Commit 117506a

Browse files
committed
test case fix for ubuntu
1 parent 6f4d2f8 commit 117506a

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/helper/download.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import fs from 'fs-extra';
22
import { uninterceptedApiClient } from '../lib/api/ApiClient';
3-
export async function downloadFile(url: string, filePath: string) {
3+
4+
export async function downloadFile(url: string, filePath: string): Promise<void> {
5+
// Ensure the file exists before attempting to write to it
46
fs.ensureFileSync(filePath);
7+
8+
// Create a writable stream to save the downloaded file
59
const writer = fs.createWriteStream(filePath);
610

11+
// Fetch the file as a stream
712
const response = await uninterceptedApiClient.get(url, {
813
responseType: 'stream',
914
});
1015

16+
// Pipe the data stream to the file writer
1117
response.data.pipe(writer);
1218

19+
// Return a promise that resolves when the download is finished or rejects if an error occurs
1320
return new Promise((resolve, reject) => {
14-
writer.on('finish', resolve);
15-
writer.on('error', reject);
21+
writer.on('finish', () => resolve()); // Ensure resolve is called without any arguments
22+
writer.on('error', error => reject(error)); // Directly pass the error to the reject function
1623
});
1724
}

0 commit comments

Comments
 (0)