@@ -3,7 +3,7 @@ import { net } from "electron"
3
3
import { createWriteStream , ensureDir } from "fs-extra-p"
4
4
import BluebirdPromise from "bluebird-lst-c"
5
5
import * as path from "path"
6
- import { HttpExecutor , DownloadOptions , HttpError , DigestTransform , checkSha2 } from "../../src/util/httpExecutor"
6
+ import { HttpExecutor , DownloadOptions , HttpError , DigestTransform , checkSha2 , calculateDownloadProgress } from "../../src/util/httpExecutor"
7
7
import { Url } from "url"
8
8
import { safeLoad } from "js-yaml"
9
9
import _debug from "debug"
@@ -69,7 +69,7 @@ export class ElectronHttpExecutor implements HttpExecutor {
69
69
// user-agent must be specified, otherwise some host can return 401 unauthorised
70
70
71
71
//FIXME hack, the electron typings specifies Protocol with capital but the code actually uses with small case
72
- const requestOpts = {
72
+ const requestOpts = {
73
73
protocol : parsedUrl . protocol ,
74
74
hostname : parsedUrl . hostname ,
75
75
path : parsedUrl . path ,
@@ -99,6 +99,16 @@ export class ElectronHttpExecutor implements HttpExecutor {
99
99
return
100
100
}
101
101
102
+ if ( options . onProgress != null ) {
103
+ const total = parseInt ( String ( safeGetHeader ( response , "content-length" ) ) , 10 )
104
+ const start = Date . now ( )
105
+ let transferred = 0
106
+
107
+ response . on ( "data" , ( chunk : any ) => {
108
+ transferred = calculateDownloadProgress ( total , start , transferred , chunk , options . onProgress )
109
+ } )
110
+ }
111
+
102
112
ensureDirPromise
103
113
. then ( ( ) => {
104
114
const fileOut = createWriteStream ( destination )
0 commit comments