async function fetchOnceAndSaveToDiskWithBuffer(
    baseURL, destDir, filename) {

  return new Promise(async (resolve, reject) => {
    const url = `${baseURL}${filename}.gz`;
    const localPath = path.join(destDir, filename);
    if (await exists(localPath)) {
      resolve(readFile(localPath));
      return;
    }
    const file = fs.createWriteStream(filename);
    console.log(`  * Downloading from: ${url}`);
    let httpModule;
    if (url.indexOf('https://') === 0) {
      httpModule = https;
    } else if (url.indexOf('http://') === 0) {
      httpModule =  http;
    } else {
      return reject(`Unrecognized protocol in URL: ${url}`);
    }

    httpModule.get(url, (response) => {
      const unzip = zlib.createGunzip();
      response.pipe(unzip).pipe(file);
      unzip.on('end', async () => {
        await rename(filename, localPath);
        resolve(readFile(localPath));
      });
    });
  });
}
Provides methods and classes that support loading data from
both MNIST and Fashion MNIST datasets.