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

Function maybeDownload

lstm-text-generation/data.js:245–262  ·  view source on GitHub ↗
(sourceURL, destPath)

Source from the content-addressed store, hash-verified

243 * @param {string} destPath Destination file path on local filesystem.
244 */
245export async function maybeDownload(sourceURL, destPath) {
246 const fs = require('fs');
247 return new Promise(async (resolve, reject) => {
248 if (!fs.existsSync(destPath) || fs.lstatSync(destPath).size === 0) {
249 const localZipFile = fs.createWriteStream(destPath);
250 console.log(`Downloading file from ${sourceURL} to ${destPath}...`);
251 https.get(sourceURL, response => {
252 response.pipe(localZipFile);
253 localZipFile.on('finish', () => {
254 localZipFile.close(() => resolve());
255 });
256 localZipFile.on('error', err => reject(err));
257 });
258 } else {
259 return resolve();
260 }
261 });
262}

Callers 2

mainFunction · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected