Я пытаюсь найти поддержку для загрузки файла с параметрами прогресса, паузы, возобновления.
Часть прогресса, о которой я рассказал, но я не могу найти ничего о паузе / резюме .
Использование узлов / электронов.
const Fs = require('fs')
const Path = require('path')
const Axios = require('axios')
let startTime, endTime;
function start() {
startTime = new Date();
};
function end() {
endTime = new Date();
var timeDiff = (endTime - startTime) / 1000;
console.log(timeDiff + " seconds");
}
async function downloadFile(url) {
start();
var received_bytes = 0;
console.log('Connecting …')
const { data, headers } = await Axios({
url,
method: 'GET',
responseType: 'stream',
})
const totalLength = headers['content-length']
const writer = Fs.createWriteStream(
Path.resolve(__dirname, 'images', 'axios.jpg')
)
data.pipe(writer)
data.on('data', (chunk) => {
received_bytes += chunk.length;
showProgress(received_bytes, totalLength);
})
data.on('error', (error) => {
console.log('downloadError', error)
})
data.on('end', () => {
end();
})
}
function showProgress(received, total) {
var percentage = (received * 100) / total;
console.log(percentage + "% | " + received + " bytes out of " + total + " bytes.");
}
downloadFile('https://unsplash.com/photos/AaEQmoufHLk/download?force=true');