* @description Downloads the TLS library if it does not exist. * @returns {Promise } Promise that resolves when the library is downloaded
()
| 79 | * @returns {Promise<void>} Promise that resolves when the library is downloaded |
| 80 | */ |
| 81 | private async downloadLibrary(): Promise<void> { |
| 82 | if (this.libraryExists()) return; |
| 83 | |
| 84 | if (this.customPath) { |
| 85 | throw new Error('Custom path provided but library does not exist: ' + this.TLS_LIB_PATH); |
| 86 | } |
| 87 | |
| 88 | console.log('[tlsClient] Detected missing TLS library'); |
| 89 | console.log('[tlsClient] DownloadPath: ' + this.tlsDependencyPath?.DOWNLOAD_PATH); |
| 90 | console.log('[tlsClient] DestinationPath: ' + this.TLS_LIB_PATH); |
| 91 | console.log('[tlsClient] Downloading TLS library... This may take a while'); |
| 92 | |
| 93 | const downloadPath = this.tlsDependencyPath?.DOWNLOAD_PATH; |
| 94 | if (!downloadPath) { |
| 95 | throw new Error('Download path not available'); |
| 96 | } |
| 97 | |
| 98 | const response = await fetch(downloadPath); |
| 99 | if (!response.ok) { |
| 100 | throw new Error(`Unexpected response ${response.statusText}`); |
| 101 | } |
| 102 | await writeFile(this.TLS_LIB_PATH, Buffer.from(await response.arrayBuffer())); |
| 103 | console.log('[tlsClient] Successfully downloaded TLS library'); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @description Opens the TLS library and initializes the worker pool. |