MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / fetchOnceAndSaveToDiskWithBuffer

Function fetchOnceAndSaveToDiskWithBuffer

mnist-node/data.js:44–61  ·  view source on GitHub ↗
(filename)

Source from the content-addressed store, hash-verified

42
43// Downloads a test file only once and returns the buffer for the file.
44async function fetchOnceAndSaveToDiskWithBuffer(filename) {
45 return new Promise(resolve => {
46 const url = `${BASE_URL}${filename}.gz`;
47 if (fs.existsSync(filename)) {
48 resolve(readFile(filename));
49 return;
50 }
51 const file = fs.createWriteStream(filename);
52 console.log(` * Downloading from: ${url}`);
53 https.get(url, (response) => {
54 const unzip = zlib.createGunzip();
55 response.pipe(unzip).pipe(file);
56 unzip.on('end', () => {
57 resolve(readFile(filename));
58 });
59 });
60 });
61}
62
63function loadHeaderValues(buffer, headerLength) {
64 const headerValues = [];

Callers 2

loadImagesFunction · 0.70
loadLabelsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected