UNPKG

@decaf-ts/utils

Version:

module management utils for decaf-ts

42 lines (41 loc) 1.53 kB
/** * @description A simple HTTP client for downloading files. * @summary This class provides functionality to download files from HTTPS URLs. * It uses Node.js built-in https module to make requests. * * @class HttpClient */ export declare class HttpClient { protected static log: import("@decaf-ts/logging").Logger; /** * @description Downloads a file from a given URL. * @summary This method sends a GET request to the specified URL and returns the response body as a string. * It handles different scenarios such as non-200 status codes and network errors. * * @param url - The URL of the file to download. * @return A promise that resolves with the file content as a string. * * @mermaid * sequenceDiagram * participant Client * participant HttpClient * participant HTTPS * participant Server * Client->>HttpClient: downloadFile(url) * HttpClient->>HTTPS: get(url) * HTTPS->>Server: GET request * Server-->>HTTPS: Response * HTTPS-->>HttpClient: Response object * alt Status code is 200 * loop For each data chunk * HTTPS->>HttpClient: 'data' event * HttpClient->>HttpClient: Accumulate data * end * HTTPS->>HttpClient: 'end' event * HttpClient-->>Client: Resolve with data * else Status code is not 200 * HttpClient-->>Client: Reject with error * end */ static downloadFile(url: string): Promise<string>; }