Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!