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

124
Visualizações
make split-file-stream synchronous

I am a newbie in javascript so I'm still having many issues that I still don't get it. I'm using this module 'split-file-stream' https://www.npmjs.com/package/split-file-stream and this code particularly:

var splitFileStream = require("split-file-stream");
let maxFileSize = 1024; // 1024 bytes per file
let outputPath = __dirname + "/outputFiles"; // file path partition's prefix
var customSplit = splitFileStream.getSplitWithGenFilePath((n) => `${outputPath}-${(n + 1)}`)    

    customSplit(readStream, maxFileSize, (error, filePaths) => {
        /* If an error occured, filePaths will still contain all files that were written */
        if (error) throw error; // Alternatively you could just log the error instead of throwing: if (error) console.error(error)
     
        console.log("This is an array of my new files:", filePaths);
    });

if I'm correct, I understand that fs.createReadStream is asynchronous. But what I need is that the file splitting makes it synchronous way. This is because after creating the parts, I'm going to use the splitting parts for some other stuff. But I cannot do that because when I want access to the files, these ones don't exist yet. The question is whether a way to make this code synchronous.

PD: I've using Promises (async/await) but I don't know if I am using them wrong because doesn't wait.

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