Server IP : 85.214.239.14 / Your IP : 18.217.242.39 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/self/root/lib/node_modules/npm/node_modules/tuf-js/dist/ |
Upload File : |
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DefaultFetcher = exports.BaseFetcher = void 0; const debug_1 = __importDefault(require("debug")); const fs_1 = __importDefault(require("fs")); const make_fetch_happen_1 = __importDefault(require("make-fetch-happen")); const util_1 = __importDefault(require("util")); const error_1 = require("./error"); const tmpfile_1 = require("./utils/tmpfile"); const log = (0, debug_1.default)('tuf:fetch'); class BaseFetcher { // Download file from given URL. The file is downloaded to a temporary // location and then passed to the given handler. The handler is responsible // for moving the file to its final location. The temporary file is deleted // after the handler returns. async downloadFile(url, maxLength, handler) { return (0, tmpfile_1.withTempFile)(async (tmpFile) => { const reader = await this.fetch(url); let numberOfBytesReceived = 0; const fileStream = fs_1.default.createWriteStream(tmpFile); // Read the stream a chunk at a time so that we can check // the length of the file as we go try { for await (const chunk of reader) { const bufferChunk = Buffer.from(chunk); numberOfBytesReceived += bufferChunk.length; if (numberOfBytesReceived > maxLength) { throw new error_1.DownloadLengthMismatchError('Max length reached'); } await writeBufferToStream(fileStream, bufferChunk); } } finally { // Make sure we always close the stream await util_1.default.promisify(fileStream.close).bind(fileStream)(); } return handler(tmpFile); }); } // Download bytes from given URL. async downloadBytes(url, maxLength) { return this.downloadFile(url, maxLength, async (file) => { const stream = fs_1.default.createReadStream(file); const chunks = []; for await (const chunk of stream) { chunks.push(chunk); } return Buffer.concat(chunks); }); } } exports.BaseFetcher = BaseFetcher; class DefaultFetcher extends BaseFetcher { constructor(options = {}) { super(); this.timeout = options.timeout; this.retry = options.retry; } async fetch(url) { log('GET %s', url); const response = await (0, make_fetch_happen_1.default)(url, { timeout: this.timeout, retry: this.retry, }); if (!response.ok || !response?.body) { throw new error_1.DownloadHTTPError('Failed to download', response.status); } return response.body; } } exports.DefaultFetcher = DefaultFetcher; const writeBufferToStream = async (stream, buffer) => { return new Promise((resolve, reject) => { stream.write(buffer, (err) => { if (err) { reject(err); } resolve(true); }); }); };