MCPcopy Create free account
hub / github.com/mempool/mempool / downloadFile

Function downloadFile

frontend/sync-assets.js:74–102  ·  view source on GitHub ↗
(filePath, url)

Source from the content-addressed store, hash-verified

72
73// Utility: Download file
74const downloadFile = (filePath, url) => {
75 if (!filePath || !url) {
76 if (config.verbose) {
77 console.log('skipping malformed download request: ', filePath, url);
78 }
79 return Promise.resolve();
80 }
81
82 return new Promise((resolve, reject) => {
83 https.get(url, (response) => {
84 if (response.statusCode < 200 || response.statusCode > 299) {
85 reject(new Error(`HTTP Error ${response.statusCode} while fetching '${filePath}'`));
86 return;
87 }
88
89 const writeStream = fsSync.createWriteStream(filePath);
90 response.pipe(writeStream);
91
92 writeStream.on('finish', () => {
93 if (config.verbose) {
94 console.log(`${LOG_TAG} \tFinished downloading ${url} to ${filePath}`);
95 }
96 resolve();
97 });
98
99 writeStream.on('error', reject);
100 }).on('error', reject);
101 });
102};
103
104// Utility: Get local file hash (Git blob format)
105const getLocalHash = (filePath) => {

Callers 2

processFileItemFunction · 0.85
downloadLiquidAssetsFunction · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected