-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(close): delete temp file when aborted (optional)
Revert "feat(download): method delete an incomplete file" This reverts commit c7341f0.
- Loading branch information
Showing
1 changed file
with
12 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 GitHub Actions / test
|
||
*/ | ||
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 {} | ||
} | ||
} | ||
|