Comparing version 1.0.3 to 1.1.0
export declare function delay(ms: number): Promise<void>; | ||
export declare function safeRun<T extends (...args: any) => any>(fn: T): void; |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.delay = void 0; | ||
exports.safeRun = exports.delay = void 0; | ||
function delay(ms) { | ||
@@ -20,1 +20,8 @@ return __awaiter(this, void 0, void 0, function* () { | ||
exports.delay = delay; | ||
function safeRun(fn) { | ||
try { | ||
fn(); | ||
} | ||
catch (_a) { } | ||
} | ||
exports.safeRun = safeRun; |
@@ -13,3 +13,3 @@ /// <reference types="node" /> | ||
*/ | ||
existBehavior?: "overwrite" | "new_file" | "ignore"; | ||
existBehavior?: "overwrite" | "new_file" | "ignore" | "error"; | ||
/** Whether `EasyDl` should follow HTTP redirection. */ | ||
@@ -16,0 +16,0 @@ followRedirect?: boolean; |
@@ -149,2 +149,5 @@ "use strict"; | ||
} | ||
else if (stats && this._opts.existBehavior === "error") { | ||
throw new Error(`Destination ${this.savedFilePath} already exists.`); | ||
} | ||
else { | ||
@@ -175,5 +178,5 @@ break; | ||
return; | ||
this.emit("build", { percentage: 0 }); | ||
const dest = fs.createWriteStream(this.savedFilePath); | ||
try { | ||
this.emit("build", { percentage: 0 }); | ||
const dest = fs.createWriteStream(this.savedFilePath); | ||
for (let i = 0; i < this._totalChunks; i += 1) { | ||
@@ -186,5 +189,8 @@ const fileName = `${this.savedFilePath}.$$${i}`; | ||
dest.on("error", rej); | ||
source.on("end", res); | ||
source.on("end", () => { | ||
dest.removeListener("error", rej); | ||
res(); | ||
}); | ||
}); | ||
source.close(); | ||
source.destroy(); | ||
this.emit("build", { | ||
@@ -198,3 +204,3 @@ percentage: 100 * (i / this._totalChunks), | ||
} | ||
dest.close(); | ||
dest.destroy(); | ||
this._done = true; | ||
@@ -205,2 +211,3 @@ this.emit("end"); | ||
catch (err) { | ||
helpers_1.safeRun(dest.destroy); | ||
this.emit("error", err); | ||
@@ -330,2 +337,3 @@ this.destroy(); | ||
.wait(); | ||
helpers_1.safeRun(dest.destroy); | ||
if (this._destroyed) | ||
@@ -332,0 +340,0 @@ return; |
{ | ||
"name": "easydl", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Easily download a file and save it to local disk. It supports resuming previously downloaded files, multi-connection/parallel downloads, and retry on fail out of the box!", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
# EasyDl | ||
![Install via NPM](https://nodei.co/npm/easydl.png) | ||
[![Install via NPM](https://nodei.co/npm/easydl.png)](https://www.npmjs.com/package/easydl) | ||
@@ -275,2 +275,3 @@ Easily download a file and save it to a local disk. It supports resuming previously downloaded files, multi-connection/parallel downloads, and retry on failure out of the box! | ||
- `overwrite` - overwrite the file. Proceed with caution. | ||
- `error` - throws error. | ||
- `ignore` - ignore and skip this download | ||
@@ -277,0 +278,0 @@ - `followRedirect` - (Boolean) Whether `EasyDl` should follow HTTP redirection. Defaults to `true` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
65669
13
1207
440
2