MCPcopy Index your code
hub / github.com/tensorflow/tfjs-examples / maybeDownload

Function maybeDownload

sentiment/data.js:146–162  ·  view source on GitHub ↗

* Get a file by downloading it if necessary. * * @param {string} sourceURL URL to download the file from. * @param {string} destPath Destination file path on local filesystem.

(sourceURL, destPath)

Source from the content-addressed store, hash-verified

144 * @param {string} destPath Destination file path on local filesystem.
145 */
146async function maybeDownload(sourceURL, destPath) {
147 return new Promise(async (resolve, reject) => {
148 if (!fs.existsSync(destPath) || fs.lstatSync(destPath).size === 0) {
149 const localZipFile = fs.createWriteStream(destPath);
150 console.log(`Downloading file from ${sourceURL} ...`);
151 https.get(sourceURL, response => {
152 response.pipe(localZipFile);
153 localZipFile.on('finish', () => {
154 localZipFile.close(() => resolve());
155 });
156 localZipFile.on('error', err => reject(err));
157 });
158 } else {
159 return resolve();
160 }
161 });
162}
163
164/**
165 * Get extracted files.

Callers 2

maybeDownloadAndExtractFunction · 0.70
loadMetadataTemplateFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected