Comparing version 3.9.1 to 3.9.2
@@ -10,3 +10,3 @@ import BaseDownloadEngineFetchStream, { DownloadInfoResponse, FetchSubState, WriteCallback } from "./base-download-engine-fetch-stream.js"; | ||
protected fetchDownloadInfoWithoutRetryByMethod(url: string, method?: "HEAD" | "GET"): Promise<DownloadInfoResponse>; | ||
protected fetchDownloadInfoWithoutRetryContentRange(url: string): Promise<number>; | ||
protected fetchDownloadInfoWithoutRetryContentRange(url: string, response?: Response): Promise<number>; | ||
chunkGenerator(callback: WriteCallback, getNextChunk: GetNextChunk): Promise<void>; | ||
@@ -13,0 +13,0 @@ protected static convertHeadersToRecord(headers: Headers): { |
@@ -70,4 +70,4 @@ import BaseDownloadEngineFetchStream, { MIN_LENGTH_FOR_MORE_INFO_REQUEST } from "./base-download-engine-fetch-stream.js"; | ||
let length = parseInt(response.headers.get("content-length")) || 0; | ||
if (method != "GET" && response.headers.get("content-encoding") || browserCheck() && MIN_LENGTH_FOR_MORE_INFO_REQUEST < length) { | ||
length = acceptRange ? await this.fetchDownloadInfoWithoutRetryContentRange(url) : 0; | ||
if (response.headers.get("content-encoding") || browserCheck() && MIN_LENGTH_FOR_MORE_INFO_REQUEST < length) { | ||
length = acceptRange ? await this.fetchDownloadInfoWithoutRetryContentRange(url, method === "GET" ? response : undefined) : 0; | ||
} | ||
@@ -81,4 +81,4 @@ return { | ||
} | ||
async fetchDownloadInfoWithoutRetryContentRange(url) { | ||
const responseGet = await fetch(url, { | ||
async fetchDownloadInfoWithoutRetryContentRange(url, response) { | ||
const responseGet = response ?? await fetch(url, { | ||
method: "GET", | ||
@@ -85,0 +85,0 @@ headers: { |
@@ -16,4 +16,4 @@ import BaseDownloadEngineFetchStream, { DownloadInfoResponse, FetchSubState, WriteCallback } from "./base-download-engine-fetch-stream.js"; | ||
protected fetchDownloadInfoWithoutRetryByMethod(url: string, method?: "HEAD" | "GET"): Promise<DownloadInfoResponse>; | ||
protected fetchDownloadInfoWithoutRetryContentRange(url: string): Promise<number>; | ||
protected fetchDownloadInfoWithoutRetryContentRange(url: string, xhrResponse?: XMLHttpRequest): number | Promise<number>; | ||
protected static convertXHRHeadersToRecord(xhr: XMLHttpRequest): Record<string, string>; | ||
} |
@@ -132,3 +132,3 @@ import BaseDownloadEngineFetchStream, { MIN_LENGTH_FOR_MORE_INFO_REQUEST } from "./base-download-engine-fetch-stream.js"; | ||
const contentLength = parseInt(xhr.getResponseHeader("content-length")); | ||
const length = MIN_LENGTH_FOR_MORE_INFO_REQUEST < contentLength && method != "GET" ? await this.fetchDownloadInfoWithoutRetryContentRange(url) : 0; | ||
const length = MIN_LENGTH_FOR_MORE_INFO_REQUEST < contentLength ? await this.fetchDownloadInfoWithoutRetryContentRange(url, method === "GET" ? xhr : undefined) : 0; | ||
const fileName = parseContentDisposition(xhr.getResponseHeader("content-disposition")); | ||
@@ -153,3 +153,10 @@ const acceptRange = this.options.acceptRangeIsKnown ?? xhr.getResponseHeader("Accept-Ranges") === "bytes"; | ||
} | ||
fetchDownloadInfoWithoutRetryContentRange(url) { | ||
fetchDownloadInfoWithoutRetryContentRange(url, xhrResponse) { | ||
const getSize = (xhr) => { | ||
const contentRange = xhr.getResponseHeader("Content-Range"); | ||
return parseHttpContentRange(contentRange)?.size || 0; | ||
}; | ||
if (xhrResponse) { | ||
return getSize(xhrResponse); | ||
} | ||
return new Promise((resolve, reject) => { | ||
@@ -167,4 +174,3 @@ const xhr = new XMLHttpRequest(); | ||
xhr.onload = () => { | ||
const contentRange = xhr.getResponseHeader("Content-Range"); | ||
resolve(parseHttpContentRange(contentRange)?.size || 0); | ||
resolve(getSize(xhr)); | ||
}; | ||
@@ -171,0 +177,0 @@ xhr.onerror = () => { |
{ | ||
"name": "ipull", | ||
"version": "3.9.1", | ||
"version": "3.9.2", | ||
"description": "The only file downloader you'll ever need. For node.js and the browser, CLI and library for fast and reliable file downloads.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
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
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
323863
4308