electron-builder-http
Advanced tools
Comparing version 10.16.0 to 10.17.1
@@ -43,3 +43,2 @@ declare module "electron-builder-http/out/publishOptions" { | ||
import { Url } from "url" | ||
import { Transform } from "stream" | ||
@@ -85,10 +84,2 @@ export interface DownloadOptions { | ||
} | ||
export class DigestTransform extends Transform { | ||
private expected | ||
private readonly digester | ||
constructor(expected: string) | ||
_transform(chunk: any, encoding: string, callback: Function): void | ||
_flush(callback: Function): void | ||
} | ||
export const executorHolder: HttpExecutorHolder | ||
@@ -107,2 +98,6 @@ | ||
export function calculateDownloadProgress(total: number, start: number, transferred: number, chunk: any, callback: any): number | ||
export function safeGetHeader(response: any, headerKey: string): any | ||
export function configurePipes(options: DownloadOptions, response: any, destination: string, callback: (error: Error | null) => void): void | ||
} | ||
@@ -109,0 +104,0 @@ |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.executorHolder = exports.DigestTransform = exports.HttpError = exports.HttpExecutor = exports.maxRedirects = exports.HttpExecutorHolder = undefined; | ||
exports.executorHolder = exports.HttpError = exports.HttpExecutor = exports.maxRedirects = exports.HttpExecutorHolder = undefined; | ||
exports.download = download; | ||
@@ -13,2 +13,4 @@ exports.githubRequest = githubRequest; | ||
exports.calculateDownloadProgress = calculateDownloadProgress; | ||
exports.safeGetHeader = safeGetHeader; | ||
exports.configurePipes = configurePipes; | ||
@@ -27,2 +29,8 @@ var _crypto; | ||
var _fsExtraP; | ||
function _load_fsExtraP() { | ||
return _fsExtraP = require("fs-extra-p"); | ||
} | ||
function download(url, destination, options) { | ||
@@ -75,2 +83,15 @@ return executorHolder.httpExecutor.download(url, destination, options); | ||
exports.HttpError = HttpError; | ||
class ProgressCallbackTransform extends (_stream || _load_stream()).Transform { | ||
constructor(onProgress, total) { | ||
super(); | ||
this.onProgress = onProgress; | ||
this.total = total; | ||
this.start = Date.now(); | ||
this.transferred = 0; | ||
} | ||
_transform(chunk, encoding, callback) { | ||
this.transferred = calculateDownloadProgress(this.total, this.start, this.transferred, chunk, this.onProgress); | ||
callback(null, chunk); | ||
} | ||
} | ||
class DigestTransform extends (_stream || _load_stream()).Transform { | ||
@@ -91,3 +112,2 @@ constructor(expected) { | ||
} | ||
exports.DigestTransform = DigestTransform; | ||
const executorHolder = exports.executorHolder = new HttpExecutorHolder(); | ||
@@ -131,2 +151,32 @@ function githubRequest(path, token) { | ||
} | ||
function safeGetHeader(response, headerKey) { | ||
const value = response.headers[headerKey]; | ||
if (value == null) { | ||
return null; | ||
} else if (Array.isArray(value)) { | ||
// electron API | ||
return value.length === 0 ? null : value[value.length - 1]; | ||
} else { | ||
return value; | ||
} | ||
} | ||
function configurePipes(options, response, destination, callback) { | ||
const streams = []; | ||
if (options.onProgress != null) { | ||
const contentLength = safeGetHeader(response, "content-length"); | ||
if (contentLength != null) { | ||
streams.push(new ProgressCallbackTransform(options.onProgress, parseInt(contentLength, 10))); | ||
} | ||
} | ||
if (options.sha2 != null) { | ||
streams.push(new DigestTransform(options.sha2)); | ||
} | ||
const fileOut = (0, (_fsExtraP || _load_fsExtraP()).createWriteStream)(destination); | ||
streams.push(fileOut); | ||
let lastStream = response; | ||
for (const stream of streams) { | ||
lastStream = lastStream.pipe(stream); | ||
} | ||
fileOut.on("finish", () => fileOut.close(callback)); | ||
} | ||
//# sourceMappingURL=httpExecutor.js.map |
{ | ||
"name": "electron-builder-http", | ||
"version": "10.16.0", | ||
"version": "10.17.1", | ||
"main": "out/httpExecutor.js", | ||
@@ -13,3 +13,6 @@ "author": "Vladimir Krivosheev", | ||
], | ||
"dependencies": { | ||
"fs-extra-p": "^3.0.3" | ||
}, | ||
"typings": "./out/electron-builder-http.d.ts" | ||
} |
Sorry, the diff of this file is not supported yet
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
31857
321
1
2
+ Addedfs-extra-p@^3.0.3
+ Addedbluebird@3.7.2(transitive)
+ Addedbluebird-lst-c@1.0.6(transitive)
+ Addedfs-extra@2.1.2(transitive)
+ Addedfs-extra-p@3.1.0(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedjsonfile@2.4.0(transitive)