Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

275
Visualizações
How to download big file & resume download after interuption in Node.js

I wrote an app that downloads big zip files and extracts them using request and unzipper. I've also managed to show downloading progress but the requirement is that it has to be able to resume download after an interuption (internet goes down or the app closes, *for example how steam downloads games) and i cant figure it out, my code is kinda like this

const getInstallerFile = (installerfileURL, installerfilename, Possition, Directory) => {

// Variable to save downloading progress
var received_bytes = 0;
var total_bytes = 0;
percentage = 0;
var outStream = fs.createWriteStream(installerfilename);

request
    .get(installerfileURL)
    .on('error', function (err) {
        console.log("Download has stopped", err);
    })
    .on('response', function (data) {
        total_bytes = parseInt(data.headers['content-length']);
        console.log("download has started")

    })
    .on('data', function (chunk) {
  //gets percentage after every chunk
        received_bytes += chunk.length;
        showDownloadingProgress(received_bytes, total_bytes, Possition);
    })
    .pipe(outStream)
    outStream.on('finish', function () {
    console.log("download has completed")
//...codeblock for storing local data

    fs.createReadStream(installerfilename)
        .pipe(unzipper.Extract({ path: Directory }))
        .on('finish', function () {
            console.log("unzipper finished extracting")
    //deleting the zip after downloading
            fs.rmSync(installerfilename, { recursive: true, force: true });

        });


})

};

is it even possible to resume download using request or even node in general?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda