summaryrefslogtreecommitdiff
path: root/src/main/util/downloader.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/util/downloader.ts')
-rw-r--r--src/main/util/downloader.ts44
1 files changed, 24 insertions, 20 deletions
diff --git a/src/main/util/downloader.ts b/src/main/util/downloader.ts
index 075097d..2a25b52 100644
--- a/src/main/util/downloader.ts
+++ b/src/main/util/downloader.ts
@@ -1,28 +1,32 @@
-var fs = require('fs');
-var request = require('request');
-var progress = require('request-progress');
+var fs = require("fs");
+var request = require("request");
+var progress = require("request-progress");
export type Progress = {
- percent:number,
- speed:number,
- size:{
- total:number,
- transfered:number
- },
- time:{
- elapsed:number,
- remaining:number
- }
+ percent: number;
+ speed: number;
+ size: {
+ total: number;
+ transfered: number;
+ };
+ time: {
+ elapsed: number;
+ remaining: number;
+ };
};
-export function download(url:string,targetLocation:string,onprogress: (state:Progress)=>void):Promise<any>{
- return new Promise((resolve:any,reject:any)=>{
+export function download(
+ url: string,
+ targetLocation: string,
+ onprogress: (state: Progress) => void
+): Promise<any> {
+ return new Promise((resolve: any, reject: any) => {
progress(request(url), {
- throttle: 500
+ throttle: 500,
})
- .on('progress', onprogress)
- .on('error', reject)
- .on('end', resolve)
- .pipe(fs.createWriteStream(targetLocation));
+ .on("progress", onprogress)
+ .on("error", reject)
+ .on("end", resolve)
+ .pipe(fs.createWriteStream(targetLocation));
});
}