Skip to content

Commit

Permalink
feat(close): delete temp file when aborted (optional)
Browse files Browse the repository at this point in the history
Revert "feat(download): method delete an incomplete file"

This reverts commit c7341f0.
  • Loading branch information
ido-pluto committed Sep 30, 2024
1 parent c7341f0 commit 209c4f6
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/download/download-engine/engine/download-engine-nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,26 @@ export default class DownloadEngineNodejs<T extends DownloadEngineWriteStreamNod
}

/**
* Abort the download & delete the file, **even if** the download is **finished**
* Abort the download & delete the file (**even if** the download is finished)
* @deprecated use `close` with flag `deleteFile` instead
*
* TODO: remove in the next major version
*/
public async closeAndDeleteFile() {
await this.close();
try {
await fs.unlink(this.fileAbsolutePath);
} catch {}
await this.close({deleteFile: true});
}

/**
* Abort the download & delete the file, **if** the download is **not finished**
* Close the download engine
* @param deleteTempFile {boolean} - delete the temp file (when the download is **not finished**).
* @param deleteFile {boolean} - delete the **temp** or **final file** (clean everything up).

Check warning on line 110 in src/download/download-engine/engine/download-engine-nodejs.ts

View workflow job for this annotation

GitHub Actions / test

@param "deleteFile" does not match an existing function parameter
*/
public async closeAndDeleteIncompleteFile() {
await this.close();
override async close({deleteTempFile, deleteFile}: { deleteTempFile?: boolean, deleteFile?: boolean } = {}): Promise<void> {
await super.close();

if (this.status.downloadStatus != DownloadStatus.Finished) {
if (deleteFile || deleteTempFile && this.status.downloadStatus != DownloadStatus.Finished) {
try {
await fs.unlink(this.options.writeStream.path);
await fs.unlink(this.fileAbsolutePath);
} catch {}
}
}
Expand Down

0 comments on commit 209c4f6

Please sign in to comment.