I tried this script below using Node8.x.
It worked but the size of the downloaded file was imperfect.
I tried for some time and each downloaded file size was not the same.
Using Node9+ I could download the file successfully.
Could anyone explain what was the cause?
(async () => {
const path = require('path')
await downloadPromise(
'http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz',
path.join(__dirname, './', 't10k-labels-idx1-ubyte.gz'))
})()
function downloadPromise (url, savepath) {
return new Promise((resolve, reject) => {
const http = require('http')
const fs = require('fs')
const outfile = fs.createWriteStream(savepath)
http.get(url, (res) => {
res.pipe(outfile)
res.on('end', () => {
outfile.close()
resolve()
})
})
.on('error', (err) => reject(err))
})
}