Speed up downloads by combining multiple network connections in parallel
TypeScript bandwidth-aggregationcross-platformdesktop-appdownloaderdownloadmanagerlinuxmacosmulticonnectionparallel-downloadswindows
fix: enhance content-disposition parsing, network interface display names, and destination directory creation
Anmol Kapil0819813b1992
diff --git a/src/main/download/downloadManager.ts b/src/main/download/downloadManager.tsindex 827446b..8aebe55 100644--- a/src/main/download/downloadManager.ts+++ b/src/main/download/downloadManager.ts@@ -433,6 +433,7 @@ export class DownloadManager {interfaces: NetworkInterfaceInfo[]): Promise<string> {await mkdir(this.downloadsRoot(), { recursive: true })+ await mkdir(requestPayload.destinationDir, { recursive: true })await ensureDiskSpace(requestPayload.destinationDir,this.downloadsRoot(),diff --git a/src/main/download/paths.ts b/src/main/download/paths.tsindex af05b36..62889ca 100644--- a/src/main/download/paths.ts+++ b/src/main/download/paths.ts@@ -1,5 +1,5 @@import { app } from 'electron'-import { open } from 'node:fs/promises'+import { mkdir, open } from 'node:fs/promises'import { basename, extname, join } from 'node:path'export function getDefaultDownloadsDir(): string {@@ -39,6 +39,7 @@ function sanitizeFileName(fileName: string): string {* download doesn't end up producing a file.*/export async function reserveDestinationPath(directory: string, fileName: string): Promise<string> {+ await mkdir(directory, { recursive: true })fileName = sanitizeFileName(fileName)const ext = extname(fileName)const base = basename(fileName, ext)diff --git a/src/main/download/probe.ts b/src/main/download/probe.tsindex 6ba7ba4..f815f7e 100644--- a/src/main/download/probe.ts+++ b/src/main/download/probe.ts@@ -48,17 +48,47 @@ function requestOneByte(url: URL): Promise<ProbeResponse> {})}+function parseContentDispositionFilename(disposition: string): string | null {+ // RFC 6266 / RFC 5987: filename* takes precedence over filename+ // format: filename*=charset'language'encoded-value+ const extMatch = /\bfilename\*=(?:[a-zA-Z0-9_-]+)'[^']*'([^;\s]+)/i.exec(disposition)+ if (extMatch?.[1]) {+ try {+ return decodeURIComponent(extMatch[1])+ } catch {+ return extMatch[1]+ }+ }++ // Quoted string: preserves semicolons inside quotes, e.g. filename="report; final.pdf"+ const quotedMatch = /\bfilename="((?:[^"\\]|\\.)*)"/i.exec(disposition)+ if (quotedMatch?.[1]) {+ const unescaped = quotedMatch[1].replace(/\\(.)/g, '$1')+ try {+ return decodeURIComponent(unescaped)+ } catch {+ return unescaped+ }+ }++ // Unquoted token fallback+ const tokenMatch = /\bfilename=([^;\s]+)/i.exec(disposition)+ if (tokenMatch?.[1]) {+ try {+ return decodeURIComponent(tokenMatch[1])+ } catch {+ return tokenMatch[1]+ }+ }++ return null+}+function fileNameFromHeaders(headers: Headers, url: URL): string {const disposition = headerValue(headers, 'content-disposition')if (disposition) {- const match = /filename\*?=(?:UTF-8'')?"?([^";]+)"?/i.exec(disposition)- if (match?.[1]) {- try {- return decodeURIComponent(match[1])- } catch {- return match[1]- }- }+ const parsed = parseContentDispositionFilename(disposition)+ if (parsed) return parsed}let pathname = url.pathnametry {diff --git a/src/main/network/interfaces.ts b/src/main/network/interfaces.tsindex 5f829da..a145b4b 100644--- a/src/main/network/interfaces.ts+++ b/src/main/network/interfaces.ts@@ -108,7 +108,7 @@ export async function listActiveInterfaces(): Promise<NetworkInterfaceInfo[]> {result.push({id: device,device,- displayName: hardwareName ?? device,+ displayName: hardwareName ?? adapter?.InterfaceDescription ?? device,address: ipv4.address,kind,mac: ipv4.mac && ipv4.mac !== '00:00:00:00:00:00' ? ipv4.mac : undefined